Skip to main content

Java Reserved Words

 Java Reserved Words 


In java, some identifiers are reserved to associate some functionality or meaning such type of reserved identifiers is called reserved words.


> Reserved words for data types (8)
  1. byte
  2. short
  3. int
  4. long
  5. float
  6. char
  7. double
  8. boolean
> Reserved words for flow control (11)
  1. if
  2. else
  3. switch
  4. case
  5. default
  6. for
  7. do
  8. while
  9. break
  10. continue
  11. return
> Keywords for modifiers (11)

  1. public
  2. private
  3. protected
  4. static
  5. final
  6. abstract
  7. synchronized
  8. native
  9. strictfp (1.2 version)
  10. transient
  11. volatile
> Keywords for exception handling (6)
  1. try
  2. catch
  3. finally
  4. throw
  5. throws
  6. assert (1.4 version)
> Class related keywords (6)
  1. class
  2. package
  3. import
  4. extends
  5. implements
  6. interface
> Object related keywords (4)
  1. new
  2. super
  3. instanceof
  4. this
> Void return type keywords:

If a method won't return anything compulsory that method should be declared with the void return type in java but it is optional in C++
  1. void
> Unused keywords:
  1. goto: Create several problems in old languages and hence it is banned in java.
  2. const: Use final instead of this.
By mistake, if we are using these keywords in our program we will get a compile-time error.

> Reserved literals :
  1. true      values for boolean data type
  2. false
  3. null      default value for object reference

Comments

Popular posts from this blog

Data Types in Java

Every variable has a type, every expression has a type and all types are strictly define moreover every assignment should be checked by the compiler by the type compatibility hence java language is considered as strongly typed programming language. Integral data types:- byte: Size: 1 byte (8 bits) Range:  -128 to 127 byte data type is best suitable if we are handling data in terms of streams either from the file or from the network. short: The most rarely used data type in Java is short. Size: 2 byte Range: -32768 to 32767 short data type is best suitable for 16-bit processors like 8086 but these processors are completely outdated and hence the corresponding short data type is also out data type. int: Size: 4 byte Range: -2147483678 to 2147483647 long: Whenever int is not enough to hold big values than we should go for long data type. Size: 8byte Range: -263 to 263-1 All the data types (byte, short, int, and long) can be used to represent whole numbers. If we want to represent real num