HomeJava

50 keywords in Java you should be aware of

50 keywords in Java you should be aware of
Like Tweet Pin it Share Share Email

Every programming language will have a huge list of keywords so that the respective compiler or interpreter can understand to perform the actions accordingly, similarly in java there are 50 keywords and it is very important that you should know to write programs in java.

Most of you fear its a huge list, but by just giving a quick read it will make your life easier to start writing programs in java, you need not know exact purpose and meaning of all 50 java keywords at once, you will learn them as you practise writing more and more programs in java.

These keywords can be categorised on different usage purposes and the list goes below:

  • Data Types
  • Access modifiers
  • Non Access modifiers
  • Control structures / Flow structures related
  • Error Handling
  • Object Oriented Programming related
  • Others / Miscellaneous
  • Un Used

50 Keywords in Java are explained below for each category with purpose

8 Keywords in Data Types category

Data Types are the different types of data that java can hold and can be represented in memory, each primitive data type has its own capacity of data that it can hold.

Below list of keywords are used to  either declare a variable for a specific type supported in java or as a return type to methods in java.

8 keywords in primitive data types of java

S.No Keyword Type Purpose
1 int Primitive A data type which can hold ( 32 bit / 4 bytes ) numeric values, i.e. both negative and positive numbers. No decimals are supported.

ex: int i = 10;

2 boolean Primitive A data type which can hold only 2 values, i.e. true and false, can be used directly in control structures like if, while, for, etc..

ex: boolean flag = true;

3 long Primitive A data type which can hold ( 64 bit / 8 bytes ) numeric values, i.e. both negative and positive numbers. No decimals are supported.

ex: long value = 10;

4 double Primitive A data type which can hold ( 64 bit / 8 bytes ) numeric values with double precision (decimals), i.e. both negative and positive numbers with decimal points.
5 char Primitive A data type which can hold character supported by java character set in 1 byte of memory.

ex: char alpha = ‘a’;

6 byte Primitive A datatype which can hold any data within 1 byte of memory.
7 short Primitive A data type which can hold ( 16 bit / 2 bytes ) numeric values, i.e. both negative and positive numbers. No decimals are supported.

ex short value = 1;

8 float Primitive A data type which can hold ( 32 bit / 4 bytes ) numeric values with single precision (decimals), i.e. both negative and positive numbers with decimal points.

ex: float value = 10.15;

3 Keywords in Access modifiers category

Access modifiers are the ones which regulate the access of class members in different locations of programming, like following:

  • Accessibility in same class
  • Accessibility in sub classes
  • Accessibility in classes in same package
  • Accessibility in classes in other packages


Source & Credits: JIRA

Following are the list of keywords you can use to declare a specific class member (i.e. a method or a field or an inner class) and regulate the accessibility of them.

S.No Keyword Purpose
9 private Class members declared with private keyword in a class can be accessible only by the members of the same class.
10 public Class members declared with public keyword in a class can be accessed by the members of the same class or a sub class or any class in same package or even in a class of a different package.
11 protected Class members declared with protected keyword in a class can be accessed by the  members of the same class or a sub class or any class present in same package.

6 Keywords in Non Access modifiers category

These are the list of keywords which regulate the behaviour of class members when declared with them.

S.No Keyword Purpose
12 static
13 final
14 volatile
15 transient
16 abstract
17 synchronized

11 Keywords in Control / Flow structure category

These are the keywords which will determine the code flow, i.e. if you want to repeat some specific set of statements or if you want certain set of statements to be executed or skipped based on conditions of the business logic that is written in the program.

S.No Keyword Type
18 if Conditional Construct
19 else Conditional Construct
20 while Looping construct
21 for  Looping Construct
22 do  Looping Construct
23 break Jumping statement – generally used with loops in conjunction with conditional constructs
24 continue Jumping statement – generally used with loops in conjunction with conditional constructs
25 return Jumping statement – generally used with conditional constructs & functions
26 switch  Conditional Construct
27 default Jumping statement – generally used with conditional construct Switch
28 case Jumping statement – generally used with conditional construct Switch

In order to dwell more in to each of the above conditional & looping constructs I would recommend you to read the article – “All about Conditional and looping constructs in Java”

6 Keywords in Error Handling category

S.No Keyword Purpose
29 try
30 catch
31 throw
32 throws
33 finally
34 assert

7 Keywords in Object Oriented Programming category

S.No Keyword Purpose
35 class
36 implements
37 extends
38 interface
39 new
40 super
41 this

7 Keywords in Miscellaneous category

S.No Keyword Purpose
42 strictfp
43 import
44 package
45 native
46 enum
47 void
48 instanceof

2 Keywords in Un Used category

S.No Keyword Purpose
49 const
50 goto

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *