Showing posts with label Reserved words. Show all posts

Can we write a method in java without return type like C programming?

class ReservedWords1
{
public static void main(String[] args)
{
System.out.println("main method");
m1();
}
static m1()
{
System.out.println("m1 method");
}
}
/*
Output :- CE[invalid method declaration; return type required]
Explanation :- If a method doesnot return anything then we should declare that method with
"void" return type. In Java, return type is mandatory but in C language return
type is optional and default return type is "int".
*/

Read more »

How many Reserved words/Keywords are available in Java?

In Java, There are 53 reserved words are available to represent some meaning
or functionality such type of words are called as reserved words.

Reserved Words(53)
|
|-----Keywords(50)
|-----Reserved Literals(3) true,false,null


Keywords(50)
|
|----Used Keywords(48)
|----Unused Keywords(2) goto,const


Keywords for Data types(8)
|----byte, short, int, long, float, double, char, boolean

Keywords for Flow Control(11)
|----if, else, switch, case, default, while, do, for, break, continue, return

Keywords for Modifiers(11)
|----public, protected, private, final, static, abstract, native, synchronized, volatile, transient, strictfp

Keywords for Exception Handling(6)
|----try, catch, finally, throw, throws, assert

Class related Keywords(6)
|----class, interface, package, import, implements, extends

Object related Keywords(4)
|----new, super, this, instanceof

Void return type Keyword(1)
|----void


Unused Keywords(2)
------------------
goto:- Usage of "goto" keyword, created several problems in old languages. Hence Sun people banned this keyword in Java.
const:- We can use "final" keyword instead of "const" keyword.

Note:- By mistake if we are using these two keywords then we will compile time error.
Read more »