Recent from talks
Nothing was collected or created yet.
Java (programming language)
View on Wikipedia
| Java | |
|---|---|
| Paradigm | Multi-paradigm: generic, object-oriented (class-based), functional, imperative, reflective, concurrent |
| Designed by | James Gosling |
| Developer | Oracle Corporation |
| First appeared | May 23, 1995[1] |
| Typing discipline | Static, strong, safe, nominative, manifest |
| Memory management | Garbage-collected |
| Filename extensions | .java, .class, .jar, .jmod, .war |
| Website | |
| Influenced by | |
| CLU,[2] Simula67,[2] Lisp,[2] Smalltalk,[2] Ada 83, C++,[3] C#,[4] Eiffel,[5] Mesa,[6] Modula-3,[7] Oberon,[8] Objective-C,[9] UCSD Pascal,[10][11] Object Pascal[12] | |
| Influenced | |
| Ada 2005, ArkTS, BeanShell, C#, Chapel,[13] Clojure, ECMAScript, Fantom, Gambas,[14] Groovy, Hack,[15] Haxe, J#, JavaScript, JS++, Kotlin, PHP, Python, Scala, Vala | |
| |
Java is a high-level, general-purpose, memory-safe, object-oriented programming language. It is intended to let programmers write once, run anywhere (WORA),[16] meaning that compiled Java code can run on all platforms that support Java without the need to recompile.[17] Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of the underlying computer architecture. The syntax of Java is similar to C and C++, but has fewer low-level facilities than either of them. The Java runtime provides dynamic capabilities (such as reflection and runtime code modification) that are typically not available in traditional compiled languages.
Java gained popularity shortly after its release, and has been a popular programming language since then.[18] Java was the third most popular programming language in 2022[update] according to GitHub.[19] Although still widely popular, there has been a gradual decline in use of Java in recent years with other languages using JVM gaining popularity.[20]
Java was designed by James Gosling at Sun Microsystems. It was released in May 1995 as a core component of Sun's Java platform. The original and reference implementation Java compilers, virtual machines, and class libraries were released by Sun under proprietary licenses. As of May 2007, in compliance with the specifications of the Java Community Process, Sun had relicensed most of its Java technologies under the GPL-2.0-only license. Oracle, which bought Sun in 2010, offers its own HotSpot Java Virtual Machine. However, the official reference implementation is the OpenJDK JVM, which is open-source software used by most developers and is the default JVM for almost all Linux distributions.
Java 25 is the version current as of September 2025[update]. Java 8, 11, 17, 21, and 25 are long-term support versions still under maintenance.
History
[edit]

James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991.[21] Java was originally designed for interactive television, but it was too advanced for the digital cable television industry at the time.[22] The language was initially called Oak after an oak tree that stood outside Gosling's office. Later the project went by the name Green and was finally renamed Java, from Java coffee, a type of coffee from Indonesia.[23] Gosling designed Java with a C/C++-style syntax that system and application programmers would find familiar.[24]
Sun Microsystems released the first public implementation as Java 1.0 in 1996.[25] It promised write once, run anywhere (WORA) functionality, providing no-cost run-times on popular platforms. Fairly secure and featuring configurable security, it allowed network- and file-access restrictions. Major web browsers soon incorporated the ability to run Java applets within web pages, and Java quickly became popular. The Java 1.0 compiler was re-written in Java by Arthur van Hoff to comply strictly with the Java 1.0 language specification.[26] With the advent of Java 2 (released initially as J2SE 1.2 in December 1998 – 1999), new versions had multiple configurations built for different types of platforms. J2EE included technologies and APIs for enterprise applications typically run in server environments, while J2ME featured APIs optimized for mobile applications. The desktop version was renamed J2SE. In 2006, for marketing purposes, Sun renamed new J2 versions as Java EE, Java ME, and Java SE, respectively.
In 1997, Sun Microsystems approached the ISO/IEC JTC 1 standards body and later the Ecma International to formalize Java, but it soon withdrew from the process.[27][28][29] Java remains a de facto standard, controlled through the Java Community Process.[30] At one time, Sun made most of its Java implementations available without charge, despite their proprietary software status. Sun generated revenue from Java through the selling of licenses for specialized products such as the Java Enterprise System.
On November 13, 2006, Sun released much of its Java virtual machine (JVM) as free and open-source software (FOSS), under the terms of the GPL-2.0-only license. On May 8, 2007, Sun finished the process, making all of its JVM's core code available under free software/open-source distribution terms, aside from a small portion of code to which Sun did not hold the copyright.[31]
Sun's vice-president Rich Green said that Sun's ideal role with regard to Java was as an evangelist.[32] Following Oracle Corporation's acquisition of Sun Microsystems in 2009–10, Oracle has described itself as the steward of Java technology with a relentless commitment to fostering a community of participation and transparency.[33] This did not prevent Oracle from filing a lawsuit against Google shortly after that for using Java inside the Android SDK (see the Android section).
On April 2, 2010, James Gosling resigned from Oracle.[34]
In January 2016, Oracle announced that Java run-time environments based on JDK 9 will discontinue the browser plugin.[35]
Java software runs on most devices from laptops to data centers, game consoles to scientific supercomputers.[36]
Oracle (and others) highly recommend uninstalling outdated and unsupported versions of Java, due to unresolved security issues in older versions.[37]
Principles
[edit]There were five primary goals in creating the Java language:[17]
- It must be simple, object-oriented, and familiar.
- It must be robust and secure.
- It must be architecture-neutral and portable.
- It must execute with high performance.
- It must be interpreted, threaded, and dynamic.
Versions
[edit]As of September 2025[update], Java 8, 11, 17, 21, and 25 are supported as long-term support (LTS) versions.[38]
Oracle released the last zero-cost public update for the legacy version Java 8 LTS in January 2019 for commercial use, although it will otherwise still support Java 8 with public updates for personal use indefinitely. Other vendors such as Adoptium continue to offer free builds of OpenJDK's long-term support (LTS) versions. These builds may include additional security patches and bug fixes.[39]
Major release versions of Java, along with their release dates:
| Version | Date |
|---|---|
| JDK Beta | 1995 |
| JDK 1.0 | January 23, 1996[40] |
| JDK 1.1 | February 19, 1997 |
| J2SE 1.2 | December 8, 1998 |
| J2SE 1.3 | May 8, 2000 |
| J2SE 1.4 | February 6, 2002 |
| J2SE 5.0 | September 30, 2004 |
| Java SE 6 | December 11, 2006 |
| Java SE 7 | July 28, 2011 |
| Java SE 8 (LTS) | March 18, 2014 |
| Java SE 9 | September 21, 2017 |
| Java SE 10 | March 20, 2018 |
| Java SE 11 (LTS) | September 25, 2018[41] |
| Java SE 12 | March 19, 2019 |
| Java SE 13 | September 17, 2019 |
| Java SE 14 | March 17, 2020 |
| Java SE 15 | September 15, 2020[42] |
| Java SE 16 | March 16, 2021 |
| Java SE 17 (LTS) | September 14, 2021 |
| Java SE 18 | March 22, 2022 |
| Java SE 19 | September 20, 2022 |
| Java SE 20 | March 21, 2023 |
| Java SE 21 (LTS) | September 19, 2023[43] |
| Java SE 22 | March 19, 2024 |
| Java SE 23 | September 17, 2024 |
| Java SE 24 | 18 March 2025[44] |
| Java SE 25 (LTS) | 16 September 2025[45] |
Editions
[edit]| Java platform editions |
|---|
|
Sun has defined and supports four editions of Java targeting different application environments and segmented many of its APIs so that they belong to one of the platforms. The platforms are:
- Java Card for smart-cards.[46]
- Java Platform, Micro Edition (Java ME) – targeting environments with limited resources.[47]
- Java Platform, Standard Edition (Java SE) – targeting workstation environments.[48]
- Java Platform, Enterprise Edition (Java EE) – targeting large distributed enterprise or Internet environments.[49]
The classes in the Java APIs are organized into separate groups called packages. Each package contains a set of related interfaces, classes, subpackages and exceptions.
Sun also provided an edition called Personal Java that has been superseded by later, standards-based Java ME configuration-profile pairings.
Execution system
[edit]Java JVM and bytecode
[edit]One design goal of Java is portability, which means that programs written for the Java platform must run similarly on any combination of hardware and operating system with adequate run time support. This is achieved by compiling the Java language code to an intermediate representation called Java bytecode, instead of directly to architecture-specific machine code. Java bytecode instructions are analogous to machine code, but they are intended to be executed by a virtual machine (VM) written specifically for the host hardware. End-users commonly use a Java Runtime Environment (JRE) installed on their device for standalone Java applications or a web browser for Java applets.
Standard libraries provide a generic way to access host-specific features such as graphics, threading, and networking.
The use of universal bytecode makes porting simple. However, the overhead of interpreting bytecode into machine instructions made interpreted programs almost always run more slowly than native executables. Just-in-time (JIT) compilers that compile byte-codes to machine code during runtime were introduced from an early stage. Java's Hotspot compiler is actually two compilers in one; and with GraalVM (included in e.g. Java 11, but removed as of Java 16) allowing tiered compilation.[50] Java itself is platform-independent and is adapted to the particular platform it is to run on by a Java virtual machine (JVM), which translates the Java bytecode into the platform's machine language.[51]
Performance
[edit]Programs written in Java have a reputation for being slower and requiring more memory than those written in C++.[52][53] However, Java programs' execution speed improved significantly with the introduction of just-in-time compilation in 1997/1998 for Java 1.1,[54] the addition of language features supporting better code analysis (such as inner classes, the StringBuilder class, optional assertions, etc.), and optimizations in the Java virtual machine, such as HotSpot becoming Sun's default JVM in 2000. With Java 1.5, the performance was improved with the addition of the java.util.concurrent package, including lock-free implementations of the ConcurrentMaps and other multi-core collections, and it was improved further with Java 1.6.
Non-JVM
[edit]Some platforms offer direct hardware support for Java; there are micro controllers that can run Java bytecode in hardware instead of a software Java virtual machine,[55] and some ARM-based processors could have hardware support for executing Java bytecode through their Jazelle option, though support has mostly been dropped in current implementations of ARM.
Automatic memory management
[edit]Java uses an automatic garbage collector to manage memory in the object lifecycle. The programmer determines when objects are created, and the Java runtime is responsible for recovering the memory once objects are no longer in use. Once no references to an object remain, the unreachable memory becomes eligible to be freed automatically by the garbage collector. Something similar to a memory leak may still occur if a programmer's code holds a reference to an object that is no longer needed, typically when objects that are no longer needed are stored in containers that are still in use.[56] If methods for a non-existent object are called, a null pointer exception is thrown.[57][58]
One of the ideas behind Java's automatic memory management model is that programmers can be spared the burden of having to perform manual memory management. In some languages, memory for the creation of objects is implicitly allocated on the stack or explicitly allocated and deallocated from the heap. In the latter case, the responsibility of managing memory resides with the programmer. If the program does not deallocate an object, a memory leak occurs.[56] If the program attempts to access or deallocate memory that has already been deallocated, the result is undefined and difficult to predict, and the program is likely to become unstable or crash. This can be partially remedied by the use of smart pointers, but these add overhead and complexity. Garbage collection does not prevent logical memory leaks, i.e. those where the memory is still referenced but never used.[56]
Garbage collection may happen at any time. Ideally, it will occur when a program is idle. It is guaranteed to be triggered if there is insufficient free memory on the heap to allocate a new object; this can cause a program to stall momentarily. Explicit memory management is not possible in Java.
Java does not support C/C++ style pointer arithmetic,[59] where object addresses can be arithmetically manipulated (e.g. by adding or subtracting an offset). This allows the garbage collector to relocate referenced objects and ensures type safety and security.
As in C++ and some other object-oriented languages, variables of Java's primitive data types are either stored directly in fields (for objects) or on the stack (for methods) rather than on the heap, as is commonly true for non-primitive data types (but see escape analysis). This was a conscious decision by Java's designers for performance reasons.
Java contains multiple types of garbage collectors. Since Java 9, HotSpot uses the Garbage First Garbage Collector (G1GC) as the default.[60] However, there are also several other garbage collectors that can be used to manage the heap, such as the Z Garbage Collector (ZGC) introduced in Java 11, and Shenandoah GC, introduced in Java 12 but unavailable in Oracle-produced OpenJDK builds. Shenandoah is instead available in third-party builds of OpenJDK, such as Eclipse Temurin. For most applications in Java, G1GC is sufficient. In prior versions of Java, such as Java 8, the Parallel Garbage Collector was used as the default garbage collector.[citation needed]
Having solved the memory management problem does not relieve the programmer of the burden of handling properly other kinds of resources, like network or database connections, file handles, etc., especially in the presence of exceptions.[citation needed]
Syntax
[edit]
The syntax of Java is largely influenced by C++ and C. Unlike C++, which combines the syntax for structured, generic, and object-oriented programming, Java was built almost exclusively as an object-oriented language.[17] All code is written inside classes, and every data item is an object, with the exception of the primitive data types, (i.e. integers, floating-point numbers, boolean values, and characters), which are not objects for performance reasons.
Unlike C++, Java does not support operator overloading[61] or multiple inheritance for classes, though multiple inheritance is supported for interfaces.[62]
Java uses comments similar to those of C++. There are three different styles of comments: a single line style marked with two slashes (//), a multiple line style opened with /* and closed with */, and the Javadoc commenting style opened with /** and closed with */. The Javadoc style of commenting allows the user to run the Javadoc executable to create documentation for the program and can be read by some integrated development environments (IDEs) such as Eclipse to allow developers to access documentation within the IDE.
Hello world
[edit]The following is an example of a "Hello, World!" program in the traditional Java syntax:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Java 25 introduced a simplified syntax for the main class and main method, which enables users to write small Java programs succinctly:[63][64]
void main() {
IO.println("Hello World!");
}
Special classes
[edit]This section needs additional citations for verification. (May 2019) |
Applet
[edit]Java applets were programs embedded in other applications, mainly in web pages displayed in web browsers. The Java applet API was deprecated with the release of Java 9 in 2017.[65][66]
Servlet
[edit]Java servlet technology provides Web developers with a simple, consistent mechanism for extending the functionality of a Web server and for accessing existing business systems. Servlets are server-side Java EE components that generate responses to requests from clients. Most of the time, this means generating HTML pages in response to HTTP requests, although there are a number of other standard servlet classes available, for example for WebSocket communication.
The Java servlet API has to some extent been superseded (but still used under the hood) by two standard Java technologies for web services:
- the Java API for RESTful Web Services (JAX-RS 2.0) useful for AJAX, JSON and REST services, and
- the Java API for XML Web Services (JAX-WS) useful for SOAP Web Services.
Typical implementations of these APIs on Application Servers or Servlet Containers use a standard servlet for handling all interactions with the HTTP requests and responses that delegate to the web service methods for the actual business logic.
JavaServer Pages
[edit]JavaServer Pages (JSP) are server-side Java EE components that generate responses, typically HTML pages, to HTTP requests from clients. JSPs embed Java code in an HTML page by using the special delimiters <% and %>. A JSP is compiled to a Java servlet, a Java application in its own right, the first time it is accessed. After that, the generated servlet creates the response.[67]
Swing application
[edit]Swing is a graphical user interface library for the Java SE platform. It is possible to specify a different look and feel through the pluggable look and feel system of Swing. Clones of Windows, GTK+, and Motif are supplied by Sun. Apple also provides an Aqua look and feel for macOS. Where prior implementations of these looks and feels may have been considered lacking, Swing in Java SE 6 addresses this problem by using more native GUI widget drawing routines of the underlying platforms.[68]
JavaFX application
[edit]JavaFX is a software platform for creating and delivering desktop applications, as well as rich web applications that can run across a wide variety of devices. JavaFX is intended to replace Swing as the standard graphical user interface (GUI) library for Java SE, but since JDK 11 JavaFX has not been in the core JDK and instead in a separate module.[69] JavaFX has support for desktop computers and web browsers on Microsoft Windows, Linux, and macOS. JavaFX does not have support for native OS look and feels.[70]
Generics
[edit]In 2004, generics were added to the Java language, as part of J2SE 5.0. Prior to the introduction of generics, each variable declaration had to be of a specific type. For container classes, for example, this is a problem because there is no easy way to create a container that accepts only specific types of objects. Either the container operates on all subtypes of a class or interface, usually Object, or a different container class has to be created for each contained class. Generics allow compile-time type checking without having to create many container classes, each containing almost identical code. In addition to enabling more efficient code, certain runtime exceptions are prevented from occurring, by issuing compile-time errors. If Java prevented all runtime type errors (ClassCastExceptions) from occurring, it would be type safe.
In 2016, the type system of Java was proven unsound in that it is possible to use generics to construct classes and methods that allow assignment of an instance of one class to a variable of another unrelated class. Such code is accepted by the compiler, but fails at run time with a class cast exception.[71]
Criticism
[edit]Criticisms directed at Java include the implementation of generics,[72] speed,[52] the handling of unsigned numbers,[73] the implementation of floating-point arithmetic,[74] and a history of security vulnerabilities in the primary Java VM implementation HotSpot.[75] Developers have criticized the complexity and verbosity of the Java Persistence API (JPA), a standard part of Java EE. This has led to increased adoption of higher-level abstractions like Spring Data JPA, which aims to simplify database operations and reduce boilerplate code. The growing popularity of such frameworks suggests limitations in the standard JPA implementation's ease-of-use for modern Java development.
Class libraries
[edit]The Java Class Library is the standard library, developed to support application development in Java. It is controlled by Oracle in cooperation with others through the Java Community Process program.[76] Companies or individuals participating in this process can influence the design and development of the APIs. This process has been a subject of controversy during the 2010s.[77] The class library contains features such as:
- The core libraries, which include:
- Input/output (I/O or IO)[78] and non-blocking I/O (NIO), or IO/NIO[79]
- Networking[80] (new user agent (HTTP client) since Java 11[81])
- Reflective programming (reflection)
- Concurrent computing (concurrency)[78]
- Generics
- Scripting, Compiler
- Functional programming (Lambda, streaming)
- Collection libraries that implement data structures such as lists, dictionaries, trees, sets, queues and double-ended queue, or stacks[82]
- XML Processing (Parsing, Transforming, Validating) libraries
- Security[83]
- Internationalization and localization libraries[84]
- The integration libraries, which allow the application writer to communicate with external systems. These libraries include:
- The Java Database Connectivity (JDBC) API for database access
- Java Naming and Directory Interface (JNDI) for lookup and discovery
- Java remote method invocation (RMI) and Common Object Request Broker Architecture (CORBA) for distributed application development
- Java Management Extensions (JMX) for managing and monitoring applications
- User interface libraries, which include:
- The (heavyweight, or native) Abstract Window Toolkit (AWT), which provides GUI components, the means for laying out those components and the means for handling events from those components
- The (lightweight) Swing libraries, which are built on AWT but provide (non-native) implementations of the AWT widgetry
- APIs for audio capture, processing, and playback
- JavaFX
- A platform dependent implementation of the Java virtual machine that is the means by which the bytecodes of the Java libraries and third-party applications are executed
- Plugins, which enable applets to be run in web browsers
- Java Web Start, which allows Java applications to be efficiently distributed to end users across the Internet
- Licensing and documentation
Documentation
[edit]Javadoc is a comprehensive documentation system, created by Sun Microsystems. It provides developers with an organized system for documenting their code. Javadoc comments have an extra asterisk at the beginning, i.e. the delimiters are /** and */, whereas the normal multi-line comments in Java are delimited by /* and */, and single-line comments start with //.[85]
Implementations
[edit]This section needs additional citations for verification. (September 2023) |
Oracle Corporation owns the official implementation of the Java SE platform, due to its acquisition of Sun Microsystems on January 27, 2010. This implementation is based on the original implementation of Java by Sun. The Oracle implementation is available for Windows, macOS, Linux, and Solaris. Because Java lacks any formal standardization recognized by Ecma International, ISO/IEC, ANSI, or other third-party standards organizations, the Oracle implementation is the de facto standard.
The Oracle implementation is packaged into two different distributions: The Java Runtime Environment (JRE) which contains the parts of the Java SE platform required to run Java programs and is intended for end users, and the Java Development Kit (JDK), which is intended for software developers and includes development tools such as the Java compiler, Javadoc, Jar, and a debugger. Oracle has also released GraalVM, a high performance Java dynamic compiler and interpreter.
OpenJDK is another Java SE implementation that is licensed under the GNU GPL. The implementation started when Sun began releasing the Java source code under the GPL. As of Java SE 7, OpenJDK is the official Java reference implementation.
The goal of Java is to make all implementations of Java compatible. Historically, Sun's trademark license for usage of the Java brand insists that all implementations be compatible. This resulted in a legal dispute with Microsoft after Sun claimed that the Microsoft implementation did not support Java remote method invocation (RMI) or Java Native Interface (JNI) and had added platform-specific features of their own. Sun sued in 1997, and, in 2001, won a settlement of US$20 million, as well as a court order enforcing the terms of the license from Sun.[86] As a result, Microsoft no longer ships Java with Windows.
Platform-independent Java is essential to Java EE, and an even more rigorous validation is required to certify an implementation. This environment enables portable server-side applications.
Use outside the Java platform
[edit]The Java programming language requires the presence of a software platform in order for compiled programs to be executed.
Oracle supplies the Java platform for use with Java. The Android SDK is an alternative software platform, used primarily for developing Android applications with its own GUI system.
Android
[edit]The Java language is a key pillar in Android, an open source mobile operating system. Although Android, built on the Linux kernel, is written largely in C, the Android SDK uses the Java language as the basis for Android applications but does not use any of its standard GUI, SE, ME or other established Java standards.[87] The bytecode language supported by the Android SDK is incompatible with Java bytecode and runs on its own virtual machine, optimized for low-memory devices such as smartphones and tablet computers. Depending on the Android version, the bytecode is either interpreted by the Dalvik virtual machine or compiled into native code by the Android Runtime.
Android does not provide the full Java SE standard library, although the Android SDK does include an independent implementation of a large subset of it. It supports Java 6 and some Java 7 features, offering an implementation compatible with the standard library (Apache Harmony).
Controversy
[edit]The use of Java-related technology in Android led to a legal dispute between Oracle and Google. On May 7, 2012, a San Francisco jury found that if APIs could be copyrighted, then Google had infringed Oracle's copyrights by the use of Java in Android devices.[88] District Judge William Alsup ruled on May 31, 2012, that APIs cannot be copyrighted,[89] but this was reversed by the United States Court of Appeals for the Federal Circuit in May 2014.[90] On May 26, 2016, the district court decided in favor of Google, ruling the copyright infringement of the Java API in Android constitutes fair use.[91] In March 2018, this ruling was overturned by the Appeals Court, which sent down the case of determining the damages to federal court in San Francisco.[92] Google filed a petition for writ of certiorari with the Supreme Court of the United States in January 2019 to challenge the two rulings that were made by the Appeals Court in Oracle's favor.[93] On April 5, 2021, the Court ruled 6–2 in Google's favor, that its use of Java APIs should be considered fair use. However, the court refused to rule on the copyrightability of APIs, choosing instead to determine their ruling by considering Java's API copyrightable "purely for argument's sake."[94]
See also
[edit]- C#
- C++
- Dalvik, used in old Android versions, replaced by non-JIT Android Runtime
- Java Heterogeneous Distributed Computing
- List of Java APIs
- List of Java frameworks
- List of JVM languages
- List of Java programming books
- List of Java software and tools
- List of Java virtual machines
- Outline of the Java programming language
- Comparison of C# and Java
- Comparison of Java and C++
- Comparison of programming languages
References
[edit]- ^ Binstock, Andrew (May 20, 2015). "Java's 20 Years of Innovation". Forbes. Archived from the original on March 14, 2016. Retrieved March 18, 2016.
- ^ a b c d Barbara Liskov with John Guttag (2000). Program Development in Java – Abstraction, Specification, and Object-Oriented Design. USA, Addison Wesley. ISBN 978-0-201-65768-5.
- ^ Chaudhary, Harry H. (July 28, 2014). "Cracking The Java Programming Interview :: 2000+ Java Interview Que/Ans". Archived from the original on September 29, 2023. Retrieved May 29, 2016.
- ^ Java 5.0 added several new language features (the enhanced for loop, autoboxing, varargs and annotations), after they were introduced in the similar (and competing) C# language. [1] Archived March 19, 2011, at the Wayback Machine [2] Archived January 7, 2006, at the Wayback Machine
- ^ Gosling, James; McGilton, Henry (May 1996). "The Java Language Environment". Archived from the original on May 6, 2014. Retrieved May 6, 2014.
- ^ Gosling, James; Joy, Bill; Steele, Guy; Bracha, Gilad. "The Java Language Specification, 2nd Edition". Archived from the original on August 5, 2011. Retrieved February 8, 2008.
- ^ "The A-Z of Programming Languages: Modula-3". Computerworld. Archived from the original on January 5, 2009. Retrieved June 9, 2010.
- ^ Niklaus Wirth stated on a number of public occasions, e.g. in a lecture at the Polytechnic Museum, Moscow in September 2005 (several independent first-hand accounts in Russian exist, e.g. one with an audio recording: Filippova, Elena (September 22, 2005). "Niklaus Wirth's lecture at the Polytechnic Museum in Moscow". Archived from the original on December 1, 2020. Retrieved November 20, 2011.), that the Sun Java design team licensed the Oberon compiler sources a number of years prior to the release of Java and examined it: a (relative) compactness, type safety, garbage collection, no multiple inheritance for classes – all these key overall design features are shared by Java and Oberon.
- ^ Patrick Naughton cites Objective-C as a strong influence on the design of the Java programming language, stating that notable direct derivatives include Java interfaces (derived from Objective-C's protocol) and primitive wrapper classes. [3] Archived July 13, 2011, at the Wayback Machine
- ^ TechMetrix Research (1999). "History of Java" (PDF). Java Application Servers Report. Archived from the original (PDF) on December 29, 2010.
The project went ahead under the name green and the language was based on an old model of UCSD Pascal, which makes it possible to generate interpretive code.
- ^ "A Conversation with James Gosling". ACM Queue. Vol. 2, no. 5. Association for Computing Machinery. August 31, 2004. Archived from the original on July 16, 2015. Retrieved June 9, 2010.
- ^ The Java Language Team. About Microsoft's 'Delegates' (White Paper). JavaSoft, Sun Microsystems, Inc. Archived from the original on June 27, 2012.
In the summer of 1996, Sun was designing the precursor to what is now the event model of the AWT and the JavaBeans component architecture. Borland contributed greatly to this process. We looked very carefully at Delphi Object Pascal and built a working prototype of bound method references in order to understand their interaction with the Java programming language and its APIs.
- ^ "Chapel spec (Acknowledgements)" (PDF). Cray Inc. October 1, 2015. Archived (PDF) from the original on February 5, 2016. Retrieved January 14, 2016.
- ^ "Gambas Documentation Introduction". Gambas Website. Archived from the original on October 9, 2017. Retrieved October 9, 2017.
- ^ "Facebook Q&A: Hack brings static typing to PHP world". InfoWorld. March 26, 2014. Archived from the original on February 13, 2015. Retrieved January 11, 2015.
- ^ "Write once, run anywhere?". Computer Weekly. May 2, 2002. Archived from the original on August 13, 2021. Retrieved July 27, 2009.
- ^ a b c "1.2 Design Goals of the Java Programming Language". Oracle. January 1, 1999. Archived from the original on January 23, 2013. Retrieved January 14, 2013.
- ^ Melanson, Mike (August 9, 2022). "Don't call it a comeback: Why Java is still champ". GitHub. Archived from the original on August 25, 2023. Retrieved October 15, 2023.
- ^ "The top programming languages". The State of the Octoverse. GitHub. Archived from the original on August 2, 2023. Retrieved October 15, 2023.
- ^ McMillan, Robert (August 1, 2013). "Is Java Losing Its Mojo?". Wired. Archived from the original on February 15, 2017. Retrieved October 15, 2023.
- ^ Byous, Jon (c. 1998). "Java technology: The early years". Sun Developer Network. Sun Microsystems. Archived from the original on April 20, 2005. Retrieved April 22, 2005.
- ^ Object-oriented programming "The History of Java Technology". Sun Developer Network. c. 1995. Archived from the original on February 10, 2010. Retrieved April 30, 2010.
- ^ Murphy, Kieron (October 4, 1996). "So why did they decide to call it Java?". JavaWorld. Archived from the original on July 13, 2020. Retrieved July 13, 2020.
- ^ Kabutz, Heinz; Once Upon an Oak Archived April 13, 2007, at the Wayback Machine. Artima. Retrieved April 29, 2007.
- ^ "JAVASOFT SHIPS JAVA 1.0". Archived from the original on March 10, 2007. Retrieved May 13, 2018.
- ^ Object-oriented Programming with Java: Essentials and Applications. Tata McGraw-Hill Education. p. 34.
- ^ "JSG – Java Study Group". open-std.org. Archived from the original on August 25, 2006. Retrieved August 2, 2006.
- ^ "Why Java Was – Not – Standardized Twice" (PDF). Archived (PDF) from the original on January 13, 2014. Retrieved June 3, 2018.
- ^ "What is ECMA—and why Microsoft cares". ZDNet. Archived from the original on May 6, 2014. Retrieved May 6, 2014.
- ^ "Java Community Process website". Jcp.org. May 24, 2010. Archived from the original on August 8, 2006. Retrieved June 9, 2010.
- ^ "JAVAONE: Sun – The bulk of Java is open sourced". GrnLight.net. Archived from the original on May 27, 2014. Retrieved May 26, 2014.
- ^ "Sun's Evolving Role as Java Evangelist". O'Reilly Media. Archived from the original on September 15, 2010. Retrieved August 2, 2009.
- ^ "Oracle and Java". oracle.com. Oracle Corporation. Archived from the original on January 31, 2010. Retrieved August 23, 2010.
Oracle has been a leading and substantive supporter of Java since its emergence in 1995 and takes on the new role as steward of Java technology with a relentless commitment to fostering a community of participation and transparency.
- ^ Gosling, James (April 9, 2010). "Time to move on..." On a New Road. Archived from the original on November 5, 2010. Retrieved November 16, 2011.
- ^ Topic, Dalibor. "Moving to a Plugin-Free Web". Archived from the original on March 16, 2016. Retrieved March 15, 2016.
- ^ "Learn About Java Technology". Oracle. Archived from the original on November 24, 2011. Retrieved November 21, 2011.
- ^ "Why should I uninstall older versions of Java from my system?". Oracle. Archived from the original on February 12, 2018. Retrieved September 24, 2021.
- ^ "Oracle Java SE Support Roadmap". Oracle. September 13, 2021. Archived from the original on September 19, 2021. Retrieved September 18, 2021.
- ^ "Temurin™ Support; Adoptium". adoptium.net. Archived from the original on March 29, 2024. Retrieved March 29, 2024.
- ^ "JAVASOFT SHIPS JAVA 1.0". sun.com. Archived from the original on March 10, 2007. Retrieved February 5, 2008.
- ^ Chander, Sharat. "Introducing Java SE 11". oracle.com. Archived from the original on September 26, 2018. Retrieved September 26, 2018.
- ^ Chander, Sharat (September 15, 2020). "The Arrival of Java 15!". Oracle. Archived from the original on September 16, 2020. Retrieved September 15, 2020.
- ^ "JDK 21". openjdk.org. Archived from the original on September 20, 2023. Retrieved September 20, 2023.
- ^ "JDK 24".
- ^ "JDK 25".
- ^ "Java Card Overview". Oracle Technology Network. Oracle. Archived from the original on January 7, 2015. Retrieved December 18, 2014.
- ^ "Java Platform, Micro Edition (Java ME)". Oracle Technology Network. Oracle. Archived from the original on January 4, 2015. Retrieved December 18, 2014.
- ^ "Java SE". Oracle Technology Network. Oracle. Archived from the original on December 24, 2014. Retrieved December 18, 2014.
- ^ "Java Platform, Enterprise Edition (Java EE)". Oracle Technology Network. Oracle. Archived from the original on December 17, 2014. Retrieved December 18, 2014.
- ^ "Deep Dive Into the New Java JIT Compiler – Graal | Baeldung". www.baeldung.com. August 6, 2021. Archived from the original on October 28, 2021. Retrieved October 13, 2021.
- ^ "Is the JVM (Java Virtual Machine) platform dependent or platform independent? What is the advantage of using the JVM, and having Java be a translated language?". Programmer Interview. Archived from the original on January 19, 2015. Retrieved January 19, 2015.
- ^ a b Jelovic, Dejan. "Why Java will always be slower than C++". Archived from the original on February 11, 2008. Retrieved February 15, 2008.
- ^ Hundt, Robert. "Loop Recognition in C++/Java/Go/Scala" (PDF). Archived (PDF) from the original on November 16, 2011. Retrieved July 12, 2012.
- ^ "Symantec's Just-In-Time Java Compiler To Be Integrated into Sun JDK 1.1". Archived from the original on June 28, 2010. Retrieved August 1, 2009.
- ^ Salcic, Zoran; Park, Heejong; Teich, Jürgen; Malik, Avinash; Nadeem, Muhammad (July 22, 2017). "Noc-HMP: A Heterogeneous Multicore Processor for Embedded Systems Designed in SystemJ". ACM Transactions on Design Automation of Electronic Systems. 22 (4): 73. doi:10.1145/3073416. ISSN 1084-4309. S2CID 11150290.
- ^ a b c Bloch 2018, p. 26-28, §Item 7: Eliminate obsolete object references.
- ^ "NullPointerException". Oracle. Archived from the original on May 6, 2014. Retrieved May 6, 2014.
- ^ "Exceptions in Java". Artima.com. Archived from the original on January 21, 2009. Retrieved August 10, 2010.
- ^ Walter, A. (2010). Towards Certification of Java Applications for Safety Critical Projects. Proceedings of Embedded Real-Time Software and Systems, ERTS2, 1-7.
- ^ "Java HotSpot™ Virtual Machine Performance Enhancements". Oracle.com. Archived from the original on May 29, 2017. Retrieved April 26, 2017.
- ^ "Operator Overloading (C# vs Java)". C# for Java Developers. Microsoft. Archived from the original on January 7, 2015. Retrieved December 10, 2014.
- ^ "Multiple Inheritance of State, Implementation, and Type". The Java Tutorials. Oracle. Archived from the original on November 9, 2014. Retrieved December 10, 2014.
- ^ Krill, Paul (September 16, 2025). "JDK 25: The new features in Java 25". InfoWorld. Retrieved October 9, 2025.
- ^ Pressler, Ron; Laskey, Jim; Bierman, Gavin (July 11, 2025). "JEP 512: Compact Source Files and Instance Main Methods". OpenJDK. Retrieved October 9, 2025.
- ^ "Deprecated APIs, Features, and Options". Oracle. Archived from the original on June 19, 2019. Retrieved May 31, 2019.
- ^ "Applet (Java Platform SE 7)". Docs. Oracle. Archived from the original on August 2, 2020. Retrieved May 1, 2020.
- ^ "What Is a JSP Page? - The Java EE 5 Tutorial". docs.oracle.com. Archived from the original on August 2, 2020. Retrieved May 1, 2020.
- ^ "Trail: Creating a GUI With JFC/Swing (The Java Tutorials)". docs.oracle.com. Archived from the original on April 29, 2020. Retrieved May 1, 2020.
- ^ "Removed from JDK 11, JavaFX 11 arrives as a standalone module". InfoWorld. September 20, 2018. Archived from the original on October 14, 2020. Retrieved October 13, 2020.
- ^ "Getting Started with JavaFX: Hello World, JavaFX Style". JavaFX 2 Tutorials and Documentation. Oracle. Archived from the original on August 2, 2020. Retrieved May 1, 2020.
- ^ "Java and Scala's Type Systems are Unsound" (PDF). Archived (PDF) from the original on November 28, 2016. Retrieved February 20, 2017.
- ^ Arnold, Ken (June 27, 2005). "Generics Considered Harmful". java.net. Archived from the original on October 10, 2007. Retrieved September 10, 2015.
- ^ Owens, Sean R. "Java and unsigned int, unsigned short, unsigned byte, unsigned long, etc. (Or rather, the lack thereof)". Archived from the original on February 20, 2009. Retrieved July 4, 2011.
- ^ Kahan, William (March 1, 1998). "How Java's Floating-Point Hurts Everyone Everywhere – ACM 1998 Workshop on Java (Stanford)" (PDF). Electrical Engineering & Computer Science, University of California at Berkeley. Archived (PDF) from the original on September 5, 2012. Retrieved June 4, 2011.
- ^ "Have you checked the Java?". Archived from the original on September 21, 2012. Retrieved December 23, 2011.
- ^ Cadenhead, Rogers (November 20, 2017), Understanding How Java Programs Work, archived from the original on August 13, 2021, retrieved March 26, 2019
- ^ Woolf, Nicky (May 26, 2016). "Google wins six-year legal battle with Oracle over Android code copyright". The Guardian. ISSN 0261-3077. Archived from the original on March 26, 2019. Retrieved March 26, 2019.
- ^ a b Bloch 2018, pp. 1–4, § 1 Introduction.
- ^ "java.nio (Java Platform SE 8)". docs.oracle.com.
- ^ "Java Networking". docs.oracle.com.
- ^ "HttpClient (Java SE 11 & JDK 11)". docs.oracle.com.
- ^ "Collections Framework Overview". Java Documentation. Oracle. Archived from the original on December 31, 2014. Retrieved December 18, 2014.
- ^ "Java Security Overview". Java Documentation. Oracle. Archived from the original on January 3, 2015. Retrieved December 18, 2014.
- ^ "Trail: Internationalization". The Java Tutorials. Oracle. Archived from the original on December 31, 2014. Retrieved December 18, 2014.
- ^ "How to Write Doc Comments for the Javadoc Tool". Oracle Technology Network. Oracle. Archived from the original on December 18, 2014. Retrieved December 18, 2014.
- ^ Niccolai, James (January 24, 2001). "Sun, Microsoft settle Java lawsuit". JavaWorld. IDG News Service. Archived from the original on July 14, 2020. Retrieved July 13, 2020.
- ^ van Gurp, Jilles (November 13, 2007). "Google Android: Initial Impressions and Criticism". Javalobby. Archived from the original on August 28, 2008. Retrieved March 7, 2009.
Frankly, I don't understand why Google intends to ignore the vast amount of existing implementation out there. It seems like a bad case of "not invented here" to me. Ultimately, this will slow adoption. There are already too many Java platforms for the mobile world and this is yet another one
- ^ Mullin, Joe (May 7, 2012). "Google guilty of infringement in Oracle trial; future legal headaches loom". Law & Disorder. Ars Technica. Archived from the original on May 8, 2012. Retrieved May 8, 2012.
- ^ Mullin, Joe (May 31, 2012). "Google wins crucial API ruling, Oracle's case decimated". Ars Technica. Archived from the original on March 12, 2017. Retrieved June 1, 2012.
- ^ Rosenblatt, Seth (May 9, 2014). "Court sides with Oracle over Android in Java patent appeal". CNET. Archived from the original on May 10, 2014. Retrieved May 10, 2014.
- ^ Mullin, Joe (May 26, 2016). "Google beats Oracle—Android makes "fair use" of Java APIs". Ars Technica. Archived from the original on January 20, 2017. Retrieved May 26, 2016.
- ^ Farivar, Cyrus (March 27, 2018). ""Google's use of the Java API packages was not fair," appeals court rules". Ars Technica. Archived from the original on September 24, 2019. Retrieved August 6, 2019.
- ^ Lee, Timothy (April 23, 2019). "Google asks Supreme Court to overrule disastrous ruling on API copyrights". Ars Technica. Archived from the original on April 23, 2019. Retrieved April 23, 2019.
- ^ "Google LLC v. Oracle America, Inc 593 U. S. ____ (2021)" (PDF). Archived (PDF) from the original on April 5, 2021. Retrieved April 6, 2021.
Bibliography
[edit]- Bloch, Joshua (2018). Effective Java: Programming Language Guide (Third ed.). Addison-Wesley. ISBN 978-0-13-468599-1.
- Gosling, James; Joy, Bill; Steele, Guy L. Jr.; Bracha, Gilad (2005). The Java Language Specification (3rd ed.). Addison-Wesley. ISBN 0-321-24678-0. Archived from the original on February 14, 2012. Retrieved February 8, 2019.
- Gosling, James; Joy, Bill; Steele, Guy; Bracha, Gilad; Buckley, Alex (2014). The Java® Language Specification (PDF) (Java SE 8 ed.). Archived (PDF) from the original on October 21, 2014. Retrieved November 18, 2014.
- Lindholm, Tim; Yellin, Frank (1999). The Java Virtual Machine Specification (2nd ed.). Addison-Wesley. ISBN 0-201-43294-3. Archived from the original on September 25, 2011. Retrieved February 8, 2019.
External links
[edit]Java (programming language)
View on Grokipediajava.util and java.awt.[10]
Java's platform independence and versatility have made it one of the most widely adopted programming languages, powering applications in enterprise software, Android mobile development, big data processing with frameworks like Hadoop, and cloud-native services. As of 2025, it ranks among the top four programming languages in the TIOBE Index,[11] used by approximately 10 million developers worldwide[12] and integral to over 90% of Fortune 500 companies for mission-critical systems.[13] Its enduring popularity stems from backward compatibility, a vast ecosystem of libraries and frameworks (e.g., Spring for web development), and strong community support through Java User Groups and the Java Community Process.[14] In embedded systems and IoT, Java Micro Edition (now part of Java ME) continues to enable billions of devices, from smart cards to consumer electronics.[15]
History
Origins and Early Development
The development of the Java programming language began in June 1991 at Sun Microsystems as part of the Green Project, a secretive initiative led by James Gosling, Mike Sheridan, and Patrick Naughton to create a programming language and runtime environment for consumer electronic devices, including interactive television set-top boxes.[16] The team, initially focused on addressing the challenges of programming resource-constrained embedded systems with varying architectures, built a prototype control system using C and C++ but encountered issues like buffer overflows that motivated a safer alternative.[17] Gosling, drawing from his earlier work on portable code systems like UCSD Pascal p-codes, designed the language—initially named Oak after a tree outside his office—with a syntax familiar to C and C++ developers to ease adoption, while introducing simplifications such as the elimination of explicit pointers and operator overloading to enhance safety and simplicity.[18][19] By late 1992, the Green Team had relocated to a dedicated facility and demonstrated a proof-of-concept device called the "*7" (star seven), a touchscreen remote control for home entertainment systems, but the project struggled to secure partnerships with consumer electronics firms amid shifting market priorities.[20] In December 1994, Sun released an early internal version of the software, marking the first deployment of Oak within the company.[21] As the World Wide Web gained prominence in the mid-1990s, the team pivoted the technology toward general-purpose applications, recognizing its potential for platform-independent distribution over networks.[20] In January 1995, amid preparations for public unveiling, the name Oak was abandoned due to a trademark conflict with Oak Technologies, leading to a brainstorming session that selected "Java"—inspired by the Indonesian island's coffee, reflecting the team's caffeine-fueled late nights.[22] On May 23, 1995, Sun Microsystems announced Java at the SunWorld Expo in San Francisco, releasing a public beta of Java 1.0 alongside the HotJava browser to demonstrate its applet capabilities for web content.[23] This debut positioned Java as a language for "write once, run anywhere" portability, shifting its focus from niche embedded uses to broader software development.[21]Release History and Evolution
Java's release history began with the public debut of JDK 1.0 on January 23, 1996, which introduced core language features, the Abstract Window Toolkit (AWT) for graphical user interfaces, applets for web-based applications, and foundational APIs for networking and I/O operations.[24] This initial release established Java's platform independence through the Java Virtual Machine (JVM), enabling the "write once, run anywhere" paradigm. In December 1998, Java 1.2, rebranded as J2SE 1.2, marked a significant expansion with the introduction of the Swing GUI toolkit for richer user interfaces, the Collections Framework for handling data structures like lists and maps, and just-in-time (JIT) compilation for performance improvements. Following the release of Java 1.2, Sun launched the J2EE 1.2 specification in December 1999 for enterprise applications and J2ME 1.0 in 2000 for mobile and embedded devices, broadening Java's ecosystem.[24][25] The release of Java 5.0 (J2SE 5.0) on September 30, 2004, brought transformative language enhancements, including generics for type-safe collections, annotations for metadata, enums for enumerated types, and autoboxing/unboxing for seamless primitive-wrapper conversions.[26] These features improved code safety, readability, and maintainability, influencing modern programming practices. Java 8, released on March 18, 2014, introduced functional programming elements such as lambda expressions, the Stream API for processing data collections declaratively, and default methods in interfaces to enable backward-compatible evolution.[27] As a long-term support (LTS) version, it remains widely used for its balance of stability and expressiveness.[28] Following Oracle's acquisition of Sun Microsystems, completed on January 27, 2010, for $7.4 billion, stewardship of Java shifted to Oracle, which assumed responsibility for its development and licensing.[29] In 2006, prior to the acquisition, Sun had open-sourced the core Java implementation as OpenJDK under the GNU General Public License with Classpath Exception, establishing it as the reference implementation for subsequent releases. In September 2017, Oracle transitioned Java to a six-month, time-driven release cadence starting with Java 9, replacing the prior irregular schedule to deliver features more predictably while maintaining LTS versions every few years.[24] This model culminated in Java 11, an LTS release on September 25, 2018, which standardized the module system from Project Jigsaw for better encapsulation and scalability, and included a standardized HTTP Client supporting HTTP/2.[30] Java 17, released as an LTS on September 14, 2021, advanced language expressiveness with sealed classes for restricting inheritance hierarchies and pattern matching for switch statements (preview), alongside enhancements like foreign function and memory APIs (incubator).[31] These changes supported more robust modeling and efficient interoperability with native code.[32] The LTS pattern continued with Java 21 on September 19, 2023, featuring virtual threads from Project Loom for lightweight concurrency, record patterns for deconstructing data classes, and sequenced collections for ordered traversals.[33] Virtual threads, in particular, addressed scalability challenges in high-throughput applications by reducing thread overhead.[34] Java 25, the latest LTS release as of September 16, 2025, incorporates 18 JDK Enhancement Proposals (JEPs), including enhancements to implicit class declarations for streamlined prototyping, further previews of pattern matching expansions, and improvements in AI-related libraries for vector computations.[35] Under Oracle's ongoing OpenJDK-based stewardship, this version emphasizes developer productivity and performance in emerging domains like machine learning.[6]Design Philosophy
Core Principles
Java's design is fundamentally guided by the principle of "Write Once, Run Anywhere" (WORA), achieved through platform-independent bytecode compiled from source code and executed on the Java Virtual Machine (JVM), which abstracts hardware and operating system differences to ensure consistent behavior across diverse environments.[36] This architecture-neutral approach uses a compact, verifiable instruction set that the JVM interprets or just-in-time compiles, enabling applications to run identically on any JVM-compliant platform without recompilation.[36] Simplicity forms another cornerstone, eliminating complexities like manual memory management through automatic garbage collection, which reclaims unused objects as a low-priority background process to prevent memory leaks and reduce programmer errors.[36] Java eschews pointers and direct memory access to avoid common pitfalls such as dangling references or buffer overflows, while forgoing multiple inheritance of classes—opting instead for single inheritance with multiple interface implementation—to sidestep ambiguities like the diamond problem and promote clearer code hierarchies.[36] These choices make the language familiar to C and C++ programmers yet more straightforward, with syntax that avoids operator overloading and excessive low-level constructs.[36] Robustness is prioritized through strong static typing, which enforces type safety at compile time to catch errors early, complemented by runtime checks like array bounds verification to prevent out-of-bounds access exceptions.[36] Comprehensive exception handling mandates that methods declare or catch potential errors, ensuring reliable error propagation without crashing the entire program, while the absence of unchecked pointer arithmetic further safeguards against unintended data corruption.[36] Security is embedded in Java's architecture, particularly for networked and applet-based applications, via a sandbox model that restricts untrusted code to limited resources and prevents direct system access through bytecode verification before execution.[36] By design, Java prohibits unsafe operations like explicit memory manipulation, reducing vulnerabilities to malicious code injection or unauthorized file/system interactions, and supports fine-grained security policies configurable via the SecurityManager class.[36] From its inception, multithreading is a core feature, integrated via the Thread class and synchronization primitives like monitors and the synchronized keyword, allowing seamless concurrent execution for responsive, high-performance applications in distributed systems.[36] Java embraces an object-oriented paradigm, where non-primitive data is treated as objects encapsulated within classes, promoting modularity, inheritance, and polymorphism; primitive types handle basic values efficiently, with autoboxing enabling seamless integration, while relying on garbage collection to automate resource management and enhance developer productivity.[36]Language Goals and Influences
Java was initially developed as part of Project Green at Sun Microsystems, targeting the creation of software for consumer electronic devices such as set-top boxes and interactive TVs, which required a language capable of handling small, reliable, portable, distributed, and real-time systems.[37] As the consumer electronics market evolved slowly, the language—originally named Oak—was repurposed for the burgeoning World Wide Web, enabling dynamic content through applets and supporting secure, distributed computing environments where code could execute remotely without compromising host systems.[36] These goals emphasized robustness against network threats, automatic memory management to prevent errors like memory leaks, and multithreading for concurrent operations in interactive applications.[8] The syntax and performance characteristics of Java draw heavily from C and C++, providing a familiar structure for developers while aiming for efficient execution through compiled bytecode interpreted by the Java Virtual Machine.[38] For object-oriented purity, it was influenced by Smalltalk, incorporating concepts like pure inheritance and polymorphism without the complexities of multiple inheritance.[39] Strong typing and package-based modularity were inspired by Ada and Mesa (via Cedar/Mesa), respectively, promoting type safety and organized code reuse to enhance reliability in large-scale systems.[38] To avoid the pitfalls of C++, such as error-prone pointer manipulation, separate compilation via header files, and unstructured control flow with goto statements, Java eliminated these features entirely, opting instead for references, unified source-compilation models, and exception handling for flow control.[38] This design choice addressed the memory safety issues and complexity that plagued C++ development. A core emphasis was placed on platform independence, achieved through bytecode portability on the JVM, to mitigate the hardware and OS fragmentation prevalent in the 1990s consumer device landscape, where no single architecture dominated.[40] Java's evolution has been guided by the community-driven Java Community Process (JCP), an open standard under which Java Specification Requests (JSRs) propose and ratify enhancements, ensuring collaborative input from industry experts and users to adapt the language for emerging needs like scalability and security.[41]Editions and Variants
Java SE
Java Platform, Standard Edition (Java SE) is the core edition of the Java platform designed for developing and deploying portable applications on desktops and servers. It provides the foundational APIs and runtime environment necessary for general-purpose computing, enabling developers to build standalone applications, server-side software, and desktop programs that run consistently across diverse hardware and operating systems. As the base platform, Java SE serves as the foundation upon which other Java editions, such as those for enterprise and embedded systems, are constructed, ensuring compatibility and extensibility for broader use cases.[42][43] The platform includes essential core APIs organized into packages that support fundamental programming tasks. Thejava.lang package offers basic language support, including classes for objects, strings, threads, and exceptions, forming the bedrock of Java's object-oriented model without requiring explicit imports. The java.util package provides utilities for data structures, such as collections (e.g., lists, sets, and maps via the Collections Framework), date/time handling, and internationalization features to manage locale-specific formatting. Additionally, the java.io package facilitates input/output operations through streams, readers, writers, and file handling, allowing applications to interact with files, networks, and other data sources in a platform-independent manner. These APIs are implemented in the java.base module, which is mandatory for all Java SE implementations and ensures the platform's portability via the Java Virtual Machine (JVM).[44][45][46]
Java SE is distributed through two primary components: the Java Development Kit (JDK) and the Java Runtime Environment (JRE). The JDK encompasses the complete development environment, including the JRE, the javac compiler for translating Java source code into bytecode, debugging tools like jdb, and utilities such as jar for packaging and javadoc for generating API documentation. In contrast, the JRE provides only the runtime components needed to execute Java applications, comprising the JVM for bytecode interpretation and just-in-time compilation, along with the core class libraries but excluding development tools. This separation allows developers to use the full JDK for building applications while deploying minimal JRE installations for end-users on desktops, servers, or standalone systems.[47][48]
Originally known as Java 2 Platform, Standard Edition (J2SE), the platform was renamed to Java SE starting with version 6 in December 2006 to simplify branding and align with the evolving Java ecosystem. Java SE has since adopted a six-month release cadence since Java 9 in 2017, with long-term support (LTS) versions like Java 21 and the latest Java 25 providing extended updates for production environments. Released on September 16, 2025, Java SE 25 introduces several enhancements, including preview features such as flexible constructor bodies (JEP 513), which permit statements before explicit constructor invocations like super() to enable safer input validation and initialization without relying on static blocks or helper methods. Other updates in Java 25 focus on performance improvements in the JVM and API refinements, maintaining backward compatibility while advancing language expressiveness.[49][13][35][50]
For production use, Oracle distributes Java SE under the Oracle No-Fee Terms and Conditions (NFTC) for versions 17 and later, which allow free development, redistribution, and deployment without subscription fees, while earlier versions like Java SE 8 adhere to the legacy Oracle Binary Code License (BCL). This licensing model supports broad adoption for desktop, server, and standalone applications, with Oracle providing critical patch updates for LTS releases over several years to address security and stability.[51][52]
Java EE and Jakarta EE
Java EE, originally introduced as J2EE in 1999, is a set of specifications extending Java SE to support the development of distributed, multi-tier enterprise applications that are portable, scalable, and secure.[53] It defines APIs for building web and business logic components, enabling developers to create robust server-side applications without vendor lock-in. Key specifications in Java EE include Jakarta Servlets for handling HTTP requests and responses in web applications, Jakarta Server Pages (JSP) for generating dynamic web content through embedded Java code in HTML, Jakarta Enterprise JavaBeans (EJB) for implementing distributed business logic with transaction management and security, Jakarta Messaging (JMS) for asynchronous communication between applications using message-oriented middleware, and Jakarta Persistence (JPA) for mapping Java objects to relational databases via object-relational mapping. These components facilitate the construction of scalable web applications, where servlets and JSP handle the presentation tier, EJBs manage core business processes, JMS enables reliable messaging, and JPA ensures efficient data persistence. Implementations of Java EE specifications are provided by web containers and full application servers. Web containers, such as Apache Tomcat, support the web tier by executing servlets and JSPs. Full application servers, including Eclipse GlassFish (the reference implementation), Oracle WebLogic, and Red Hat WildFly, offer comprehensive runtime environments for all Java EE APIs, including transaction processing, security, and resource management. The evolution of the platform culminated in Java EE 8, released by Oracle in September 2017, which introduced enhancements like support for HTTP/2 and JSON binding while maintaining backward compatibility. In November 2017, Oracle transferred stewardship of the specifications to the Eclipse Foundation to foster open innovation, resulting in the rebranding to Jakarta EE in March 2018 due to Oracle's inability to grant trademark rights for "Java" under the new governance.[54] Jakarta EE 8, released in September 2019, served as a direct migration of Java EE 8 with minimal changes to ensure compatibility.[55] Jakarta EE 9, released in December 2020, marked a significant shift by renaming packages fromjavax.* to jakarta.* to resolve trademark issues, requiring source code updates but preserving functional equivalence.[55] Building on this, Jakarta EE 10, released in September 2022, incorporated modern features such as JSON Processing API (JSON-P) 2.1 for handling JSON data streams and Jakarta RESTful Web Services 3.0 for building RESTful APIs with improved server-sent events support.[55] Jakarta EE 11, released on June 26, 2025, further advances cloud-native capabilities with a new Core Profile for lightweight microservices, updates to 16 specifications for improved performance and developer productivity, and expanded support for modern Java platforms.[55]
Recent developments in Jakarta EE emphasize microservices and cloud-native architectures, with integrations like Eclipse MicroProfile providing lightweight APIs for configuration, health checks, metrics, and fault tolerance to complement the full platform in containerized environments. This focus enables enterprise applications to deploy efficiently on Kubernetes and other cloud platforms while leveraging established Java EE strengths.[53]
Java ME and Embedded Systems
Java Platform, Micro Edition (Java ME), formerly known as Java 2 Platform, Micro Edition (J2ME), is a lightweight computing platform designed for developing and deploying portable Java applications on resource-constrained embedded and mobile devices.[15][56] Announced by Sun Microsystems at the JavaOne Conference in June 1999, it targets devices with limited memory, processing power, and battery life, such as early mobile phones and small embedded systems, by providing a subset of the full Java APIs optimized for these environments.[56] Java ME is structured around two primary configurations: the Connected Limited Device Configuration (CLDC) for tiny, highly constrained devices and the Connected Device Configuration (CDC) for more capable embedded systems.[57] CLDC, intended for devices with as little as 128 KB of memory, employs the K Virtual Machine (KVM), a compact virtual machine derived from the Java Virtual Machine (JVM) specification, which supports a minimal set of Java language features and core APIs while omitting floating-point support and other resource-intensive elements.[58][59] In contrast, CDC builds on CLDC's foundations but includes a fuller JVM implementation and broader APIs, such as those from Java SE 1.1, to accommodate devices with more resources like set-top boxes or industrial controllers.[57] Profiles define higher-level APIs tailored to specific device categories and extend the configurations with domain-specific functionality. The Mobile Information Device Profile (MIDP), built on CLDC, became prominent for mobile applications, enabling features like user interfaces, networking, and persistence on early devices such as Nokia phones in the early 2000s. For IoT and headless embedded applications, the Information Module Profile (IMP) provides a lightweight alternative to MIDP, focusing on networked, non-graphical operations; its next-generation variant (IMP-NG) under JSR 361 further optimizes for modern connected devices.[60] Over time, Java ME's prominence in consumer mobile waned with the rise of smartphones and platforms like Android and iOS in the late 2000s, which offered richer native development environments.[60] However, Oracle, following its 2010 acquisition of Sun Microsystems, revitalized the platform for embedded and IoT uses through Java ME Embedded, introduced in 2011 and evolving to version 8.0 in 2014, which integrates CLDC 8 and the Micro Edition Embedded Profile 8 (MEEP 8) for low-power, always-on devices in machine-to-machine (M2M) scenarios.[61] This shift emphasized secure, portable applications for sectors like industrial control and smart grids, with subset APIs for networking (e.g., HTTP, UDP), data persistence (e.g., RMS for record management), and security.[60] Meanwhile, the related Java SE Embedded edition, which provided a more complete Java SE runtime for embedded systems, was discontinued by Oracle in 2017, with support ending thereafter.[62] In contemporary applications as of 2025, Java ME persists in legacy mobile systems and niche embedded deployments, particularly in IoT gateways and sensors where its small footprint and proven reliability are advantageous.[61] A specialized extension, Java Card, enables secure Java applet execution on smart cards and tamper-resistant chips, supporting multi-application hosting for uses like payment systems and access control, with versions up to Java Card 3.1 maintaining compatibility with the broader Java ME ecosystem.[63]Syntax and Fundamentals
Basic Structure and Hello World Example
Java programs follow a structured layout that begins with optional package and import statements, followed by class or interface declarations. The core of a basic application is a public class containing a main method, which serves as the entry point for execution. This method has the fixed signaturepublic static void main(String[] args), where public ensures accessibility, static allows invocation without instantiating the class, void indicates no return value, and String[] args accepts command-line arguments as an array of strings.[64]
A simple "Hello World" program exemplifies this structure. The following code defines a class named HelloWorldApp with the required main method that outputs a greeting using System.out.println:[65]
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
public class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
public class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
System is part of the core java.lang package, which is automatically available.[64]
Java supports three types of comments for documentation and code annotation, which the compiler ignores during processing. Single-line comments begin with // and extend to the end of the line, such as // Display the string.; multi-line comments are enclosed in /* and */, allowing text spanning multiple lines; and Javadoc comments start with /** and end with */, used to generate API documentation via the javadoc tool.[64][66]
For organizing code into namespaces, a package declaration can be added at the top of the source file, using the syntax package packageName;, where packageName follows lowercase naming conventions to avoid conflicts—typically a reversed domain name like com.example.myapp. This declaration groups related classes and must precede any import or class statements. If no package is declared, the class belongs to the default unnamed package.[67][68]
File naming conventions require that the source file name matches the public class name exactly, including case sensitivity, and ends with .java—for instance, the above example must be saved as HelloWorldApp.java. Multiple public classes in one file are not permitted; each public class needs its own file.[65][67]
To compile and run a Java program, use the Java compiler (javac) on the source file, which generates a bytecode .class file: javac HelloWorldApp.java produces HelloWorldApp.class. Then, execute it with the Java runtime (java), specifying the class name without the extension: java HelloWorldApp, which outputs "Hello World!" to standard output. These commands assume the JDK is installed and the current directory is in the classpath.[65]
Data Types and Control Structures
Java's data types are categorized into primitive types and reference types, providing the foundation for storing and manipulating values in programs. Primitive types are predefined by the language and store simple values directly, while reference types store references to objects in memory.[69]Primitive Types
Primitive types in Java include eight basic categories: byte, short, int, long for integers; float and double for floating-point numbers; char for characters; and boolean for logical values. The byte type is an 8-bit signed integer with a range from -128 to 127, suitable for small values to save memory.[69] The short type uses 16 bits, ranging from -32,768 to 32,767.[69] The int type, the most commonly used integer type, is a 32-bit signed value from -2^31 (-2,147,483,648) to 2^31 - 1 (2,147,483,647).[69] Long integers employ 64 bits, spanning -2^63 to 2^63 - 1, for larger numerical needs.[69] Floating-point types follow the IEEE 754 standard: float is a 32-bit single-precision value with approximately 6-7 decimal digits of precision, while double is 64-bit double-precision with about 15 decimal digits, ideal for scientific computations.[69] The char type represents a 16-bit unsigned Unicode character, with values from 0 to 65,535, allowing storage of international text elements.[69] Boolean holds only true or false, used for conditional logic without numerical range.[69] These types are stored efficiently on the stack and do not require object overhead.Reference Types
Reference types point to objects rather than holding values directly, enabling complex data structures. Common examples include the String class for immutable sequences of characters and arrays for ordered collections. A String variable, such asString message = "Hello";, references an instance of the java.lang.String class, which supports methods like concatenation via the + operator. Arrays are fixed-size, dynamically allocated structures declared as, for example, int[] arr = new int[5];, where the type is the element type followed by []. Arrays can hold primitives or other reference types and are themselves objects, with a public final length field for size access. Reference types are allocated on the heap and can be null if no object is assigned.
Operators
Java provides operators for performing operations on data types, categorized by function. Arithmetic operators include addition (+), subtraction (-), multiplication (*), division (/), and modulus (%), which compute numerical results; for instance,int result = 10 % 3; yields 1.[70] These apply to numeric primitives, with integer division truncating toward zero and floating-point division producing decimals.[71]
Relational operators compare values, returning boolean results: equality (==), inequality (!=), greater than (>), less than (<), greater than or equal (>=), and less than or equal (<=). For example, if (a > b) evaluates the condition based on operand types, with object comparisons using reference equality unless overridden.
Logical operators handle boolean expressions: AND (&&) for both true, OR (||) for at least one true, and NOT (!) for inversion. Short-circuit evaluation applies, where && skips the second operand if the first is false, and || skips if the first is true, improving efficiency. These operators support conditional logic without side effects in unevaluated parts.
Control Structures
Control structures direct program flow based on conditions or repetition. The if-else statement executes code conditionally:if (condition) { ... } else { ... }, where the condition is a boolean expression, allowing single or chained decisions.[72]
The switch statement selects among multiple cases based on a selector expression, traditionally using integers, enums, or strings. Enhanced in Java 14, it supports switch expressions with arrow syntax (case L -> ...) for concise, exhaustive handling without fall-through, and yields values like String day = switch (num) { case 1 -> "Monday"; default -> "Invalid"; };.[73][74]
Looping structures include for, while, and do-while. The basic for loop iterates a fixed number of times: for (int i = 0; i < 5; i++) { ... }, with initialization, condition, and update. The enhanced for-each loop, introduced in Java 5, simplifies iteration over arrays or collections: for (int num : numbers) { ... }, where each element is assigned to the variable without indexing, improving readability for traversal tasks.[75] The while loop checks a condition before each iteration: while (condition) { ... }. Do-while executes the body first, then checks: do { ... } while (condition);, ensuring at least one run. Break and continue statements alter loop flow, exiting or skipping iterations.[72]
Variable Declaration
Variables must be declared with a type before use, specifying storage for values. Syntax istype name = initializer;, such as int count = 0;. Since Java 10, local variables can use type inference with the reserved keyword var, where the type is automatically determined from the initializer, as in var count = 0; (inferred as int). Local variables require explicit initialization before reading to prevent compile-time errors.[76][77] Scope defines accessibility: local variables, declared in methods, exist only within that block and are not visible outside.[78]
Instance variables, declared in classes without static, belong to objects and are initialized to defaults (e.g., 0 for int, null for references) if not set.[76] Static variables, marked with static, are class-level, shared across instances, and also default-initialized.[76] All variables follow camelCase naming conventions, and primitives hold values while references point to heap objects.[76]
Object-Oriented Features
Classes and Objects
In Java, a class serves as a blueprint for creating objects, encapsulating data and behavior through fields and methods. A class is declared using theclass keyword, optionally with access modifiers such as public, followed by the class name and a body enclosed in curly braces. For example, a basic class definition might look like public class Bicycle { }, where fields and methods are defined inside the body to represent the class's state and operations.[79]
Fields in a class store the state of objects and can be instance variables or constants. Instance variables, also known as non-static fields, are unique to each object instance and hold values specific to that object, such as private int cadence; in a Bicycle class to track pedaling speed. Constants are declared using the static final modifiers, making them class-level values that remain unchanged and are shared across all instances, for example, public static final int WHEEL_SIZE = 26; to define a fixed attribute. Access to fields is controlled by modifiers like public, private, protected, or default (package-private), where public allows access from any class, private restricts it to the same class, protected permits access within the package and subclasses, and default limits it to the same package.[80][81]
Methods define the behavior of a class and can be instance or static. Instance methods operate on a specific object and can access both instance and static fields, invoked via an object reference like myBike.setCadence(50);, where setCadence updates the object's state. Static methods belong to the class itself, not instances, and are called using the class name, such as Bicycle.getNumberOfBicycles();, which might return a shared counter without requiring an object. Like fields, methods use access modifiers to control visibility: public for broad access, private for internal use only, protected for package and subclass access, and default for package-limited access.[80][81][82]
Constructors are special methods invoked automatically when creating an object to initialize its state, named after the class with no return type. If no constructors are defined, Java provides a default no-argument constructor that sets fields to default values (e.g., 0 for integers). Parameterized constructors accept arguments for custom initialization, such as public Bicycle(int startCadence, int startSpeed, int startGear) { cadence = startCadence; speed = startSpeed; gear = startGear; }, allowing Bicycle myBike = new Bicycle(30, 0, 8);. Constructor chaining uses this() to invoke another constructor in the same class, which must be the first statement, promoting code reuse; for instance, a no-argument constructor might call this(0, 0, 1, 1) to set defaults via a parameterized one. Constructors also respect access modifiers, typically being public for external instantiation.[83][84]
Objects are instances of classes created at runtime using the new operator, which allocates memory and calls the constructor, returning a reference to the object. For example, Point origin = new Point(23, 94); creates a Point object with coordinates. Members are accessed using dot notation, such as origin.x to read a field or rect.width() to invoke a method, enabling interaction with the object's state and behavior. Multiple objects from the same class share the class structure but maintain separate instance fields.[85]
Inheritance and Polymorphism
Java supports single inheritance for classes, where a subclass is derived from a single superclass using theextends keyword, thereby inheriting its non-private fields and methods to promote code reuse and hierarchical organization.[86] This mechanism allows subclasses to extend or modify the behavior of their superclasses while avoiding the complexities of multiple inheritance of implementation. To explicitly invoke a superclass constructor from a subclass, the super() call must be used as the first statement in the subclass constructor, ensuring proper initialization of inherited state.[87]
Abstract classes provide a way to define partial implementations in Java, declared with the abstract keyword and potentially containing abstract methods that lack a body, requiring subclasses to provide concrete implementations.[88] These classes cannot be instantiated directly but serve as blueprints for related subclasses, combining shared concrete methods with placeholders for specialized behavior. For example, an abstract class Shape might define a concrete method getArea() for common calculations while declaring an abstract draw() method that subclasses like Circle and Rectangle must implement.
Method overriding in Java enables a subclass to provide a specific implementation of a method already defined in its superclass, with the Java Virtual Machine using dynamic method dispatch to invoke the overridden version at runtime based on the actual object type rather than the reference type.[89] The @Override annotation is recommended to indicate intent and catch errors if the method signature does not match the superclass version, enhancing code reliability during compilation. Consider this example:
abstract class Animal {
public void makeSound() {
System.out.println("Animal makes a sound");
}
}
class Dog extends Animal {
@Override
public void makeSound() {
System.out.println("Dog barks");
}
}
abstract class Animal {
public void makeSound() {
System.out.println("Animal makes a sound");
}
}
class Dog extends Animal {
@Override
public void makeSound() {
System.out.println("Dog barks");
}
}
Animal reference points to a Dog object, calling makeSound() executes the Dog version due to late binding.[90]
Interfaces in Java define contracts for behavior, declared with the interface keyword and consisting of abstract methods, constants, and since Java 8, default and static methods with implementations, allowing classes to implement multiple interfaces via the implements keyword for a form of multiple inheritance without implementation conflicts.[91] Default methods provide backward-compatible enhancements to existing interfaces by supplying optional implementations that implementing classes can override if needed.[92] For instance:
interface Drawable {
void draw(); // Abstract method
default void resize() {
System.out.println("Resizing default implementation");
}
}
class Circle implements Drawable {
@Override
public void draw() {
System.out.println("Drawing a circle");
}
}
interface Drawable {
void draw(); // Abstract method
default void resize() {
System.out.println("Resizing default implementation");
}
}
class Circle implements Drawable {
@Override
public void draw() {
System.out.println("Drawing a circle");
}
}
Circle to inherit the resize() behavior while providing its own draw() logic.
Polymorphism in Java manifests through inheritance and interfaces, allowing objects of different classes to be treated uniformly via a common supertype, with runtime decisions determining the appropriate method invocation.[93] Upcasting permits assigning a subclass instance to a superclass reference, enabling flexible code that operates on the base type while leveraging subclass specifics at execution.[86] The instanceof operator tests an object's type compatibility at runtime, returning a boolean to safely perform downcasts or conditional logic, as in if (obj instanceof Dog) { ((Dog) obj).bark(); }.[94] Pattern matching for the instanceof operator, standardized in Java 16, combines type checking with variable binding for cleaner syntax, such as if (obj instanceof Dog d) { d.bark(); }, eliminating the need for explicit casting while maintaining equivalent functionality.[95] Late binding, or dynamic dispatch, ensures that overridden methods are resolved based on the object's actual class during execution, supporting polymorphic behavior essential for extensible designs.[90]
Advanced Language Features
Generics and Collections
Java generics, introduced in Java SE 5.0, enable the creation of type-safe, reusable classes, interfaces, and methods by parameterizing them with types, thereby catching type-related errors at compile time rather than runtime. This feature draws inspiration from languages like C++ templates but adapts to Java's virtual machine constraints through a process known as type erasure.[96] The syntax uses angle brackets to specify type parameters, typically denoted by a single uppercase letter such asT for type, E for element, K for key, or V for value.[97] For example, a generic list can be declared as List<String> list = new ArrayList<>();, where String is the type parameter ensuring that only strings can be added, and the diamond operator <> (introduced in Java SE 7) allows type inference for the right-hand side.[97]
Type erasure occurs during compilation, where the Java compiler replaces all type parameters in generic code with their bounds or Object if unbounded, effectively removing generic information from the bytecode to maintain backward compatibility with pre-generics Java code.[96] This means that at runtime, a List<String> and a List<Integer> are indistinguishable, both treated as raw List types, and the JVM inserts casts as needed to preserve type safety.[96] While this approach avoids the overhead of creating distinct classes for every parameterization, it imposes limitations, such as the inability to instantiate type parameters directly (e.g., new T()) or perform certain runtime type checks like instanceof T.[96] Bounded type parameters, such as <T extends Number>, further refine this by restricting types to subclasses of a specified class or interface, enhancing compile-time checks.[97]
The Collections Framework, part of the java.util package since Java SE 1.2, provides a unified architecture for representing and manipulating collections of objects, promoting code reuse and efficiency through a hierarchy of interfaces and implementations. At its core is the Collection interface, which defines basic operations like adding, removing, and checking size for unordered collections, serving as the supertype for subinterfaces List and Set.[98] The List interface supports ordered collections allowing duplicates and positional access, implemented by classes like ArrayList (resizable array for fast random access) and LinkedList (doubly-linked list for efficient insertions and deletions).[99] In contrast, Set ensures uniqueness with no duplicates, with HashSet using hash tables for average O(1) operations and TreeSet providing sorted order via a red-black tree for O(log n) performance. Separately, the Map interface handles key-value associations without extending Collection, featuring implementations like HashMap (hash-based for fast lookups) and TreeMap (sorted by keys).[100]
Iteration over collections is facilitated by the Iterator interface, which provides a standard way to traverse elements sequentially using methods like hasNext() and next(), while the Iterable interface allows collections to be used in enhanced for-each loops. The enhanced for-each loop, introduced in Java SE 5.0 alongside generics, simplifies traversal as in for (String s : list) { ... }, internally leveraging an iterator without exposing its complexity. This design ensures fail-fast behavior, where concurrent modifications during iteration throw a ConcurrentModificationException to detect inconsistencies early.
The Collections utility class offers static methods for common operations on collections, such as Collections.sort(list) for sorting lists based on natural ordering or a comparator, and Collections.unmodifiableCollection(coll) to create read-only views that throw exceptions on modification attempts. These methods promote immutability and algorithmic reuse without altering the underlying data structures.
Prior to the Collections Framework, legacy classes like Vector and Hashtable provided synchronized collections for thread-safe access, but they are now considered outdated due to performance overhead from unnecessary synchronization in single-threaded contexts. Modern development favors non-synchronized implementations like ArrayList and HashMap for better efficiency, with synchronization added explicitly only when needed.
Lambda Expressions and Streams
Lambda expressions were introduced in Java 8 as a concise way to represent instances of single-method interfaces, known as functional interfaces, allowing functional programming constructs within the language.[101] They consist of a parameter list, the arrow token (->), and a body, which can be an expression or a block of statements, enabling the treatment of functionality as a method argument or data.[102] For example, a lambda expression like(String s) -> s.length() implements the Function<String, Integer> interface by returning the length of a string.[102] Functional interfaces, such as Runnable (with its run() method) or Predicate<T> (with test(T t)), are annotated with @FunctionalInterface to ensure they have exactly one abstract method, making them compatible with lambda expressions.[103]
Method references provide a shorthand for lambda expressions that invoke existing methods, improving readability when no additional logic is needed beyond the method call.[104] They use the syntax ClassName::methodName for static methods, object::instanceMethod for instance methods on a specific object, or ClassName::instanceMethod for instance methods on an instance to be supplied.[104] For instance, String::length is equivalent to the lambda (s) -> s.length(), referencing the length() method of the String class.[104]
The Stream API, part of the java.util.stream package introduced alongside lambdas in Java 8, enables functional-style operations on sequences of elements, supporting both sequential and parallel processing.[105] Streams are created from sources like collections using methods such as Collection.stream() or Stream.of(elements), producing a pipeline of intermediate operations (e.g., filter(Predicate), map(Function)) that transform data lazily, followed by a terminal operation like reduce() or collect() to produce a result.[106] For example, a list of integers can be filtered for even numbers and summed with list.stream().filter(n -> n % 2 == 0).mapToInt(Integer::intValue).sum().[105] Parallel streams, invoked via parallel(), leverage the Fork/Join framework for automatic concurrency on multicore systems, dividing tasks recursively while maintaining order where specified.[105]
The Collectors class provides reduction operations to accumulate stream elements into collections or other data structures, facilitating aggregation tasks.[107] Common collectors include toList() for gathering elements into a List, groupingBy(Function) for partitioning data by a key, and joining(CharSequence) for concatenating strings.[107] For instance, stream.collect(Collectors.groupingBy(Person::getDepartment)) groups persons by department into a Map<String, List<Person>>.[107] Later Java versions, such as Java 9 and beyond, enhanced streams with methods like takeWhile and dropWhile for more precise subrange operations; in Java 24, the Stream Gatherers API was standardized (JEP 485), enabling the creation and reuse of custom intermediate operations to handle complex transformations more elegantly.[108] These build on the Java 8 foundation.
Modules and Recent Enhancements
Java introduced the module system through Project Jigsaw in Java 9, providing a standardized way to encapsulate code into self-describing modules that enhance reliability, maintainability, and security. A module is defined in amodule-info.java file, which declares the module's name and specifies dependencies using the requires directive, while controlling visibility with exports to limit access to internal packages. This system addresses the "JAR hell" problem by enforcing strong encapsulation, preventing unintended access to non-public APIs and reducing classpath conflicts in large applications.
Records, introduced as a preview feature in Java 14 and standardized in Java 16, offer a concise syntax for creating immutable data carrier classes, automatically generating constructors, getters, equals(), hashCode(), and toString() methods.[109] For example, a simple record can be declared as public record Point(int x, int y) {} to represent a 2D coordinate without boilerplate code. This feature promotes cleaner, more readable code for data classes while ensuring immutability by default, with final fields and no setter methods.
Sealed classes, finalized in Java 17, allow developers to restrict which classes or interfaces can extend or implement a given class or interface using the permits clause. Declared as public sealed class Shape permits Circle, Square {} , this enables precise control over inheritance hierarchies, improving API design by documenting exhaustive type sets and supporting pattern matching. Such restrictions enhance code maintainability and enable compiler optimizations for switch statements over sealed types.
Pattern matching has evolved to simplify type checking and data extraction, starting with enhanced instanceof patterns in Java 16, which allow binding variables directly in type tests like if (obj instanceof String s) { ... }. This progressed to switch expressions with pattern matching in Java 21, supporting deconstruction such as switch (shape) { case Circle c -> ...; case Rectangle(int w, int h) r -> ...; }. These features reduce verbosity in conditional logic and integrate seamlessly with sealed classes for exhaustive matching.
Other notable enhancements include text blocks in Java 15, which provide multiline string literals delimited by triple quotes ("""), eliminating the need for escape sequences and concatenation in embedded text like HTML or JSON. Virtual threads, introduced in Java 21 via Project Loom, enable lightweight concurrency by modeling threads as continuations rather than OS threads, supporting millions of threads with minimal overhead (detailed runtime aspects covered elsewhere). Java's development process incorporates preview features, allowing experimental APIs to be tested in incubation modules before stabilization, as seen with records and pattern matching, ensuring iterative refinement based on community feedback.
Runtime and Execution
Java Virtual Machine Overview
The Java Virtual Machine (JVM) serves as the abstract computing machine that enables the execution of Java bytecode, providing a runtime environment that abstracts the details of the underlying hardware and operating system to achieve platform independence. This abstraction allows Java programs, once compiled to bytecode, to run on any device with a compatible JVM implementation without modification. The JVM specification outlines this runtime engine, ensuring consistency across implementations while permitting optimizations specific to target platforms.[9] The core architecture of the JVM consists of several interconnected components that manage the loading, verification, and execution of bytecode. The class loader subsystem dynamically loads class files from the classpath or network into the JVM's memory, organizing them into a namespace hierarchy to support features like class inheritance and dynamic linking. Following loading, the bytecode verifier examines the bytecode to ensure it adheres to the JVM specification, preventing security vulnerabilities such as stack overflows or unauthorized access by confirming type safety and operational validity. Execution occurs through an interpreter that processes bytecode instructions sequentially and a Just-In-Time (JIT) compiler that translates frequently executed bytecode into native machine code for improved performance. Bytecode serves as the portable intermediate format processed by these components.[110] HotSpot, the default JVM implementation in Oracle JDK and OpenJDK distributions, incorporates advanced adaptive optimization mechanisms that monitor application behavior at runtime to identify and recompile "hot" code paths—those executed often—for enhanced efficiency. This just-in-time compilation approach balances startup speed with long-term performance by initially interpreting code and progressively optimizing based on usage profiles.[111] Historically, security in the JVM was managed through the SecurityManager class, which implemented a configurable policy defining permissions for code execution, such as file access or network operations, often specified via policy files that grant privileges based on code source or signing certificates. This mechanism allowed administrators to restrict potentially unsafe operations, particularly for untrusted code like applets, by requiring explicit checks before sensitive actions. However, the SecurityManager was deprecated for removal in Java 17, permanently disabled in JDK 24, and removed in JDK 25 due to its complexity and limited use in modern applications. Current Java security relies on alternatives such as the Java Platform Module System (JPMS) for encapsulation and built-in policies for cryptography and networking.[112][113] The JVM is formally defined by The Java Virtual Machine Specification, a document maintained by Oracle and the OpenJDK community as part of the Java SE platform, with updates aligned to major Java SE releases through the Java Community Process (JCP). Each specification edition, such as for Java SE 25, details the required behavior and interfaces while allowing implementation-specific extensions.[114][115] Cross-platform portability is further enabled by the JVM's ability to invoke native operating system functions through the Java Native Interface (JNI), a standard programming interface that allows Java code to interact with libraries written in languages like C or C++, bridging the gap to hardware-specific capabilities without compromising the bytecode's portability.[116]Bytecode Compilation and JIT Optimization
Java source code is compiled into platform-independent bytecode using thejavac compiler, which reads class and interface definitions from .java files and generates corresponding .class files containing bytecode instructions executable by the Java Virtual Machine (JVM).[117] These bytecode instructions form a low-level, stack-based virtual machine language, with examples including iload (opcode 21), which loads an integer value from a local variable onto the operand stack, and invokevirtual (opcode 182), which invokes an instance method on an object reference using dynamic dispatch based on the constant pool index.[118] The resulting .class files encapsulate the bytecode along with metadata such as constant pools and access flags, enabling portability across JVM implementations without recompilation.[117]
At runtime, the JVM initially interprets bytecode for quick startup, converting it to native machine code on-the-fly via just-in-time (JIT) compilation to optimize performance for frequently executed ("hot") methods.[119] In the HotSpot JVM, the default implementation in OpenJDK, tiered compilation balances compilation overhead and execution speed across five tiers: tier 0 uses pure interpretation with instrumentation; tiers 1–3 employ the client compiler (C1) for progressively profiled compilations starting after about 200–1,500 invocations; and tier 4 applies the server compiler (C2) for aggressive optimizations after roughly 5,000–10,000 invocations.[120][119] This adaptive approach collects runtime profiling data during interpretation and lower tiers to inform higher-tier decisions, ensuring methods transition from interpreted execution to optimized native code as usage patterns emerge.[120]
The JIT compilers perform a range of optimization techniques to generate efficient native code, prioritizing hot paths based on invocation counts and profile feedback. Inlining replaces method calls with the actual method body for small or frequent methods, reducing call overhead and enabling further intra-method optimizations; for instance, trivial inlining handles simple cases, while speculative inlining uses guards for virtual calls.[119][121] Escape analysis examines object lifetimes to determine if allocations can be eliminated or moved to the stack if objects do not escape their creating method, avoiding heap allocations and enabling scalar replacement.[119][121] Loop unrolling duplicates loop bodies to minimize iteration overhead, facilitating subsequent transformations like vectorization or invariant code motion, particularly in the C2 compiler's global optimizations.[119][121]
While experimental ahead-of-time (AOT) compilation was previously available in the JDK to pre-generate native code for faster startup, it has been removed since JDK 17. AOT for Java applications is now primarily supported through external tools such as GraalVM Native Image, which produces standalone executables. Within the standard JVM, JIT remains the primary optimization mechanism, offering superior adaptability for long-running applications.[122][123]
JIT's runtime optimizations yield superior peak throughput for long-running applications by adapting to actual workloads, often achieving near-native performance after warmup, whereas AOT prioritizes reduced startup time (e.g., sub-second launches versus minutes for JIT warmup) at the cost of potentially lower steady-state efficiency due to static assumptions.[124] This trade-off makes JIT ideal for server environments emphasizing sustained high throughput, while AOT suits latency-sensitive, short-lived processes like microservices.[124]
Garbage Collection and Memory Management
Java provides automatic memory management through its garbage collection (GC) mechanism, which identifies and reclaims memory occupied by objects no longer in use, eliminating the need for explicit deallocation as in languages like C++. This process occurs within the Java Virtual Machine (JVM) heap, a contiguous memory area allocated for object storage. The heap is divided into generations to optimize collection efficiency: the young generation, where most short-lived objects are allocated, and the old generation for long-lived objects. The young generation consists of an Eden space for new allocations and two Survivor spaces (S0 and S1) that hold objects surviving minor collections; objects promoted from the young generation after multiple survival cycles move to the old generation. Since Java 8, class metadata, previously stored in the permanent generation, is managed in native memory via Metaspace, which dynamically resizes and is subject to GC when space is low. In Java 25, compact object headers (JEP 519) further reduce memory overhead by using smaller headers for objects, improving overall memory efficiency especially in large-scale applications.[125][126] Garbage collection in the JVM primarily employs a mark-and-sweep algorithm to manage heap memory. In the marking phase, the GC traces from root references (such as stack variables and static fields) to identify live objects, marking them to distinguish from garbage. The sweeping phase then scans the heap to reclaim unmarked (dead) space, freeing it for reuse. Compaction follows in many collectors, relocating surviving objects to eliminate fragmentation and reduce allocation failures, though this can introduce pauses. These phases enable efficient memory reclamation but vary in concurrency and parallelism across collectors to balance throughput, latency, and CPU usage.[127] The JVM offers several GC implementations, selectable via command-line flags, each tailored to different workloads. The Serial collector performs both minor and major collections using a single thread, making it suitable for small applications or single-processor environments with heaps up to about 100 MB; it is enabled with-XX:+UseSerialGC. The Parallel collector, also known as the throughput collector, extends this with multiple threads for young and old generation collections, prioritizing high throughput on multiprocessor systems; enable it using -XX:+UseParallelGC. For larger heaps, the Garbage-First (G1) collector partitions the heap into fixed-size regions (default 1-32 MB) and prioritizes collecting regions with the most garbage, aiming for predictable pause times under 200 ms; it became the default since Java 9 and is explicitly set with -XX:+UseG1GC. Low-latency options include ZGC, introduced in Java 15, which achieves sub-millisecond pauses (<1 ms) for heaps from hundreds of MB to 16 TB by performing most work concurrently and using colored pointers for relocation; enable generational mode with -XX:+UseZGC -XX:+ZGenerational (available since Java 21). Shenandoah, available since JDK 12 (production in JDK 15), focuses on low pauses (typically 0-10 ms) via concurrent evacuation and compaction, supporting heaps of varying sizes; it is activated by -XX:+UseShenandoahGC. Java 25 introduces Generational Shenandoah (JEP 521), adding nursery and old generations to further reduce pauses and improve throughput for mixed workloads; it is enabled similarly with generational flags.[128][129]
Tuning GC involves JVM flags to control heap size and collector behavior, often guided by application profiling to minimize pauses or maximize throughput. The maximum heap size is set with -Xmx (e.g., -Xmx4g for 4 GB), while -Xms specifies the initial size to avoid resize overhead; exceeding the maximum triggers OutOfMemoryError. For G1, -XX:MaxGCPauseTimeMillis=200 targets pause goals, and -XX:G1HeapRegionSize adjusts region granularity. Parallelism can be tuned via -XX:ParallelGCThreads for collector threads. Monitoring tools like JFR or jstat help assess effectiveness, with adjustments based on metrics such as promotion rates and pause durations.[130]
Java supports reference types for fine-grained control over object reachability and collection. Weak references (WeakReference) allow objects to be reclaimed when only weakly reachable, useful for canonicalizing or avoiding memory leaks in caches; they become eligible for finalization upon clearing. Soft references (SoftReference) defer collection until memory pressure arises, ideal for image caches or least-recently-used eviction, with clearance based on heap availability (tunable via -XX:SoftRefLRUPolicyMSPerMB). Finalizers, implemented via Object.finalize(), were historically used for resource cleanup but are deprecated since JDK 9 and slated for removal due to unpredictability, security risks, and performance overhead; monitor their impact with jcmd GC.finalizer_info. Instead, the Cleaner API (introduced in Java 9) registers explicit cleaning actions for phantom-reachable objects, providing safer, more predictable cleanup without finalization's drawbacks.[131]
Standard Class Libraries
Core API Packages
The core API packages in Java form the foundational layer of the standard class libraries, providing essential classes and interfaces for basic language operations, utility functions, and input/output handling without requiring external dependencies. These packages are part of thejava.base module in modular Java applications and are designed to support core programming needs across platforms. They emphasize portability, security, and efficiency, enabling developers to build robust applications from simple utilities to complex data processing.
The java.lang package contains the fundamental classes that are automatically imported in every Java compilation unit, eliminating the need for explicit import statements. It serves as the bedrock of the Java class hierarchy, with the Object class acting as the superclass for all other classes, providing methods like equals(), hashCode(), and toString() that ensure consistent behavior across the language. Key classes include String for immutable sequences of characters, supporting operations like concatenation and substring extraction; Thread for managing concurrent execution threads within programs; and Throwable (the base for Exception and Error classes) to handle runtime errors and exceptional conditions. This package also includes wrapper classes for primitive types (e.g., Integer, Double) and utility classes like Math for basic numeric computations and System for interacting with the runtime environment. Introduced in Java 1.0, java.lang ensures that core language features are always accessible.[132][133][134][135]
The java.util package offers a suite of utility classes for common programming tasks, including date and time manipulation, random number generation, and input parsing. Since Java 8, the modern java.time subpackage provides a comprehensive Date/Time API with classes like LocalDate, LocalTime, and ZonedDateTime for handling dates, times, durations, and time zones in a thread-safe, immutable manner, replacing the legacy java.util.Date and Calendar classes that suffered from mutability issues and limited functionality. The Random class generates pseudorandom numbers using a 48-bit seed for basic stochastic operations, while SplittableRandom extends this for parallel computations with a longer 64-bit period. Additionally, Scanner facilitates parsing of primitive types and strings from input sources using regular expressions, making it ideal for reading user input or configuration files. Overall, java.util supports internationalization, properties handling, and miscellaneous utilities beyond data structures.[136][137]
For input and output operations, the java.io package defines classes for handling data streams, character streams, and file system interactions through a stream-based model. Byte-oriented streams are built around abstract base classes InputStream for reading data sequentially and OutputStream for writing it, with subclasses like FileInputStream and FileOutputStream enabling direct access to files. Character-oriented streams use Reader and Writer as bases, supporting Unicode text handling; for example, BufferedReader and BufferedWriter add buffering to improve performance for text I/O. File handling is managed via the File class, which represents pathnames and provides methods for creating, deleting, and querying files or directories, while serialization is supported through ObjectInputStream and ObjectOutputStream for persisting object graphs. All operations are subject to IOException for error handling, ensuring robust I/O in networked or file-based applications. This package, available since Java 1.0, focuses on blocking, synchronous operations.[138][139]
The java.math package addresses limitations of primitive numeric types by offering classes for arbitrary-precision arithmetic, crucial for financial, cryptographic, or scientific computations where overflow or precision loss must be avoided. BigInteger represents immutable, signed integers of unlimited length, supporting operations like addition, multiplication, modular exponentiation, greatest common divisor calculation, primality testing, and bit shifts, making it suitable for large-scale integer math. Similarly, BigDecimal provides fixed-point decimal arithmetic with full control over rounding via eight predefined modes (e.g., ROUND_HALF_UP), ideal for exact monetary calculations without floating-point inaccuracies. Both classes, introduced in Java 1.1, implement comparable interfaces and are designed for performance in high-precision scenarios.[140][141][142]
Introduced in Java 1.4 as an enhancement to traditional I/O, the java.nio package (New I/O) introduces buffer- and channel-based mechanisms for more efficient, scalable data transfer, particularly supporting non-blocking operations. Buffers, such as ByteBuffer and CharBuffer, act as fixed-size containers for primitive types or characters, maintaining position, limit, and capacity indices to facilitate reading, writing, and flipping between modes without copying data. Channels provide open connections to I/O sources or destinations, enabling direct interaction with files, sockets, or other entities; for instance, FileChannel supports memory-mapped files for high-speed access. This architecture allows for non-blocking I/O via selectors and multiplexed channels, improving throughput in server applications compared to the stream model in java.io. Networking extensions build on these channels for socket programming, as detailed in related utilities.[143][144][145][146]
GUI and Multimedia Frameworks
Java's graphical user interface (GUI) frameworks provide developers with tools to create interactive desktop applications, leveraging the platform's "write once, run anywhere" philosophy through cross-platform rendering. The primary frameworks evolved from early lightweight components to modern scene-graph-based systems, enabling rich visual experiences without native dependencies. These libraries integrate seamlessly with the Java runtime, handling events and rendering via the Java Virtual Machine. The Abstract Window Toolkit (AWT), introduced in Java 1.0, forms the foundational layer for GUI development by utilizing native platform components, known as peers, to render windows, buttons, and menus. This approach ensures compatibility with underlying operating systems like Windows, macOS, and Linux, but it results in a "heavyweight" model where components are tied to the host system's look and feel, potentially leading to inconsistencies across platforms. AWT supports basic event handling through interfaces like ActionListener, allowing developers to respond to user interactions such as mouse clicks or key presses. Despite its limitations, AWT remains essential for simple applets and as a base for higher-level toolkits. Building upon AWT, Swing—part of the Java Foundation Classes (JFC) released in Java 1.2—offers a pure Java implementation of GUI components, eliminating reliance on native peers for a consistent appearance and behavior across platforms. Swing introduces "lightweight" components like JComponent, which enable custom painting and pluggable look-and-feels (L&Fs), such as Metal, Nimbus, or system defaults, allowing applications to mimic native styles if desired. Key elements include advanced widgets like JTable for tabular data display, JTree for hierarchical structures, and layout managers such as BorderLayout and GridBagLayout for flexible positioning. Swing's MVC (Model-View-Controller) architecture separates data from presentation, enhancing maintainability in complex UIs. JavaFX, bundled with JDK 8 and modularized in JDK 9, was removed from the standard JDK distribution starting with JDK 11 and is now a separate open-source platform maintained by the OpenJFX project. Oracle's commercial support ended in April 2025, but it remains actively developed, with JavaFX 25 released in September 2025, and represents the modern evolution of Java's GUI capabilities, positioning itself as the successor to Swing for new development due to its support for richer media and animations.[147][148] It employs a scene graph model where UI elements are nodes in a hierarchical tree, manipulated via the JavaFX API for transformations, effects, and bindings. Developers can define interfaces using FXML, an XML-based markup language, and style them with CSS, facilitating designer-developer workflows similar to web technologies. JavaFX excels in creating responsive applications with hardware-accelerated rendering through its Prism engine, supporting features like charts, media playback, and 2D/3D primitives, though it focuses primarily on 2D for standard use. Its modular nature allows selective inclusion in applications, reducing footprint in containerized environments. For multimedia handling, Java provides dedicated APIs to manipulate graphics and audio within GUIs. The Java 2D API, part of the java.awt.geom and java.awt.image packages since Java 1.2, enables high-quality 2D rendering with support for shapes, text, gradients, and compositing operations, integrated into both AWT and Swing for custom drawing in components like JPanel. Image I/O (javax.imageio), introduced in Java 1.4, facilitates reading and writing raster formats such as JPEG, PNG, and GIF, streamlining image processing tasks. Audio capabilities are handled by the javax.sound.midi and javax.sound.sampled packages, offering playback, mixing, and synthesis for MIDI files and sampled sounds, suitable for simple games or interactive apps. The Java Media Framework (JMF), an earlier extension for streaming and advanced media, was deprecated in favor of more integrated solutions, with JavaFX now providing built-in media players for video and audio. Accessibility in Java's GUI frameworks ensures that applications are usable by people with disabilities, adhering to standards like the Web Content Accessibility Guidelines (WCAG) through built-in support. The Accessible interface, implemented in core components across AWT, Swing, and JavaFX, exposes properties for screen readers and assistive technologies, including role descriptions, state information, and keyboard navigation. For instance, Swing's JComponent provides methods like getAccessibleContext() to integrate with platforms like JAWS or VoiceOver, while JavaFX extends this via javafx.scene.AccessibleAttribute for dynamic UI updates. This framework promotes inclusive design without requiring extensive custom code.Networking and Concurrency Utilities
Java's networking utilities, primarily in thejava.net package, enable applications to communicate over networks using TCP and UDP protocols. The Socket class provides a client-side API for establishing TCP connections to remote hosts, allowing bidirectional data streams for reliable communication. Similarly, the URL class represents uniform resource locators and facilitates resource retrieval, while HttpURLConnection, an extension of URLConnection, supports HTTP-specific operations such as GET and POST requests, including header management and response code handling. These classes form the foundation for basic network I/O in Java, supporting both blocking and non-blocking modes.[149]
For more efficient, scalable networking, Java introduced the New I/O (NIO) package, featuring channel-based abstractions like SocketChannel. This selectable channel supports stream-oriented connecting sockets, enabling non-blocking I/O operations and integration with selectors for multiplexing multiple connections. SocketChannel instances are created via open methods and connected asynchronously, making them suitable for high-throughput server applications. In Java 11, the standardized HTTP Client API in java.net.http further modernizes web interactions by providing an asynchronous, reactive model for sending requests and processing responses. It supports both HTTP/1.1 and HTTP/2 protocols, with builders for configuring timeouts, redirects, and authentication, replacing older approaches like HttpURLConnection for complex scenarios.[150][151]
Concurrency in Java is built on foundational threading primitives that allow multiple execution flows within a single process. The Thread class extends the base for creating and managing threads, while the Runnable interface defines a task executable by a thread, promoting separation of concerns in multithreaded designs. Synchronization is achieved via the synchronized keyword, which enforces mutual exclusion on methods or blocks to prevent race conditions, and the volatile keyword ensures visibility of changes to shared variables across threads by establishing a happens-before relationship. These primitives, detailed in the Java Language Specification, underpin safe concurrent access to shared state.[152]
The java.util.concurrent package extends these basics with high-level abstractions for scalable parallelism. ExecutorService manages thread pools and asynchronous task execution, submitting Callable or Runnable tasks and returning Future objects to track completion and retrieve results. The package also includes the Lock interface and implementations like ReentrantLock for flexible locking beyond synchronized, supporting features such as try-lock and fairness policies. Atomic classes in java.util.concurrent.atomic, such as AtomicInteger and AtomicReference, enable lock-free updates to single variables using compare-and-swap operations, reducing contention in high-concurrency environments.[153][154][155]
Introduced in Java 7, the Fork/Join Framework implements a work-stealing algorithm via ForkJoinPool and ForkJoinTask, optimizing recursive divide-and-conquer tasks across multicore processors. It extends ExecutorService by forking subtasks in parallel and joining results, minimizing overhead in compute-intensive applications like sorting or tree traversals. Java 8's parallel streams build on this by automatically utilizing the common ForkJoinPool for aggregate operations on collections, partitioning data for concurrent processing while preserving order when needed. This integration allows developers to leverage multicore hardware with minimal code changes, as streams execute in parallel by default when parallelism is requested.[156][157]
For secure networking, the Java Secure Socket Extension (JSSE) provides a framework implementing SSL and TLS protocols atop the networking APIs. It handles encryption, server authentication, and message integrity using classes like SSLSocket and SSLEngine, configurable via key stores and trust managers. JSSE integrates seamlessly with Socket and SocketChannel, enabling encrypted channels without altering core I/O logic.[158]
