0% found this document useful (0 votes)
31 views8 pages

Java Programming Language Keywords List

This document lists and describes Java keywords that are relevant for programming in Java. It covers keywords used for class, field, and method declarations as well as keywords that control program flow and handle errors and exceptions. Less commonly used keywords for threading, serialization, and floating point calculations are also mentioned.

Uploaded by

gaurav7771
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)
31 views8 pages

Java Programming Language Keywords List

This document lists and describes Java keywords that are relevant for programming in Java. It covers keywords used for class, field, and method declarations as well as keywords that control program flow and handle errors and exceptions. Less commonly used keywords for threading, serialization, and floating point calculations are also mentioned.

Uploaded by

gaurav7771
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

Java keywords

Keywords of the Java programming


language (Java 8)
Keywords of interest
In the Programming in Java book, we are concerned with the following
keywords:

abstract continue for package this


assert default if private throw
boolean double implements protected throws
break else import public try
byte enum instanceof return void
case extends int short while
catch final interface static
char finally long super
class float new switch
Keywords of interest - classes
The following keywords are relevant when declaring a class (or enum or
interface):

Context (before the actual class definition):


import package
Access level:
private protected public
Other modifier:
abstract final static
Entity (what are we declaring):
enum interface class
Hierarchy:
implements extends
Keywords of interest - fields (variables) of a class
The following keywords are relevant when declaring fields:

Access level:
private protected public
Other modifier:
final static
Type:
boolean byte char double float int long short

Note that classes like String when used as types are not keywords, they are identifiers (names)!
Keywords of interest - method declarations
For declaring methods of a class:

Access level:
private protected public
Other modifier:
abstract final static
Type:
boolean byte char float double int long short void
Exception signal:
throws
Keywords of interest - code which does something
The following keywords are used when writing code which doesn something,
like the body of constructors and methods (and initializers):

Control flow:
continue for if break else return switch case while finally
Errors and exceptions:
assert throw try catch
(Local) Variable declarations:
boolean byte char double float int long short
final
Tests:
instanceof
Dereferencing
this super
Creation:
new
The rest (outside of the scope of this book/course)
Thread syncronization:
synchronized
Serialization:
transient
Floating point calculations:
strictfp
Concurrency/atomicity:
volatile
Methods written in other languages (differ between Java installations):
native
Java 8 interface default method modifier:
default
Further reading
● [Link]
● [Link]
l
● [Link]
ml
● [Link]

(For those who really want to know more!)

Common questions

Powered by AI

The 'strictfp' keyword in Java ensures consistent floating-point calculations across different platforms by enforcing IEEE 754 standards for floating-point arithmetic. This means that expressions are evaluated with specific precision and rounding behavior, which is crucial for applications requiring predictable and consistent floating-point results across diverse hardware environments, such as scientific computations and financial applications.

In Java, 'continue' and 'break' keywords influence the control flow within loops. 'continue' skips the current iteration and proceeds with the next cycle of the loop, which is particularly useful for bypassing specific conditions without exiting the loop entirely. Meanwhile, 'break' immediately terminates the loop, transferring control to the statement following the loop, which is useful for exiting the loop based on a specific condition being met. These keywords enhance the flexibility and readability of loop constructs.

'Default' methods in interfaces, introduced in Java 8, allow interfaces to have method implementations, enhancing backward compatibility. This allows new methods to be added to interfaces without breaking existing implementations. Classes implementing the interface can either use the provided default implementation or override it if needed, facilitating incremental interface evolution while sparing existing implementations from immediate changes. This adds versatility by allowing developers to improve interfaces over time without disrupting existing codebases.

Java keywords such as 'extends' and 'implements' are fundamental to class hierarchy and polymorphism. 'extends' allows a class to inherit properties and behavior from a superclass, enabling method overriding to support dynamic method dispatch. 'implements' allows a class to adopt interface contracts, ensuring that it provides specific behaviors outlined, facilitating polymorphic interface implementations. This structure supports flexible program design and reusable code.

The access level keywords in Java (private, protected, and public) regulate the visibility and accessibility of classes and their members, controlling which parts of the program can interact with them. 'private' limits access to within the same class, 'protected' allows access to subclasses and package members, and 'public' permits access by any class. This encapsulation is crucial for maintaining a modular and secure codebase.

The 'synchronized' keyword in Java is used to control access to a critical section of code by multiple threads. When a method or block is marked with 'synchronized', only one thread can access it at a time for a given object, preventing thread interference and memory consistency errors. This is crucial in maintaining state integrity in concurrent applications, as it coordinates the thread interactions needed for correct operation of shared mutable data.

The 'throws' keyword in Java is used in method declarations to indicate that a method may throw one or more exceptions. This is part of Java's checked exception mechanism, requiring explicit handling of exceptions in calling methods, thereby promoting robust error management. By declaring exceptions, it ensures that exceptions are either caught or forwarded to the next higher level of the application crash hierarchy, thereby increasing program reliability.

In Java, 'final' and 'abstract' modifiers serve distinct yet critical roles in method and class declarations. A 'final' class or method cannot be extended or overridden, providing stability and protecting critical functionality from alteration. Conversely, an 'abstract' class cannot be instantiated directly, necessitating subclass extensions that provide implementations for its abstract methods. This is crucial for enforcing a design template that subclasses must adhere to, facilitating a cohesive system architecture.

The 'new' keyword in Java facilitates object creation by allocating memory for a new object and initializing it via a constructor call. The 'super' keyword is used within a subclass constructor to invoke a specific superclass constructor, ensuring the superclass's part of the object is initialized correctly. This coordination between 'new' and 'super' is vital for executing construction sequences that maintain the invariant of class hierarchies, enabling structured and predictable object initialization.

The 'instanceof' keyword in Java serves as a test mechanism to verify whether a specific object is an instance of a particular class or subclass. It returns a boolean value, true if the object is an instance of the specified class, allowing developers to safely cast objects and implement logic based on object types, enhancing type safety and reducing runtime errors. This keyword is pivotal in polymorphic algorithms and dynamic type checks.

You might also like