0% found this document useful (0 votes)
81 views

List of All Java Keywords - GeeksforGeeks

Uploaded by

Ananya Sharma
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)
81 views

List of All Java Keywords - GeeksforGeeks

Uploaded by

Ananya Sharma
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/ 1

GEEKSFORGEEKS

List of all Java Keywords


Keywords or Reserved words are the words in a
language that are used for some internal process or
represent some predefined actions. These words are
therefore not allowed to use as variable names or
objects. If we do we will get a compile-time error as
shown below as follows:

Illustration:

Java

// Java Program to Illustrate What If


// Code Contributed by @Shubham Jain

class HelloWorld {
public static void main(String[] a
{

int this = "Hello World!"; //


System.out.println(this);
}
}

Output:

Errors in Code : Compiler Error

prog.java:11: error: not a statement

int this = "Hello World!"; // Note "this

prog.java:11: error: ';' expected

int this = "Hello World!"; // Note "this

2 errors

Java contains a list of keywords or reserved words


which are also highlighted with different colors be it an
IDE or editor in order to segregate the differences
between flexible words and reserved words. They are
listed below in the table with the primary action
associated with them.

S.No Keyword Usage

Specifies that a class or method


1. abstract will be implemented later, in a
subclass

Assert describes a predicate


placed in a java program to
2. assert indicate that the developer thinks
that the predicate is always true at
that place.

A data type that can hold True and


3. boolean
False values only

A control statement for breaking


4. break
out of loops.

A data type that can hold 8-bit


5. byte
data values

Used in switch statements to mark


6. case
blocks of text

Catches exceptions generated by


7. catch
try statements

A data type that can hold


8. char unsigned 16-bit Unicode
characters

9. class Declares a new class

10. continue Sends control back outside a loop

Specifies the default block of


11. default
code in a switch statement

12. do Starts a do-while loop

A data type that can hold 64-bit


13. double
floating-point numbers

Indicates alternative branches in


14. else
an if statement

A Java keyword is used to declare


an enumerated type.
15. enum
Enumerations extend the base
class.

Indicates that a class is derived


16. extends
from another class or interface

Indicates that a variable holds a


17. final constant value or that a method
will not be overridden

Indicates a block of code in a try-


18. finally catch structure that will always be
executed

A data type that holds a 32-bit


19. float
floating-point number

20. for Used to start a for loop

Tests a true/false expression and


21. if
branches accordingly

Specifies that a class implements


22. implements
an interface

23. import References other classes

Indicates whether an object is an


24. instanceof instance of a specific class or
implements an interface

A data type that can hold a 32-bit


25. int
signed integer

26. interface Declares an interface

A data type that holds a 64-bit


27. long
integer

Specifies that a method is


28. native implemented with native
(platform-specific) code

29. new Creates new objects

This indicates that a reference


30. null
does not refer to anything

31. package Declares a Java package

An access specifier indicating that


a method or variable may be
32. private
accessed only in the class it’s
declared in

An access specifier indicating that


a method or variable may only be
accessed in the class it’s declared
33. protected
in (or a subclass of the class it’s
declared in or other classes in the
same package)

An access specifier used for


classes, interfaces, methods, and
variables indicating that an item is
34. public
accessible throughout the
application (or where the class
that defines it is accessible)

Sends control and possibly a


35. return return value back from a called
method

A data type that can hold a 16-bit


36. short
integer

Indicates that a variable or


method is a class method (rather
37 static
than being limited to one
particular object)

A Java keyword is used to restrict


the precision and rounding of
38. strictfp
floating-point calculations to
ensure portability.

Refers to a class’s base class


39. super (used in a method or class
constructor)

A statement that executes code


40. switch
based on a test value

Specifies critical sections or


41. synchronized
methods in multithreaded code

Refers to the current object in a


42. this
method or constructor

43. throw Creates an exception

Indicates what exceptions may be


44. throws
thrown by a method

Specifies that a variable is not


45. transient
part of an object’s persistent state

Starts a block of code that will be


46. try
tested for exceptions

Specifies that a method does not


47. void
have a return value

This indicates that a variable may


48. volatile
change asynchronously

49. while Starts a while loop

Note:

The keywords const and goto are reserved,


even they are not currently in use.
Currently they are no longer supported in Java.

const Reserved for future use

goto Reserved for future use

true, false and null look like keywords, but in


actual they are literals. However they still can’t
be used as identifiers in a program.
These keywords cannot be used as a variable.
Check out this article for more on the rules of
variable declarations.

Article Tags : Java Java-keyword

Recommended Articles
1. Important Keywords in Java
2. super and this keywords in Java
3. Difference between volatile and transient keywords in
Java
4. Difference Between java.sql.Time, java.sql.Timestamp
and java.sql.Date in Java
5. Program to convert List of Integer to List of String in Java
6. Program to convert List of String to List of Integer in Java
7. How to iterate over a 2D list (list of lists) in Java
8. Java Program to Access the Part of List as List
9. Java Program to Rotate the sub-list of a linked list from
position M to N to the right by K places
10. Java Program to List all Files in a Directory and Nested
Sub-Directories
11. How to Copy and Add all List Elements to an Empty
ArrayList in Java?
12. How to Convert all LinkedHashMap Key-Value pairs to
List in Java?
13. How to Convert all LinkedHashMap Values to a List in
Java?
14. Java Program to Maximize sum of diagonal of a matrix
by rotating all rows or all columns
15. Java Program to Rotate all odd numbers right and all
even numbers left in an Array of 1 to N
16. How to Convert java.sql.Date to java.util.Date in Java?
17. Different Ways to Convert java.util.Date to
java.time.LocalDate in Java
18. How to Convert java.util.Date to java.sql.Date in Java?
19. Sum of all Palindrome Numbers present in a Linked list
20. Different Ways to Get List of All Apps Installed in Your
Android Phone
21. Swapping items of a list in Java : Collections.swap()
with Example
22. Factory method to create Immutable List in Java SE 9
23. Java Program to Compute the Sum of Numbers in a List
Using Recursion
24. Set to List in Java
25. List to Set in Java

Read Full Article

A-143, 9th Floor, Sovereign Corporate Tower,


Sector- 136, Noida, Uttar Pradesh (201305)
feedback@geeksforgeeks.org

Company

About Us
Careers
In Media
Contact Us
Privacy Policy
Copyright Policy
Advertise with us

Learn

DSA
Algorithms
Data Structures
SDE Cheat Sheet
Machine Learning
CS Subjects
Video Tutorials
Courses

NEWS

Top News
Technology
Work & Career
Business
Finance
Lifestyle
Knowledge

Languages

Python
Java
CPP
Golang
C#
SQL
Kotlin

Web Development

Web Tutorials
Django Tutorial
HTML
JavaScript
Bootstrap
ReactJs
NodeJs

Contribute

Write an Article
Improve an Article
Pick Topics to Write
Write Interview Experience
Internships
Video Internship

@geeksforgeeks, Some rights reserved

You might also like