My other sites |
New Summer Look :)
![]() |
- Case sensitive
|
| abstract boolean break byte case catch char class const continue |
default do double else extends false final finally float for |
goto if implements import instanceof int interface long native new null |
package private protected public return short static super switch |
synchronized this throw throws transient true try void volatile while |
![]() |
/**
* This is a special kind of comment
* that is used to hold javadoc comments
* More on this later...
*/
public class Comments {
/*
* this is a comment that spans multiple
* lines
*/
public static void main(String[] args) {
// this is a one line comment
System.out.println( "hey" ); // comment to the end of the line
}
}
|
![]() |
- Identifiers are simple names used within a programming
language - In Java, identifiers can be any combination of letters, numbers, '_' and '$' - However, identifiers cannot begin with a number - Identifiers in Java are also case-sensitive |
|
Valid Identifiers:
abc a1b2c3 _123 $_$_$ |
Invalid Identifers:
1hello @hello@ hello&world |
|
Recommended:
helloWorld finished startIndex theLastPoint |
Not Recommended:
j p hello_world hello1 hello2 |
| Type | Data Storage | Example |
| byte | signed 8-bit | -2^7 2^7 - 1 |
| short | signed 16-bit | -2^15 2^15 - 1 |
| int | signed 32-bit | -2^31 2^31 - 1 |
| long | signed 64-bit | -2^63 2^63 - 1 |
| boolean | 1 bit | true or false |
| float | 32-bit (IEEE-754) | 3.4e+38 |
| double | 64-bit (IEEE-754) | 1.7e+308 |
| char | 16-bit (unicode) | '\n', '\t', '\\'' |
| Data Type | Example Values |
| Integers | 42, 0, -22, +69, 345678 |
| Octals | 0177, 00, 0777, -023 |
| Hexadecimals | 0x0, -0x1, 0x34af, 0XA9B3 |
| Longs | 0L, 0l, 12345678L, 0xab12345L, -87654321L |
| Floats | 123.456, -654.321, 0.0, 0.98, 1.23f, 45.678F, 2.567d, 7.374D, 6.564e+23, |
| Boolean | true, false |
| Characters | 'a', 'b', 'A', '3', '{', ' ', '\b', '\n', '\r', '\\', '\t', '\'', \123, \234, \012 |
| Strings | "This is a string","Hello World!!!\n", "left\tcentre\tright\t" |
| Null | null |
|
For Complex types we use classes |
|
![]() |
Arrays:
int[] five = { 0, 1, 2, 3, 4 }; char[] separators = { ',', '.', ';', ':' }; |
| Type Casting = To change a basic type into another int myint = 70; char ch = (char) myint; |
![]() |
|
| Casts that results in no loss of information : |
From Type byte short char int long float |
To Type short, char, int, long, float, double int, long, float, double int, long, float, double long, float, double float, double double |
| Operator | Operand Type(s) | Assoc | Operation Performed |
| ++ | arithmetic | R | pre-or-post increment (unary) |
| -- | arithmetic | R | pre-or-post decrement (unary) |
| +, - | arithmetic | R | unary plus, unary minus |
| ~ | integral | R | bitwise complement (unary) |
| ! | Boolean | R | logical complement (unary) |
| (type) | any | R | cast |
| *, /, % | arithmetic | L | multiplication, division, remainder |
| +, - | arithmetic | L | addition, subtraction |
| + | string | L | string concatenation |
| << | integral | L | left shift |
| >> | integral | L | right shift with sign extension |
| >>> | integral | L | right shift with zero extension |
| <, <= | arithmetic | L | less than, less than or equal |
| >, >= | arithmetic | L | greater than, greater than or equal |
| instanceof | object,type | L | type comparison |
| == | primitive | L | equal (have identical values) |
| != | primitive | L | not equal (have different values) |
| == | object | L | equal (refer to same object) |
| != | object | L | not equal (refer to different objects) |
| & | integral | L | bitwise AND |
| & | boolean | L | boolean AND |
| ^ | integral | L | bitwise XOR |
| ^ | boolean | L | boolean XOR |
| | | integral | L | bitwise OR |
| | | boolean | L | boolean OR |
| && | boolean | L | conditional AND |
| || | boolean | L | conditional OR |
| ?: | boolean, any,any | R | conditional (ternary) operator |
| = | variable, any | R | assignment |
| *=, /=, %=, +=, -=, <<=,>>=, >>>=, &=, ^=, |= | variable, any | R | assignment with operation |