×
☰ See All Chapters

Keywords in Java

Every programming language has special reserved words, or keywords, that have specific meanings and restrictions around how they should be used. Java is no different. Java keywords are the fundamental building blocks of any Java program. Keywords are an essential part of a language definition. They implement specific features of the language. These keywords, combined with operators and separators according to syntax, form definition of the Java language.

In this chapter, you’ll find a basic introduction to all Java keywords along with other resources that will be helpful for learning more about each keyword.

Java language has reserved 50 words as keywords that cannot be used as variable names, function names, or any other identifiers. Since keywords have specific meaning in Java, we cannot use them as names for variables, classes, methods and so on. All keywords are to be written in lower-case letters. Since Java is case-sensitive, one can use these words as identifiers by changing one or more letters to upper case. However, it is a bad practice and should be avoided.

The keywords const and goto are reserved but not used.  In addition to the keywords, Java reserves true, false, and null. These are values defined by Java. You may not use these words for the names of variables, classes, and so on. Below tables lists all the keywords.  It is not needed to memorize all the below keywords. You will learn about different keywords in different chapters.

Keywords for Class - Building - Handling - Managing Tools

abstract

to define an abstract class and abstract method

extends

Extending classes and interfaces (by another interface only )

implements

implementing interfaces

import

import and static import

package

package declaration

Keywords for Exception Handling

try

Exception handling

throw

throwing Exception

catch

Exception handling

assert

added by java 1.4 to Create a Mechanism for doing Pre and Post Validation methods pre validation on public methods should not be done using assert                            

finally

used with Exception

Keywords for Object Reference

super

calling super class constructor , super class methods , super class members

this

refence to current Object , accessable only to non-static methods and initialisers , also has a special meaning in constructors, though non inconsistent .        

Reserved keywords for future

strictfp

Reserved for future

const

Reserved for future

goto

Reserved for future

Modifier keywords

final

modifier to represent contants

private

Access modifier

protected

Access modifier

public

access definition

synchronized

used with Multithreading

volatile

used to suggest to compilier not to Optimise this variable since this can be modified unexpectedly.

transient

specifies that the data should not be serialized

native

defining native methods

static

creating Static members for a Class

Flow control keywords

while

used in loops , while and do-while

do

used with do-while loop

for

for loop

break

used with switch case and for loops

continue

used with loops to continue with next interation

switch

switch case condition

case

switch case statement

default

used with switch case

if

if condition

else

else clause of if CONDITION

return

return a value to called method

Keyword operators in the sense that, they could well be functions

instanceof

checks if Object is an instance of class

new

creating objects on the heap

Data and Data Types keywords

boolean

datatype

byte

datatype

char

datatype

short

datatype

int

datatype

long

datatpe

class

to  define a class

enum

defining enumeration

interface

interface definition

float

datatype

double

datatype

void

key word which says that a ordinary method does not return anything

null

represents a null reference

TRUE

boolean literal

FALSE

boolean literal

       

 


All Chapters
Author