BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Java Keywords With Examples

By Chaitanya Singh | Filed Under: java

List of keywords and their usages in Java Programming language. To learn more about a specific keyword, just click on the keyword and it will take you to a separate keyword tutorial where you can find examples and more details about that particular keyword.

KeywordDescription
abstractUsed for classes and methods. An abstract class cannot be instantiated, which means you cannot create an object of this class, it can be used through inheritance in sub class. An abstract method does not have a body and can only be declared inside abstract class, the method is overriden in sub class, where it can have a body.
booleanIt is a data type, which is used to declare a variable. A boolean variable can hold only true or false values. A boolean keyword can also be used be as a return type of a method.
breakThe break keyword is used to end the execution of the loops such as for, while, do-while, it can also be used inside a switch block to form switch-case. It is generally accompanied by a condition inside a loop, when the condition is meet, the break statement is encountered and it ends the loop.
byteThe byte keyword is a data type. It can hold values in the range of -128 to 127.
caseIt is used along with switch statement to form a switch-case block, this switch case block is used to evaluate a given condition and execute corresponding block based on the output of condition.
catchUsed with try block to handle an exception.
charIt is a primitive data type. It is used to store a single character. Size is 2 bytes and it can print characters for ASCII values between 0 and 65,535.
classThe class keyword is used to create a class.
continueThe continue statement is used inside a loop to directly jump to the next iteration of the loop, skipping the statements after continue statement for this iteration.
defaultUsed inside switch block. It specifies the default case in switch, which executes when there is no matching case block is found.
doUsed in do-while loop. The do-while loop checks the loop condition after the first execution of the loop body so it executes at-least once for any condition.
doubleIt is a primitive data type. The range is 1.7e-308 to 1.7e+308.
elseIt is used along with if for if-else conditional statement.
enumThe enum keyword is used to define a set of constants.
extendsIt is used in inheritance, where sub class can access the methods and variables of the parent class.
finalIt is used with class, variables and methods. It marks them final (non-changeable).
finallyThe finally keyword used in exception handling. The finally block always executes whether an exception occurs or not.
floatA primitive data type used for floating point numbers. The range is 3.4e-038 to 3.4e+038.
forThe for keyword is used for creating a for loop.
ifIf statement checks a condition and executes statements inside if body, only when the condition returns true.
implementsIt is used for implementing an interface.
importThe import keyword is used for importing a package.
instanceofIt checks if the object is an instance of the given class or interface.
intA primitive data type for whole numbers. The range is -2147483648 to 2147483647.
interfaceUsed to create an interface that contains abstract methods (method without body), these methods are given body in sub class using method overriding.
longA primitive data type, which is used for storing whole numbers. It has a bigger range than int data type. The range of long is -9223372036854775808 to 9223372036854775808.
nativeIt specifies that method is implemented in native code and not included in the java source code file.
newIt is used for creating new objects of classes.
nullIt specifies that object does not refer to anything in the memory.
packageUsed for creating packages. These packages contain classes. Similar types of classes are included in same package. This helps in grouping the classes in a meaningful manner.
privateThe private keyword is used for variables, methods and constructors. It is the most restrictive access modifier, which makes them only accessible within the class.
protectedIt is used for variables, methods and constructors. It makes them accessible within the same package and in the subclasses only.
publicIt is the least restrictive access modifier. It is used for classes, methods, variables and constructors. It makes them accessible by any class.
returnUsed by a method to return a value.
shortA primitive data type, which is used for storing whole numbers but the range is shorter than int. The range of short data type is: -32768 to 32767.
staticThe static keyword is used for variables and methods. Such methods and variables can be accessed without creating the object of the class.
strictfpUsed for floating point numbers portability. The precision is system dependent so strictfp restricts the precision and rounding of floating point numbers.
superRefers to the parent class object.
switchConditional statement, that evaluates a given condition and executes the corresponding case block.
synchronizedIt is used to control multithreading. It specifies that a method can be only accessed by one thread at a time.
thisRefers to the object of current class.
throwIt is used to throw exception explicitly.
throwsIt is used to declare an exception. Mainly used for checked exceptions.
transientThe transient keyword is used in serialization.
tryIt is used in exception handling. The set of statements that can throw an exception are placed inside try block.
voidSpecifies that a method does not return anything.
volatileSpecifies that a variable is accessed directly from main memory and may be changed asynchronously.
whileThe while keyword is used to create a while loop.

Java Tutorial

Java Introduction

  • Java Index
  • Java Introduction
  • History of Java
  • Features of Java
  • C++ vs Java
  • JDK vs JRE vs JVM
  • JVM - Java Virtual Machine
  • First Java Program
  • Variables
  • Data Types
  • Operators

Java Flow Control

  • Java If-else
  • Java Switch-Case
  • Java For loop
  • Java while loop
  • Java do-while loop
  • Continue statement
  • break statement

Java Arrays

  • Java Arrays

OOPs Concepts

  • OOPs Concepts
  • Constructor
  • Java String
  • Static keyword
  • Inheritance
  • Types of inheritance
  • Aggregation
  • Association
  • Super Keyword
  • Method overloading
  • Method overriding
  • Overloading vs Overriding
  • Polymorphism
  • Types of polymorphism
  • Static and dynamic binding
  • Abstract class and methods
  • Interface
  • Abstract class vs interface
  • Encapsulation
  • Packages
  • Access modifiers
  • Garbage Collection
  • Inner classes
  • Static import
  • Static constructor

Java Exception Handling

  • Exception handling
  • Java try-catch
  • Java throw
  • Java throws
  • Checked and Unchecked Exceptions
  • Jav try catch finally
  • Exception Examples
  • Exception Propagation

Collections Framework

  • Collections in Java
  • Java ArrayList
  • Java LinkedList
  • Java Vector
  • Java HashSet
  • Java LinkedHashSet
  • Java TreeSet
  • Java HashMap
  • Java TreeMap
  • Java LinkedHashMap
  • Java Queue
  • Java PriorityQueue
  • Java Deque
  • Comparable interface
  • Comparator interface
  • Collections Interview Questions

MORE ...

  • Java Scanner Class
  • Java 8 Features
  • Java 9 Features
  • Java Conversion
  • Java Date
  • Java Multithreading
  • Java I/O
  • Java Serialization
  • Java Regex
  • Java AWT
  • Java Swing
  • Java Enum
  • Java Annotations
  • Java main method
  • Java Interview Q

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap