Saturday 25 May 2013

Java Keywords

Tags

Complete list of Java keywords: abstract, assert, boolean, break, byte, case, catch, char, class, const, continue, default, do, double, else, enum, extends, final, finally, float, for, goto, if, implements, import, instanceof, int, interface, long, native, new, package, private, protected, public, return, short, static, strictfp, super, switch, synchronized, this, throw, transient, try, void, volatile, while.

Reserved words for literal use: true, null, false.

Is main/next/delete/exit/null/sizeof/virtual a keyword in Java?
None of these are Java keywords.

Final, finally, finalize in Java?*Final is a modifier that can be applied to classes, methods, fields, variables and parameters. Classes cannot be extended, methods cannot be overridden, fields cannot be assigned multiple times and must be instantiated in the constructors, variables can only be assigned once and parameters cannot be assigned. Finalize is the method called just before the object is garbage collected. Finally indicated the code block to be executed in connection with a try/catch block. The finally code is executed even if the function returns a value in try/catch and can change the return value.

What are the final fields and final methods?
See above.

What is static in Java?
The static keyword is used to declare fields, methods or inner classes. Objects hold a single copy of the fields no matter how many instance are there. Static member classes are actually top-level classes and not inner classes.

What if I write static public void instead of public static void?Program compiles, no error, the same thing.

How is the transient keyword used?
Transient modifier applies to members that are not stored during serialization.

How is volatile keyword used?
Volatile fields can be modified asynchronously by multiple threads.

How are goto and const keywords used in Java?
Although these are actually keywords, they are not used and don’t serve any purpose.


EmoticonEmoticon