Say "Hello World" to Java
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 Type | Size | Description |
byte | 1 byte | Stores whole numbers from -128 to 127 |
short | 2 bytes | Stores whole numbers from -32,768 to 32,767 |
int | 4 bytes | Stores whole numbers from -2,147,483,648 to 2,147,483,647 |
long | 8 bytes | Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
float | 4 bytes | Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits |
double | 8 bytes | Stores fractional numbers. Sufficient for storing 15 decimal digits |
boolean | 1 bit | Stores true or false values |
char | 2 bytes | Stores 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