0% found this document useful (0 votes)
316 views7 pages

Java Keywords

Java keywords are reserved tokens that implement specific features of the language, with 51 total keywords, 49 of which are currently in use. They are categorized into access modifiers, class method variables modifiers, flow control, package control, primitive types, error handling, enumeration, and others. Notable keywords include 'abstract', 'public', 'static', and 'void', while 'const' and 'goto' are reserved but not used.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
316 views7 pages

Java Keywords

Java keywords are reserved tokens that implement specific features of the language, with 51 total keywords, 49 of which are currently in use. They are categorized into access modifiers, class method variables modifiers, flow control, package control, primitive types, error handling, enumeration, and others. Notable keywords include 'abstract', 'public', 'static', and 'void', while 'const' and 'goto' are reserved but not used.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Keywords

In java programming language keywords are special tokens which have reserved
use.
They implement specific features of the language. Keywords in java represent
predefined actions, internal processes etc.

Features of Java Keywords


Lower case letter are written by all keywords.
We can changing one or more letter to upper case by using some words as
identifiers, since java is case sensitive.
According to syntax, these keywords combined with operators and separators,
form definition of the Java language.
We cannot use keywords as variables, classes, methods etc.., because keywords are
specific meaning in java.
Java language has reserved 51 words as keywords, out of these 49 are in use and 2
are not in use.

Categories of Java Keywords

Access modifiers:- private, protected, public

Class method variables modifier: — abstract, class, extends, final, implements,


interface, native, new, static, synchronized, transient, volatile.

Flow control:- break, case, continue, default, do, else, for, if, instance of, return,
switch, while.

Package control:- import, package.

Primitive types:- boolean, byte, char, double, float, int, long, short.

Error handling:- assert, catch, finally, throw, throws, try

Enumeration:- Enum.

Others:- super, this, void.


Unused:- Const, goto

Following is java keywords in alphabetical order

Abstract
The abstract keyword is use to declare a class or a method as abstract. Abstract
specifies that a class or methods will be implemented later, in a sub-class

Assert
Assert is a java keyword is used to define an assert statement is used to declare an
expected Boolean condition in a program.
Assertion enables developers to test assumptions in their program in compile time
as a way to defect and fix bugs, it continue since java 1.4.

Boolean
Boolean keyword is a data type that can only take the value true or false The
Boolean keyword is used to declare return type of a method

Break

In java break keyword stops execution of for loop, while loop and switch-case
construct.When the construct is broken, then the next statement is executed.

Byte
In java, the byte keyword is used to declare a variable as a numeric type.
A byte value can hold an 8-bits integer. The byte keyword declared return type of
method.

Case
Each case is tested from top to bottom, until a case is matched and a break
statement is found. If a case matches the expression, the statement block after the
case clause are executed, until a break statement is reached. The switch-case
construct is a flow control structure that tests value of a variable against a list of
value.

Catch
Catches exception generated by try statement.
Char
In java, the char keyword is used to declare a variable as a character type.
A char variable represents a single character.

Class
The class keyword is used to declare a class, in java programing. Class is a
fundamental structure in object oriented programing

Const
In java const is a reserved keyword are not being used

Continue
In java, the continue keyword is use to stop execution of a current repetition in a
for loop or a while loop, then advance to the next repetition.

Default
Basically, there are three places you can use the default keyword in java
Specially the default value in switch case statement.
Declare default values in a java annotation.
Declare default method in an interface.

Do
The do-while construct is a loop structure which iteratively executes one or some
statements until a condition becomes false. In other words, it repeats the statements
while the condition is true.

Double
In java, the double keyword is used to declare a variable as a numeric type .
A double value can hold a 64-bit floating number.

Else
In java, the if-else construct is used to check if a condition is satisfy then do
something, otherwise do something else.

Enum
In java, the enum keyword is used to declare a new enumeration type. This
keyword has been introduced since java 5.
Extend
In java, when class declaring a class as a subclass of another class, the extends
keyword is used

Final
In java, the final keyword can be applied to declaration of classes, methods and
variables.

Finally
It indicates a block of code in a try catch structure that will always be executed

Float
A data type that holds a 32-bit floating point number

For
It is used to start a for loop.

If
it tests a true/false expression and branches accordingly

Implements
It specifies that implement class in an interface.

Import
It references other classes

Instanceof
It indicates whether an object is an instance of a specific class or implements an
interface

Int
A data type that can hold 32-bit signed integer

Interface
Declares an interface

Long
It can hold a 64-bit integer and it is one type of data type.

Native
Specifies that a method is implemented with native code

New
Creates new objects.

Null
Now it is not use.

Package
An access specifier indicating that a method or variable may be accessed only in
the class it’s declared in

Private
An access specifier indicating that a method or variable may be accessed only in
the class it’s declared in privately, it means it dose not run any where.

Protected
An access specifier indicating that a method or variable may only be accessed in
the class it’s declare in ( or a subclass of the class it’s declared in or other classes
in the same package) .

Public
An access specifier used for classes, interfaces, methods, and variables indicating
that an item is accessible throughout the application (or where the class that defines
it is accessible).

Return
Send control and possibly a return value back from a called method.
Short
It can hold a 16-bit integer and it is a data type.

Static
Indicates that a variable or method is class method (rather than being limited to one
particular object)

Super
Refers to a class base class.

Switch
Switch statement that executes code based on a test value.

Synchronized
Multithread code is specify by critical section or methods

This
The current object is refer by a method or constructor.

Throw
Creates an exception.

Throws
It indicates what exception may be thrown by a method.

Transient
Specifies that a variable not part of an objects persistent state.

Try
Starts a block of code that will be tested for exceptions.

Void
Specifies that a method does not have a return value.

Volatile
Indicates that a variable may change asynchronously.
While
Starts a while loop.

Other important facts about keyword:


Const and go to are reserved words but not used.
True, false and null are literals, not keywords.

Since java 8, the default keyword is also used to declare default method in
interfaces.

Since java 10, the word var is used to declare local variables. For backward
compatibility, you can still use var as variable names. So var is a reserve word not
keyword.

Java 14 adds two new keywords record & yield (but in preview mode)

Common questions

Powered by AI

The 'try-catch-finally' construct manages exception handling in Java by allowing a program to attempt block execution ('try'), manage exceptions via handlers ('catch'), and execute critical code irrespective of exceptions ('finally'). It enhances program reliability by ensuring that programs handle exceptions gracefully, recovering from errors with encapsulated code execution, maintaining program flow, and freeing resources through the 'finally' block, even when exceptions occur.

Java keywords are reserved tokens that implement specific language features and form the definition of the Java language by combining with operators and separators . In program design, they ensure that keywords cannot be used as variables, classes, or method names because they have specific predefined meanings . This enforces syntactical correctness and aids in clearly defining program structure, facilitating object-oriented programming principles such as encapsulation and inheritance through keywords like private, protected, public, and extends .

The 'abstract' keyword defines classes and methods that must be implemented in subclasses, promoting polymorphism via inheritance and permitting methods to have varying implementations across different subclasses . The 'interface' keyword supports polymorphism by allowing definitions of method contracts without implementations, enabling multiple inheritance through class implementations of interfaces . Together, they define structured APIs and enforce consistent method signatures while allowing diverse implementations, core to polymorphic behavior.

Access modifiers in Java enforce encapsulation by controlling the visibility and accessibility of classes, methods, and variables . The 'private' modifier restricts access to declare elements strictly within the class . 'Protected' allows access within the same package or subclasses . 'Public' permits unrestricted access across the application where the class or interface is accessible . These modifiers ensure that internal implementation details remain hidden and secure, promoting modularity and data protection.

The 'final' keyword in Java ensures immutability and prevents modification. When used with classes, it prevents the class from being subclassed, providing security and consistency . Applied to methods, it prohibits method overriding in subclasses, ensuring method behavior remains unchanged across different implementations . For variables, 'final' makes variables constants, which must be initialized at declaration and cannot be modified thereafter, aiding in defining unmodifiable program constants.

The keyword 'null' in Java represents the literal value for an uninitialized object reference . Unlike other Java keywords that represent actions, data types, or control structures, 'null' is not a keyword but a literal . Its unique role is to indicate the absence of a value, often used to check for uninitialized or released objects, which can affect program flow and error handling. Recognizing 'null' as a non-keyword emphasizes the differentiation between Java's reserved syntax and data literals.

Both 'throw' and 'throws' are integral to Java's exception handling. The 'throw' keyword is used within a method to create and push a new exception object onto the call stack, effectively triggering an exception . In contrast, 'throws' is declared in a method signature to indicate which exceptions a method might throw . It helps developers understand possible exception outcomes of method execution and enforces proper handling of checked exceptions to promote robust error management.

In Java, the 'instanceof' keyword checks if an object or its subclass belongs to a specified type or class . It returns a boolean value, 'true' if the object is an instance, or 'false' otherwise. This facilitates safe type casting and prevents ClassCastException by verifying object types before performing operations that require specific class types, offering advantages in dynamic type checking within polymorphic behavior contexts.

The 'static' keyword designates a variable or method as belonging to the class rather than an instance of the class. This means that static variables are shared among all instances of the class, and static methods can be called without creating an instance of the class . It allows for memory efficiency and reduces the need for multiple instances when shared resources or utility functions are needed across the class instances.

The 'synchronized' keyword is crucial in Java for controlling access to critical sections of code by multiple threads . It ensures that only one thread can access a method or block of code at any given time, which prevents data inconsistencies and race conditions in a multithreaded environment. By using 'synchronized', developers can set locks on objects or class methods to maintain data integrity and consistency by synchronizing threads' interactions with shared resources.

You might also like