Java Language specification
In this post, you will learn all important aspects of Java.
Key things to note about Java are –
- It’s an object oriented language.
- Everything is Class and Object in Java.
- Class, Interface and Enum names should start with Upper Case letter.
- Package names should be in lower case.
- Method names should start with lower case letter and each subsequent word should start in Capital letter – for example setMarks()
- All Java statements end with semi-colon (;).
- Single line Comments can be marked using // . For multi-line comments you need to use /* ………………*/
Keywords in Java
Here is the list of Keywords in Java.
- Data types – int, float, byte, char, double, boolean, long, short
- Access Modifiers – public, private, protected
- Object Oriented – class, Object, interface, enum, extends, implements, import, instanceof, new, native, package, super, this
- Other modifiers – static, abstract, strictfp, synchronized, transient, volatile,const, final
- Constructs – break, case, continue, default, do, else, if, for, goto, switch, while
- Exception related – catch, finally, throw, throws, try
- Others – void, false, null, true, false, assert, return
Operators in Java
Here is the list of Operators in Java.
- Arithmetic operators +, -, /, *, %, ++, —
- Logical Operators ||, &&, !
- Relational Operators <. >, ==, <=, >=, !=
- Bitwise Operators &, |, ^, ~, <<, >>
- Assignment Operators =, +=, -=, *=, /=, %=, <<=, >>=, &=, |=, ^=
- Conditional operator ?:
Operator precedence – When calculating the mathematical expressions, Java uses operator precedence rule to calculate the final value of the expression.
For example – * operator has high precedence over – operator.
x = 5-2*9
Result of above expression would be 13 and not 27. If you want to override this rule, you can use parenthesis ().
x = (5-2) * 9
Result of above expression would be 27 as everything inside parenthesis is evaluated first.
Identifiers in Java
Identifiers are nothing but the names given to variables, methods, classes, interfaces etc. Here are the rules to define the identifiers in Java.
- It should start with letter, _ or $
- It can not contain any other special character like +, &, / etc
- It should not have spaces in it