A Java keyword is a reserved word in a programming language that is not used as an Identifier. Java Keywords are called reserved words because they are ‘reserved’ by the language you are using. They have a special meaning which is defined in the library of the language.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
The concept in Java Programming Language
Like any other programming language, a Keyword in Java programming language is a reserved word with a special meaning. Keywords are reserved for internal processes and have some predefined actions. In Java, if the keywords are used otherwise, the program or code will encounter a ‘Compile Time Error.’ For ease of use for the programmer and identification of the Keywords, generally, they are a bit ‘highlighted’ in Java.
List of Keywords in Java
We have tried to list the important keywords in use currently in Java below in alphabetical order. You can also observe the working of every keyword by following the given examples for the same. Let’s see these keywords one by one.
1. Abstract: Abstract The keyword is used to declare a class to be used later in the abstract program. Abstract used with a class declaration makes that class an abstract and specifies that the class will be implemented in a subclass at a later stage. Below is an example of the usage of the ‘Abstract’ keyword.2. Assert: The ‘assert’ keyword was added to Java 1.4. This keyword allows a programmer to test his assumptions in the program.
3. Boolean: Boolean is a data type that can hold only two values; it’s either a ‘True’ or a ‘False’.
4. Break: This keyword helps the programmer want his code to jump out of a loop, for example, a For loop. It’s a control statement that breaks the current flow of the execution on a specific condition provided by the programmer.
5. Byte: Byte keyword is one of the data types that are able to store whole numbers. The numbers range from -128 to 127
6. Case: Case keyword is used in a switch statement. The ‘case’ keyword creates a block of code and marks it.
7. Catch: The ‘catch’ keyword catches the exceptions that were created by the ‘try’ statements. The catch block is used after Try block.
8. Char: The ‘char’ is one of the data types that is used to hold one character at a time.
9. Class: The class keyword is used to create a class in java. Everything that runs in Java programming resides inside a class.
10. Continue: The ‘continue’ keyword is used to skip the current execution and continues to the next step in a loop like a For loop or a While loop.
11. Default: The ‘Default’ keyword is used to create a default block of code containing a set of statements executed by default if the required case is not present.
12. Do: The ‘do’ keyword is used when creating a ‘do-while’ loop. The ‘do’ block is executed at least once before checking the condition in a while block.
13. Double: The ‘double’ keyword is one of the data types used for holding fractional numbers. The fractional numbers range from 1.7e – 308 to 1.7e + 308. While declaring a fraction, the value is ended with a ‘d’.
14. Else: The ‘Else’ keyword is used to create a block of code that will be executed if the condition is not ‘True’ in an ‘If’ statement.
15. Enum: The ‘enum’ keyword is used to create enumerations, unchangeable data types. The enum keyword defines a fixed set of constants.
16. Extends: Extends keyword is used to inherit properties of a superclass’s attributes and methods by a subclass.
17. Final: The ‘Final’ keyword is used to set a final value to a variable, making it impossible to overwrite or change altogether. If the value of a final variable is tried to change, it throws an error.
When hovered over, it shows the following error.
18. Finally: Finally keyword is used along try and catch statements, which has a block that is executed even if the exception is not handled.
19. Float: The float keyword is a data type that holds fractional numbers that range from 3.4e−038 to 3.4e+038. While declaring a fractional number, the value should be ended with an ‘f’.
20. For: The ‘For’ keyword is used to create a loop, a for a loop. The for loop executes the enclosed set of code a number of times, which is defined inside the for loop condition statement.
21. If: The ‘If’ keyword is used to create a set or block of code or statements that are executed if the condition is ‘True’.
22. Implements: Implement is another keyword that is reserved for declaring interfaces. It is used during the declaration of the class and specifies one or more interfaces.
23. Import: The import keyword is used for importing packages or a class or classes or maybe an interface as well.
24. Instanceof: The ‘instanceof’ keyword is used to check if the object in question is an instance of the class or the interface.
25. Int: The ‘int’ keyword is one of the data types for declaring an integer type.
26. Interface: The interface keyword is used to declare a special type of class that will only contain abstract methods. For accessing the interface methods, the interface must be “implemented” like we use the inheritance concept by another class by using the ‘implements’ keyword.
27. Long: The ‘long’ keyword is again one of the data types for holding whole numbers. They range from -9223372036854775808 to 9223372036854775808. The whole number value should end with an ‘L’.
28. New: The ‘new’ keyword is used to create an object.
29. Package: The ‘package’ keyword is used to create packages.30. Private: The ‘private’ keyword is used to create attributes or methods for a private mode class. ‘Private’ is an access modifier that allows only the declared class to use private properties or attributes or methods.
31. Protected: ‘Protected’ is an access modifier that allows the properties or methods to be used only by the same package or subclasses.
32. Public: The ‘public’ keyword is another access modifier that allows one class to use a publicly defined class’s attributes or methods or etc., within itself.
Below is a publicly defined class ‘test.java’ and another class, class ‘Test2.java’, access it.Class – Test2.java
33. Return: The ‘return’ keyword can be used as an execution end for a method, and also, it is used to return a value from a method.
34. Short: The ‘short’ keyword is a type of data type that is used to hold the whole number ranging from -32768 to 32767.
35. Static: The ‘static’ keyword is used to create a method static, which means that method can be called without creating its object.
36. Super: The ‘super’ keyword is used to call the super or parent class or objects.
37. Switch: The ‘switch’ keyword is used to create different scenarios into different cases and is used to select one out of them. The switch statement contains a value or expression, which then is compared with all the cases present, and the match one is selected.
38. This: the ‘this’ keyword is used to refer to the current object of a method or a constructor.
39. Throw: The ‘throw’ keyword is used to throw an exception message on the screen for the user.
40. Throws: The ‘throws’ keyword is used when the programmer want to decide and throw a type of exception.41 specifically. Try: The ‘try’ keyword starts a ‘try-catch’ block. The ‘try’ block is where the exceptions are tested.
42. Void: The ‘void’ keyword, when used with a method, specifies that the method will not have a return value.
43. While: The ‘while’ keyword creates a loop with a condition in its statements. The loop is executed until the statement is true.
Keywords are the tokens in the Java programming language that are reserved and have special meaning. They have a reserved use and a predefined action in the language.
The above is the detailed content of Java Keywords. For more information, please follow other related articles on the PHP Chinese website!

Start Spring using IntelliJIDEAUltimate version...

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

Java...

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to set the SpringBoot project default run configuration list in Idea using IntelliJ...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

WebStorm Mac version
Useful JavaScript development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.