Home > Java > javaTutorial > body text

Java Keywords

王林
Release: 2024-08-30 15:21:03
Original
200 people have browsed it

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.Java Keywords2. Assert: The ‘assert’ keyword was added to Java 1.4. This keyword allows a programmer to test his assumptions in the program.Java Keywords3. Boolean: Boolean is a data type that can hold only two values; it’s either a ‘True’ or a ‘False’.Java Keywords4. 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.Java Keywords5. Byte: Byte keyword is one of the data types that are able to store whole numbers. The numbers range from -128 to 127Java Keywords6. Case: Case keyword is used in a switch statement. The ‘case’ keyword creates a block of code and marks it.Java Keywords7. Catch: The ‘catch’ keyword catches the exceptions that were created by the ‘try’ statements. The catch block is used after Try block.Java Keywords8. Char: The ‘char’ is one of the data types that is used to hold one character at a time.Java Keywords9. Class: The class keyword is used to create a class in java. Everything that runs in Java programming resides inside a class.Java Keywords10. 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.Java Keywords11. 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.Java Keywords12. 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.Java Keywords13. 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’.Java Keywords14. 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.Java Keywords15. Enum: The ‘enum’ keyword is used to create enumerations, unchangeable data types. The enum keyword defines a fixed set of constants.Java Keywords16. Extends: Extends keyword is used to inherit properties of a superclass’s attributes and methods by a subclass.Java Keywords17. 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.Java Keywords When hovered over, it shows the following error.Java Keywords18. Finally: Finally keyword is used along try and catch statements, which has a block that is executed even if the exception is not handled.Java Keywords19. 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’.Java Keywords20. 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.Java Keywords21. If: The ‘If’ keyword is used to create a set or block of code or statements that are executed if the condition is ‘True’.Java Keywords22. 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.Java Keywords23. Import: The import keyword is used for importing packages or a class or classes or maybe an interface as well.Java Keywords24. Instanceof: The ‘instanceof’ keyword is used to check if the object in question is an instance of the class or the interface.Java Keywords25. Int: The ‘int’ keyword is one of the data types for declaring an integer type.Java Keywords26. 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.

Java Keywords

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’.

Java Keywords

28. New: The ‘new’ keyword is used to create an object.

Java Keywords

29. Package: The ‘package’ keyword is used to create packages.Java Keywords30. 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.Java Keywords31. Protected: ‘Protected’ is an access modifier that allows the properties or methods to be used only by the same package or subclasses.Java Keywords32. 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.Java KeywordsClass – Test2.javaJava Keywords33. 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.Java Keywords34. Short: The ‘short’ keyword is a type of data type that is used to hold the whole number ranging from -32768 to 32767.Java Keywords35. Static: The ‘static’ keyword is used to create a method static, which means that method can be called without creating its object.Java Keywords36. Super: The ‘super’ keyword is used to call the super or parent class or objects.Java Keywords37. 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.Java Keywords38. This: the ‘this’ keyword is used to refer to the current object of a method or a constructor.Java Keywords39. Throw: The ‘throw’ keyword is used to throw an exception message on the screen for the user.Java Keywords40. 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.Java Keywords42. Void: The ‘void’ keyword, when used with a method, specifies that the method will not have a return value.Java Keywords43. While: The ‘while’ keyword creates a loop with a condition in its statements. The loop is executed until the statement is true.Java Keywords

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!

Related labels:
source:php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!