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.
|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.
|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.
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.
|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|
|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
7 Keywords in Object Oriented Programming category
7 Keywords in Miscellaneous category
2 Keywords in Un Used category