Say "Hello World" to Java

·

2 min read

public class Main {
  public static void main(String[] args) {
    System.out.println("Hello World");
  }
}

**Java Basics - I
**

java -version : To check the java version in our local

Single-line Comments : // This is a comment

Multi-line Comments : /** This is a multi-line comment we use for Java docs to share our info with the other developers at Anthology about what we created in our API - https://developer.anthology.com/portal/displayApi/Learn **/

Variables are containers for storing data values. Like our real name used to identify an object used in our application.

A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign " $ ", or the underscore character "_". The convention, however, is to always begin your variable names with a letter, not " $ " or "_".

Data type cannot be used as a variable name. Like int int; will throws error

similarly int 2long_data will throws error.

int _mobileTeamMembersCount = 30;
int $webTeamMembersCount = 14;
int #Hashtag ; // This line throws Error - Identifier expected -  Illegal character: # (U+0023)

Primitive Data types

Data TypeSizeDescription
byte1 byteStores whole numbers from -128 to 127
short2 bytesStores whole numbers from -32,768 to 32,767
int4 bytesStores whole numbers from -2,147,483,648 to 2,147,483,647
long8 bytesStores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float4 bytesStores fractional numbers. Sufficient for storing 6 to 7 decimal digits
double8 bytesStores fractional numbers. Sufficient for storing 15 decimal digits
boolean1 bitStores true or false values
char2 bytesStores a single character/letter or ASCII values

Their default values

byte, short, int, long --> 0

float, double --> 0.0

String --> null

char --> � also called --> \u0000

boolean --> false