Java Platform, Standard Edition (Java SE) is a computing platform, technical standard for execution of applications on independent Java-supported platforms as such portable code for desktop and server environments. Java SE was formerly known as Java 2 Platform, Standard Edition (J2SE).
The platform uses the Java programming language and is part of the Java software-platform family. Java SE defines a range of general-purpose APIs—such as Java APIs for the Java Class Library—and also includes the Java Language Specification and the Java Virtual Machine Specification. OpenJDK is the official reference implementation since version 7.Moving to OpenJDK as the official Java SE 7 Reference ImplementationJava Platform, Standard Edition 7 Reference Implementations
Nomenclature, standards and specifications The platform was known as Java 2 Platform, Standard Edition or J2SE from version 1.2, until the name was changed to Java Platform, Standard Edition or Java SE in version 1.5. The "SE" is used to distinguish the base platform from the Enterprise Edition (Java EE) and Micro Edition (Java ME) platforms. The "2" was originally intended to emphasize the major changes introduced in version 1.2, but was removed in version 1.6. The naming convention has been changed several times over the Java version history. Starting with J2SE 1.4 (Merlin), Java SE has been developed under the Java Community Process, which produces descriptions of proposed and final specifications for the Java platform called Java Specification Requests (JSR). JSR 59 was the umbrella specification for J2SE 1.4 and JSR 176 specified J2SE 5.0 (Tiger). Java SE 6 (Mustang) was released under JSR 270.
Java Platform, Enterprise Edition (Java EE) is a related specification that includes all the classes in Java SE, plus a number that are more useful to programs that run on servers as opposed to workstations.
Java Platform, Micro Edition (Java ME) is a related specification intended to provide a certified collection of Java APIs for the development of software for small, resource-constrained devices such as cell phones, PDAs and set-top boxes.
The Java Runtime Environment (JRE) and Java Development Kit (JDK) are the actual files downloaded and installed on a computer to run or develop Java programs, respectively.
General purpose packages The majority of these packages are exported by the java.base module of the Java Platform Module System (since Java 9).
java.lang The Java package contains fundamental classes and interfaces closely tied to the language and runtime system. This includes the root classes that form the class hierarchy, types tied to the language definition, basic exceptions, math functions, threading, security functions, as well as some information on the underlying native system. This package contains 22 of 32 java.lang.Error classes provided in JDK 6.
The main classes and interfaces in java.lang are:
– the class that is the root of every class hierarchy. – the base class for enumeration classes (as of J2SE 5.0). – the class that is the root of the Java reflective programming (reflection) system. – the class that is the base class of the exception class hierarchy. , , and – the base classes for each exception type. – the class that allows operations on threads. – the class for strings and string literals. and – classes for performing string manipulation (StringBuilder as of J2SE 5.0). – the interface that allows generic comparison and ordering of objects (as of J2SE 1.2). – the interface that allows generic iteration using the enhanced for loop (as of J2SE 5.0). , , , , and – classes that provide "system operations" that manage the dynamic loading of classes, creation of external processes, host environment inquiries such as the time of day, and enforcement of security policies. and – classes that provide basic math functions such as sine, cosine, and square root (java.lang.StrictMath as of J2SE 1.3). The primitive wrapper classes that encapsulate primitive types as objects. The basic exception classes thrown for language-level and other common exceptions.
Classes in java.lang are automatically imported into every source file.
java.lang.ref The package provides more flexible types of references than are otherwise available, permitting limited interaction between the application and the Java Virtual Machine (JVM) garbage collector. It is an important package, central enough to the language for the language designers to put it under the java.lang namespace, but it is somewhat special-purpose and not used by a lot of developers. This package was added in J2SE 1.2.
Java has an expressive system of references and allows for special behavior for garbage collection. A normal reference in Java is known as a "strong reference". The java.lang.ref package defines three other types of references—soft, weak, and phantom references. Each type of reference is designed for a specific use.
A can be used to implement a cache. An object that is not reachable by a strong reference (that is, not strongly reachable), but is referenced by a soft reference is called "softly reachable". A softly reachable object may be garbage collected at the discretion of the garbage collector. This generally means that softly reachable objects are only garbage collected when free memory is low—but again, this is at the garbage collector's discretion. Semantically, a soft reference means, "Keep this object when nothing else references it, unless the memory is needed." A is used to implement weak maps. An object that is not strongly or softly reachable, but is referenced by a weak reference is called "weakly reachable". A weakly reachable object is garbage collected in the next collection cycle. This behavior is used in the class . A weak map allows the programmer to put key/value pairs in the map and not worry about the objects taking up memory when the key is no longer reachable anywhere else. Another possible application of weak references is the string intern pool. Semantically, a weak reference means "get rid of this object when nothing else references it at the next garbage collection." A is used to reference objects that have been marked for garbage collection and have been finalized, but have not yet been reclaimed. An object that is not strongly, softly or weakly reachable, but is referenced by a phantom reference is called "phantom reachable." This allows for more flexible cleanup than is possible with the finalization mechanism alone. Semantically, a phantom reference means "this object is no longer needed and has been finalized in preparation for being collected."
Each of these reference types extends the class, which provides the method to return a strong reference to the referent object (or null if the reference has been cleared or if the reference type is phantom), and the method to clear the reference.
The java.lang.ref also defines the class , which can be used in each of the applications discussed above to keep track of objects that have changed reference type. When a java.lang.ref.Reference<T> is created it is optionally registered with a reference queue. The application polls the reference queue to get references that have changed reachability state.
java.lang.reflect Reflective programming (reflection) is a constituent of the Java API that lets Java code examine and "reflect" on Java components at runtime and use the reflected members. Classes in the package, along with java.lang.Class<T> and accommodate applications such as debuggers, interpreters, object inspectors, class browsers, and services such as object serialization and JavaBeans that need access to either the public members of a target object (based on its runtime class) or the members declared by a given class. This package was added in JDK 1.1.
Reflection is used to instantiate classes and invoke methods using their names, a concept that allows for dynamic programming. Classes, interfaces, methods, fields, and constructors can all be discovered and used at runtime. Reflection is supported by metadata that the JVM has about the program.
Techniques There are basic techniques involved in reflection: Discovery – this involves taking an object or class and discovering the members, superclasses, implemented interfaces, and then possibly using the discovered elements. Use by name – involves starting with the symbolic name of an element and using the named element.
Discovery Discovery typically starts with an object and calling the method to get the object's java.lang.Class<?>. The java.lang.Class<T> object has several methods for discovering the contents of the class, for example: – returns an array of objects representing all the public methods of the class or interface – returns an array of objects representing all the public constructors of the class – returns an array of objects representing all the public fields of the class or interface – returns a java.lang.Class<?>[] objects representing all the public classes and interfaces that are members (e.g. inner classes) of the class or interface – returns the java.lang.Class<? super T> object representing the superclass of the class or interface (null is returned for interfaces) – returns a java.lang.Class<?>[] representing all the interfaces that are implemented by the class or interface
Use by name The java.lang.Class<T> object can be obtained either through discovery, by using the class literal (e.g. X.class, for a class X) or by using the name of the class (e.g. ). With a java.lang.Class<T> object, member java.lang.reflect.Method, java.lang.reflect.Constructor<T>, or java.lang.reflect.Field objects can be obtained using the symbolic name of the member. For example: – returns the java.lang.reflect.Method object representing the public method with the name name of the class or interface that accepts the parameters specified by the java.lang.Class<?>... parameters. – returns the java.lang.reflect.Constructor<T> object representing the public constructor of the class that accepts the parameters specified by the java.lang.Class<?>... parameters. – returns the java.lang.reflect.Field object representing the public field with the name name of the class or interface.
java.lang.reflect.Method, java.lang.reflect.Constructor<T>, and java.lang.reflect.Field objects can be used to dynamically access the represented member of the class. For example: – returns an java.lang.Object containing the value of the field from the instance of the object passed to get(). (If the java.lang.reflect.Field object represents a static field then the java.lang.Object parameter is ignored and may be null.) – returns an java.lang.Object containing the result of invoking the method for the instance of the first java.lang.Object parameter passed to invoke(). The remaining java.lang.Object... parameters are passed to the method. (If the java.lang.reflect.Method object represents a static method then the first java.lang.Object parameter is ignored and may be null.) – returns the new java.lang.Object instance from invoking the constructor. The java.lang.Object... parameters are passed to the constructor. (Note that the parameterless constructor for a class can also be invoked by calling .)
Arrays and proxies The java.lang.reflect package also provides an class that contains static methods for creating and manipulating array objects, and since J2SE 1.3, a class that supports dynamic creation of proxy classes that implement specified interfaces.