There are near about 50 keywords ( reserved words) in core Java.The tables bellow demonstrate JAVA keywords with description and example and assigned alphabetically.Hope that you will find useful for learning or refreshing your memory......
Please inform me by posting comments if I am wrong...
| keyword | description | example |
|---|---|---|
| Abstact | used in class and method declaration. Abstract class: 1) class must be declared with abstract keyword 2) methods in abstract class may or may not be abstract 3)If a class contains at-least one abstract method, the class must be declared as abstract. 4)Abstract methods must not be implemented in abstract class. Methods must be implemented in sub classes 5) An abstract class can not be instantiated, its solo mission is to be subclassed. |
abstact class Myclass // abstract class { public abstact void do();// is a abstract method public String getName() { } } |
| Assert | followed by a boolean value (true or false), or an expression, to be evaluated at runtime, that returns a boolean value. If the boolean expression evaluates to false, then an AssertionError is thrown. | assert true; assert 50 == 50; // this will throw an Assertion Error: int test = 50; assert test == 100; |
| boolean | is a data type which stores boolean value, i.e True or False. It is also used to declare methods that returns a value which is also a boolean. | boolean myFlag = true; |
| break | One of the control statement to control the program flow. used to break the loop of switch statement. 1) Unlabeled Break statement 2) Labeled Break Statement | 1) Unlabeled Break statement for(int num =0; num < 5 ; var++) { System.out.println(“Num is : “ + num); if(num == 3) break; } 2)Labeled Break Statement Back: for(int num1=0; var1 < 10 ; num1++) { for(int num2 = 1; num2 < 10; num2++) { System.out.println(“num1:” + num1 + “, num2:” + num2); if(num1 == 5) break Back; } } |
| byte | 8 bit signed 2's complement integer | byte b = -1; |
| case | case is used in Switch statement |
switch ( value/variable to test ) {
case value: your code_here; break; case value: your code_here; break; default: value/variable_not_above;
}
|
| catch | use with try block to catching exceptiion | try { code here} catch( exception ) {} |
| char | character type in unicode | char test ="y" |
| class | implementation of a particular kind of object which defines instance, class fields, methods,innner classes,interfaces as well as superclasses of class | class Person { private String name; public Person(String myName) { this.name = myName; } public void show() { System.out.println(name); } } classs Strudent extends Person { Pesron p = new Person(); p.show(); } |
| const | is keyword in Java, but till now not used | |
| continue | to skip the rest of the statement in body of the loop and continue with the next iteration of the loop 1)Unlabeled Continue 2)labeled Continue | 1)Unlabeled Continue for(int num1 =0; num1 < 15 ; num1++) { for(int num2=0 ; num2 <1 5 ; num2++) { if(num2 == 2) continue; System.out.println( num1 + num2); } } 2) Labeled Continue Back: for(int num1 =0; num1 < 5 ; num1++) { for(int num2=0 ; num2 < 5 ; num2++) { if(var2 == 2) continue Back; System.out.println( num1 + num2); } } |
| default | can optionally be used in "Switch case" labelling a block of statement which is to be executed | see case |
| do | use with while to form "do-while" loop uses boolean expression to execute block of statements | do { statement(s) } while (expression); |
| double | 64-bit double precision IEEE 754 floating-point number | double mydouble = 0.05; |
| else | use with "if " to form "if else" or "else if" statement tests boolean expression | int score = 79; char status; if (score >= 90) { status= 'A'; } else if (score >= 80) { status = 'B'; } else if (score >= 70) { status = 'C'; } else if (score >= 60) { status = 'D'; } else { status = 'F'; } System.out.println("status = " + grade); |
| enum | enumeration is a type whose field consist of a fixed value of constant. It extends base class called Enum | public enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY } |