Java is a
programming languageA programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....
originally developed by
James GoslingJames A. Gosling, OC is a computer scientist, best known as the father of the Java programming language.-Education and career:In 1977, Gosling received a B.Sc in Computer Science from the University of Calgary...
at
Sun MicrosystemsSun Microsystems, Inc. was a company that sold :computers, computer components, :computer software, and :information technology services. Sun was founded on February 24, 1982...
(now part of
Oracle CorporationOracle Corporation is an American multinational computer technology corporation that specializes in developing and marketing hardware systems and enterprise software products – particularly database management systems...
) and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from
CC is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
and
C++C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
but has a simpler
object modelIn computing, object model has two related but distinct meanings:# The properties of objects in general in a specific computer programming language, technology, notation or methodology that uses them. For example, the Java objects model, the COM object model, or the object model of OMT...
and fewer
low-levelIn computer science, a low-level programming language is a programming language that provides little or no abstraction from a computer's instruction set architecture. Generally this refers to either machine code or assembly language...
facilities. Java applications are typically
compiledA compiler is a computer program that transforms source code written in a programming language into another computer language...
to
bytecodeJava bytecode is the form of instructions that the Java virtual machine executes. Each bytecode opcode is one byte in length, although some require parameters, resulting in some multi-byte instructions. Not all of the possible 256 opcodes are used. 51 are reserved for future use...
(
class fileIn the Java programming language, source files are compiled into machine-readable class files which have a .class extension. Since Java is a platform-independent language, source code is compiled into an output file known as bytecode, which it stores in a .class file. If a source file has more...
) that can run on any
Java Virtual MachineA Java virtual machine is a virtual machine capable of executing Java bytecode. It is the code execution component of the Java software platform. Sun Microsystems stated that there are over 4.5 billion JVM-enabled devices.-Overview:...
(JVM) regardless of
computer architectureIn computer science and engineering, computer architecture is the practical art of selecting and interconnecting hardware components to create computers that meet functional, performance and cost goals and the formal modelling of those systems....
.
Java is a general-purpose, concurrent, class-based, object-oriented language that is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere." Java is currently one of the most popular programming languages in use, particularly for client-server web applications.
The original and reference implementation Java
compilerA compiler is a computer program that transforms source code written in a programming language into another computer language...
s, virtual machines, and class libraries were developed by Sun from 1995. As of May 2007, in compliance with the specifications of the
Java Community ProcessThe Java Community Process or JCP, established in 1998, is a formalized process that allows interested parties to get involved in the definition of future versions and features of the Java platform....
, Sun relicensed most of its Java technologies under the
GNU General Public LicenseThe GNU General Public License is the most widely used free software license, originally written by Richard Stallman for the GNU Project....
. Others have also developed alternative implementations of these Sun technologies, such as the
GNU Compiler for Java and
GNU ClasspathGNU Classpath is a project aiming to create a free software implementation of the standard class library for the Java programming language. Despite the massive size of the library to be created, the majority of the task is already done, including Swing, CORBA, and other major parts. The Classpath...
.
History
James GoslingJames A. Gosling, OC is a computer scientist, best known as the father of the Java programming language.-Education and career:In 1977, Gosling received a B.Sc in Computer Science from the University of Calgary...
, Mike Sheridan, and
Patrick NaughtonPatrick Naughton is an American software developer, best known as being one of the original creators of the Java programming language.-Working for Sun:...
initiated the Java language project in June 1991. Java was originally designed for interactive television, but it was too advanced for the digital cable television industry at the time. The language was initially called
OakOak was a programming language created by James Gosling in 1991, initially for Sun Microsystems set-top box project. The language later evolved to become Java.The name Oak was used by Gosling after an oak tree that stood outside his office.-History:...
after an
oak treeAn oak is a tree or shrub in the genus Quercus , of which about 600 species exist. "Oak" may also appear in the names of species in related genera, notably Lithocarpus...
that stood outside Gosling's office; it went by the name
Green later, and was later renamed
Java, from Java coffee, said to be consumed in large quantities by the language's creators. Gosling aimed to implement a
virtual machineA virtual machine is a "completely isolated guest operating system installation within a normal host operating system". Modern virtual machines are implemented with either software emulation or hardware virtualization or both together.-VM Definitions:A virtual machine is a software...
and a language that had a familiar
CC is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
/
C++C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
style of notation.
Sun Microsystems released the first public implementation as Java 1.0 in 1995. It promised "
Write Once, Run Anywhere"Write once, run anywhere" , or sometimes write once, run everywhere , is a slogan created by Sun Microsystems to illustrate the cross-platform benefits of the Java language. Ideally, this means Java can be developed on any device, compiled into a standard bytecode and be expected to run on any...
" (WORA), 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
appletIn computing, an applet is any small application that performs one specific task that runs within the scope of a larger program, often as a plug-in. An applet typically also refers to Java applets, i.e., programs written in the Java programming language that are included in a web page...
s within web pages, and Java quickly became popular. 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. For example,
J2EE targeted enterprise applications and the greatly stripped-down version
J2ME for mobile applications (Mobile Java).
J2SE designated the Standard Edition. In 2006, for marketing purposes, Sun renamed new
J2 versions as
Java EEJava Platform, Enterprise Edition or Java EE is widely used platform for server programming in the Java programming language. The Java platform differs from the Java Standard Edition Platform in that it adds libraries which provide functionality to deploy fault-tolerant, distributed, multi-tier...
,
Java MEJava Platform, Micro Edition, or Java ME, is a Java platform designed for embedded systems . Target devices range from industrial controls to mobile phones and set-top boxes...
, and
Java SEJava Platform, Standard Edition or Java SE is a widely used platform for programming in the Java language. It is the Java Platform used to deploy portable applications for general use...
, respectively.
In 1997, Sun Microsystems approached the
ISO/IEC JTC1ISO/IEC JTC 1 is Joint Technical Committee 1 of the International Organization for Standardization and the International Electrotechnical Commission . It deals with all matters of information technology....
standards body and later the
Ecma InternationalEcma International is an international, private non-profit standards organization for information and communication systems. It acquired its name in 1994, when the European Computer Manufacturers Association changed its name to reflect the organization's global reach and activities...
to formalize Java, but it soon withdrew from the process. Java remains a
de factoDe facto is a Latin expression that means "concerning fact." In law, it often means "in practice but not necessarily ordained by law" or "in practice or actuality, but not officially established." It is commonly used in contrast to de jure when referring to matters of law, governance, or...
standard, controlled through the
Java Community ProcessThe Java Community Process or JCP, established in 1998, is a formalized process that allows interested parties to get involved in the definition of future versions and features of the Java platform....
. At one time, Sun made most of its Java implementations available without charge, despite their
proprietary softwareProprietary software is computer software licensed under exclusive legal right of the copyright holder. The licensee is given the right to use the software under certain conditions, while restricted from other uses, such as modification, further distribution, or reverse engineering.Complementary...
status. Sun generated revenue from Java through the selling of licenses for specialized products such as the Java Enterprise System. Sun distinguishes between its
Software Development Kit (SDK)A software development kit is typically a set of software development tools that allows for the creation of applications for a certain software package, software framework, hardware platform, computer system, video game console, operating system, or similar platform.It may be something as simple...
and
Runtime Environment (JRE)HotSpot is a Java virtual machine for desktops and servers, maintained and distributed by Oracle Corporation. It features techniques such as just-in-time compilation and adaptive optimization designed to improve performance.-History:...
(a subset of the SDK); the primary distinction involves the JRE's lack of the compiler, utility programs, and header files.
On November 13, 2006, Sun released much of Java as
free and open source softwareFree and open-source software or free/libre/open-source software is software that is liberally licensed to grant users the right to use, study, change, and improve its design through the availability of its source code...
, (FOSS), under the terms of the
GNU General Public LicenseThe GNU General Public License is the most widely used free software license, originally written by Richard Stallman for the GNU Project....
(GPL). On May 8, 2007, Sun finished the process, making all of Java's core code available under
free softwareFree software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...
/open-source distribution terms, aside from a small portion of code to which Sun did not hold the copyright.
Sun's vice-president Rich Green said that Sun's ideal role with regards to Java was as an "evangelist." Following
Oracle CorporationOracle Corporation is an American multinational computer technology corporation that specializes in developing and marketing hardware systems and enterprise software products – particularly database management systems...
's acquisition of Sun Microsystems in 2009–2010, Oracle has described itself as the "steward of Java technology with a relentless commitment to fostering a community of participation and transparency". Java software runs on
laptopA laptop, also called a notebook, is a personal computer for mobile use. A laptop integrates most of the typical components of a desktop computer, including a display, a keyboard, a pointing device and speakers into a single unit...
s to
data centerA data center is a facility used to house computer systems and associated components, such as telecommunications and storage systems...
s,
game consolesA video game console is an interactive entertainment computer or customized computer system that produces a video display signal which can be used with a display device to display a video game...
to scientific
supercomputerA supercomputer is a computer at the frontline of current processing capacity, particularly speed of calculation.Supercomputers are used for highly calculation-intensive tasks such as problems including quantum physics, weather forecasting, climate research, molecular modeling A supercomputer is a...
s. There are 930 million Java Runtime Environment downloads each year and 3 billion
mobile phoneA mobile phone is a device which can make and receive telephone calls over a radio link whilst moving around a wide geographic area. It does so by connecting to a cellular network provided by a mobile network operator...
s run Java. On April 2, 2010, James Gosling resigned from Oracle.
Principles
There were five primary goals in the creation of the Java language:
- It should be "simple, object-oriented and familiar"
- It should be "robust and secure"
- It should be "architecture-neutral and portable"
- It should execute with "high performance"
- It should be "interpreted, threaded, and dynamic"
Versions
Major release versions of Java, along with their release dates:
- JDK 1.0 (January 23, 1996)
- 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 Platform
One characteristic of Java is portability, which means that computer programs written in the Java language must run similarly on any hardware/operating-system platform.
This is achieved by compiling the Java language code to an intermediate representation called
Java bytecodeJava bytecode is the form of instructions that the Java virtual machine executes. Each bytecode opcode is one byte in length, although some require parameters, resulting in some multi-byte instructions. Not all of the possible 256 opcodes are used. 51 are reserved for future use...
, instead of directly to platform-specific
machine codeMachine code or machine language is a system of impartible instructions executed directly by a computer's central processing unit. Each instruction performs a very specific task, typically either an operation on a unit of data Machine code or machine language is a system of impartible instructions...
. Java bytecode instructions are analogous to machine code, but are intended to be
interpretedIn computer science, an interpreter normally means a computer program that executes, i.e. performs, instructions written in a programming language...
by a
virtual machineA virtual machine is a "completely isolated guest operating system installation within a normal host operating system". Modern virtual machines are implemented with either software emulation or hardware virtualization or both together.-VM Definitions:A virtual machine is a software...
(VM) written specifically for the host hardware.
End-userEconomics and commerce define an end user as the person who uses a product. The end user or consumer may differ from the person who purchases the product...
s commonly use a
Java Runtime EnvironmentA Java virtual machine is a virtual machine capable of executing Java bytecode. It is the code execution component of the Java software platform. Sun Microsystems stated that there are over 4.5 billion JVM-enabled devices.-Overview:...
(JRE) installed on their own machine for standalone Java applications, or in a Web browser for Java
appletIn computing, an applet is any small application that performs one specific task that runs within the scope of a larger program, often as a plug-in. An applet typically also refers to Java applets, i.e., programs written in the Java programming language that are included in a web page...
s.
Standardized libraries provide a generic way to access host-specific features such as graphics,
threadingIn computer science, a thread of execution is the smallest unit of processing that can be scheduled by an operating system. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process...
, and
networkingA computer network, often simply referred to as a network, is a collection of hardware components and computers interconnected by communication channels that allow sharing of resources and information....
.
A major benefit of using bytecode is porting. However, the overhead of interpretation means that interpreted programs almost always run more slowly than programs compiled to native executables would. Just-in-Time compilers were introduced from an early stage that compile bytecodes to machine code during runtime.
Implementations
Sun MicrosystemsSun Microsystems, Inc. was a company that sold :computers, computer components, :computer software, and :information technology services. Sun was founded on February 24, 1982...
officially licensed the Java Standard Edition platform for
LinuxLinux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...
,
Mac OS XMac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...
, and Solaris. In the past Sun licensed Java to Microsoft but the license expired without renewal. Because Windows does not ship with a Java software platform, a network of third-party vendors and licensees develop them for Windows and other operating system/hardware platforms.
Sun's trademark license for usage of the Java brand insists that all implementations be "compatible". This resulted in a legal dispute with
MicrosoftMicrosoft Corporation is an American public multinational corporation headquartered in Redmond, Washington, USA that develops, manufactures, licenses, and supports a wide range of products and services predominantly related to computing through its various product divisions...
after Sun claimed that the Microsoft implementation did not support
RMIThe Java Remote Method Invocation Application Programming Interface , or Java RMI, is a Java application programming interface that performs the object-oriented equivalent of remote procedure calls ....
or
JNIThe Java Native Interface is a programming framework that enables Java code running in a Java Virtual Machine to call and to be called by native applications and libraries written in other languages such as C, C++ and assembly.-Purpose and features:JNI enables one to write native methods to...
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. As a result, Microsoft no longer ships Java with
WindowsMicrosoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
, and in recent versions of Windows,
Internet ExplorerWindows Internet Explorer is a series of graphical web browsers developed by Microsoft and included as part of the Microsoft Windows line of operating systems, starting in 1995. It was first released as part of the add-on package Plus! for Windows 95 that year...
cannot support Java applets without a third-party plugin. Sun, and others, have made available free Java run-time systems for those and other versions of Windows.
Platform-independent Java is essential to the
Java EEJava Platform, Enterprise Edition or Java EE is widely used platform for server programming in the Java programming language. The Java platform differs from the Java Standard Edition Platform in that it adds libraries which provide functionality to deploy fault-tolerant, distributed, multi-tier...
strategy, and an even more rigorous validation is required to certify an implementation. This environment enables portable server-side applications, such as
Web serviceA Web service is a method of communication between two electronic devices over the web.The W3C defines a "Web service" as "a software system designed to support interoperable machine-to-machine interaction over a network". It has an interface described in a machine-processable format...
s,
Java ServletA servlet is a Java programming language class used to extend the capabilities of servers that host applications accessed via a request-response programming model. Although servlets can respond to any type of request, they are commonly used to extend the applications hosted by Web servers...
s, and
Enterprise JavaBeanEnterprise JavaBeans is a managed, server-side component architecture for modular construction of enterprise applications.The EJB specification is one of several Java APIs in the Java EE specification. EJB is a server-side model that encapsulates the business logic of an application...
s, as well as with
embedded systemAn embedded system is a computer system designed for specific control functions within a larger system. often with real-time computing constraints. It is embedded as part of a complete device often including hardware and mechanical parts. By contrast, a general-purpose computer, such as a personal...
s based on
OSGiThe Open Services Gateway initiative framework is a module system and service platform for the Java programming language that implements a complete and dynamic component model, something that does not exist in standalone Java/VM environments...
, using
Embedded Java[This section needs to be updated, as Embedded Java covers much more than Java ME and Sun SPOT alone -- it also covers embedded use of Java on top of Java platforms such as JavaCard and Java SE ]...
environments. Through the
GlassFishGlassFish is an open source application server project started by Sun Microsystems for the Java EE platform and now sponsored by Oracle Corporation. The supported version is called Oracle GlassFish Server...
project, Sun is working to create a fully functional, unified
open sourceThe term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...
implementation of the Java EE technologies.
Sun also distributes a superset of the JRE called the
Java Development KitThe Java Development Kit is an Oracle Corporation product aimed at Java developers. Since the introduction of Java, it has been by far the most widely used Java SDK. On 17 November 2006, Sun announced that it would be released under the GNU General Public License , thus making it free software...
(commonly known as the JDK), which includes development tools such as the
Java compilerA Java compiler is a compiler for the Java programming language. The most common form of output from a Java compiler is Java class files containing platform-neutral Java bytecode...
,
JavadocJavadoc is a documentation generator from Sun Microsystems for generating API documentation in HTML format from Java source code.The "doc comments" format used by Javadoc is the de facto industry standard for documenting Java classes. Some IDEs, such as Netbeans and Eclipse automatically generate...
,
JarIn software, JAR is an archive file format typically used to aggregate many Java class files and associated metadata and resources into one file to distribute application software or libraries on the Java platform.JAR files are built on the ZIP file format and have the .jar file extension...
, and
debuggerA debugger or debugging tool is a computer program that is used to test and debug other programs . The code to be examined might alternatively be running on an instruction set simulator , a technique that allows great power in its ability to halt when specific conditions are encountered but which...
.
Performance
Programs written in Java have a reputation for being slower and requiring more memory than those written in
CC is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
. However, Java programs' execution speed improved significantly with the introduction of
Just-in-time compilationIn computing, just-in-time compilation , also known as dynamic translation, is a method to improve the runtime performance of computer programs. Historically, computer programs had two modes of runtime operation, either interpreted or static compilation...
in 1997/1998 for
Java 1.1The Java language has undergone several changes since JDK 1.0 as well as numerous additions of classes and packages to the standard library. Since J2SE 1.4, the evolution of the Java language has been governed by the Java Community Process , which uses Java Specification Requests to propose and...
, the addition of language features supporting better code analysis (such as inner classes, StringBuffer class, optional assertions, etc.), and optimizations in the
Java Virtual MachineA Java virtual machine is a virtual machine capable of executing Java bytecode. It is the code execution component of the Java software platform. Sun Microsystems stated that there are over 4.5 billion JVM-enabled devices.-Overview:...
itself, such as
HotSpotHotSpot is a Java virtual machine for desktops and servers, maintained and distributed by Oracle Corporation. It features techniques such as just-in-time compilation and adaptive optimization designed to improve performance.-History:...
becoming the default for Sun's JVM in 2000. Currently (November 2011), Java 2.0 code has approximately half the performance of C code.
Some platforms offer direct hardware support for Java; there are microcontrollers that can run Java in hardware instead of a software JVM, and
ARMAn arm is an upper limb of the body.Arm may also refer to:-Geography:* Arm , a narrow stretch of a larger body of water** Canal arm, a subsidiary branch of a canal or inland waterway** Distributary or arm, a subsidiary branch of a river...
based processors can have hardware support for executing Java bytecode through its
JazelleJazelle DBX allows some ARM processors to execute Java bytecode in hardware as a third execution state alongside the existing ARM and Thumb modes. Jazelle functionality was specified in the ARMv5TEJ architecture and the first processor with Jazelle technology was the ARM926EJ-S...
option.
Automatic memory management
Java uses an
automatic garbage collectorIn computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program...
to manage memory in the
object lifecycleIn computer science, the object lifetime of an object in object-oriented programming is the time between an object's creation till the object is no longer used, and is destructed or freed.In object-oriented programming , the meaning of creating objects is far more subtle than simple...
. 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 memoryIn computer science, unreachable memory is a block of memory allocated dynamically where the program that allocated the memory no longer has any reachable pointer that refers to it. Similarly, an unreachable object is a dynamically allocated object that has no reachable reference to it...
becomes eligible to be freed automatically by the garbage collector. Something similar to a
memory leakA memory leak, in computer science , occurs when a computer program consumes memory but is unable to release it back to the operating system. In object-oriented programming, a memory leak happens when an object is stored in memory but cannot be accessed by the running code...
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. If methods for a nonexistent object are called, a "null pointer exception" is thrown.
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
stackIn computer science, a stack is a last in, first out abstract data type and linear data structure. A stack can have any abstract data type as an element, but is characterized by only three fundamental operations: push, pop and stack top. The push operation adds a new item to the top of 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 leakA memory leak, in computer science , occurs when a computer program consumes memory but is unable to release it back to the operating system. In object-oriented programming, a memory leak happens when an object is stored in memory but cannot be accessed by the running code...
occurs. 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 and/or crash. This can be partially remedied by the use of
smart pointerIn computer science, a smart pointer is an abstract data type that simulates a pointer while providing additional features, such as automatic garbage collection or bounds checking. These additional features are intended to reduce bugs caused by the misuse of pointers while retaining efficiency...
s, but these add overhead and complexity. Note that garbage collection does not prevent "logical" memory leaks, i.e. those where the memory is still referenced but never used.
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, where object addresses and unsigned integers (usually long integers) can be used interchangeably. This allows the garbage collector to relocate referenced objects and ensures type safety and security.
As in
C++C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
and some other object-oriented languages, variables of Java's primitive data types are not objects. Values of primitive types are either stored directly in fields (for objects) or on the
stackStacks in computing architectures are regions of memory where data is added or removed in a last-in-first-out manner.In most modern computer systems, each thread has a reserved region of memory referred to as its stack. When a function executes, it may add some of its state data to the top of the...
(for methods) rather than on the heap, as commonly true for objects (but see
Escape analysisIn programming language compiler optimization theory, escape analysis is a method for determining the dynamic scope of pointers. It is related to pointer analysis and shape analysis....
). This was a conscious decision by Java's designers for performance reasons. Because of this, Java was not considered to be a pure object-oriented programming language. However, as of Java 5.0, autoboxing enables programmers to proceed as if primitive types were instances of their wrapper class.
Java contains multiple types of garbage collectors. By default, HotSpot uses the
Concurrent Mark Sweep collectorThe Concurrent Mark Sweep Garbage collector is the default garbage collector that is delivered with Java 1.4.1, 5, 6 and 7. It is also known as the CMS Garbage collector....
, also known as the CMS Garbage Collector. However, there are also several other garbage collectors that can be used to manage the Heap. For 90% of applications in Java, the CMS Garbage Collector is good enough.
Syntax
The syntax of Java is largely derived from
C++C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
. Unlike C++, which combines the syntax for structured, generic, and object-oriented programming, Java was built almost exclusively as an object-oriented language. All code is written inside a class, and everything is an object, with the exception of the primitive data types (integers, floating-point numbers, boolean values, and characters), which are not classes for performance reasons.
Unlike C++, Java does not support
operatorProgramming languages typically support a set of operators: operations which differ from the language's functions in calling syntax and/or argument passing mode. Common examples that differ by syntax are mathematical arithmetic operations, e.g...
overloadingIn object oriented computer programming, operator overloading—less commonly known as operator ad-hoc polymorphism—is a specific case of polymorphism, where different operators have different implementations depending on their arguments...
or
multiple inheritanceMultiple inheritance is a feature of some object-oriented computer programming languages in which a class can inherit behaviors and features from more than one superclass....
for
classes. This simplifies the language and aids in preventing potential errors and
anti-patternIn software engineering, an anti-pattern is a pattern that may be commonly used but is ineffective and/or counterproductive in practice.The term was coined in 1995 by Andrew Koenig,...
design.
Java uses similar commenting methods to 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
JavadocJavadoc is a documentation generator from Sun Microsystems for generating API documentation in HTML format from Java source code.The "doc comments" format used by Javadoc is the de facto industry standard for documenting Java classes. Some IDEs, such as Netbeans and Eclipse automatically generate...
commenting style opened with
/** and closed with
*/. The Javadoc style of commenting allows the user to run the Javadoc executable to compile documentation for the program.
Example:
// This is an example of a single line comment using two slashes
/* This is an example of a multiple line comment using the slash and asterisk.
This type of comment can be used to hold a lot of information or deactivate
code but it is very important to remember to close the comment. */
/**
* This is an example of a Javadoc comment; Javadoc can compile documentation
* from this text.
*/
Hello world
The traditional
Hello world programA "Hello world" program is a computer program that outputs "Hello world" on a display device. Because it is typically one of the simplest programs possible in most programming languages, it is by tradition often used to illustrate to beginners the most basic syntax of a programming language, or to...
can be written in Java as:
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
To compare this to other programming languages see the list of
hello world program examplesThe Hello world program is a simple computer program that prints the string "Hello World". It is typically one of the simplest programs possible in almost all computer languages, and often used as first program to demonstrate a programming language. As such it can be used to quickly compare syntax...
.
Source files must be named after the public class they contain, appending the suffix
.java, for example,
HelloWorldApp.java. It must first be compiled into bytecode, using a
Java compilerA Java compiler is a compiler for the Java programming language. The most common form of output from a Java compiler is Java class files containing platform-neutral Java bytecode...
, producing a file named
HelloWorldApp.class. Only then can it be executed, or 'launched'. The Java source file may only contain one public class but can contain multiple classes with less than public access and any number of public
inner classIn object-oriented programming , an inner class or nested class is a class declared entirely within the body of another class or interface. It is distinguished from a subclass.-Overview:...
es.
A
class that is not declared
public may be stored in any .java file. The compiler will generate a class file for each class defined in the source file. The name of the class file is the name of the class, with
.class appended. For class file generation, anonymous classes are treated as if their name were the concatenation of the name of their enclosing class, a
$, and an integer.
The
keyword public denotes that a method can be called from code in other classes, or that a class may be used by classes outside the class hierarchy. The class hierarchy is related to the name of the directory in which the .java file is located.
The keyword
static in front of a method indicates a static method, which is associated only with the class and not with any specific instance of that class. Only static methods can be invoked without a reference to an object. Static methods cannot access any class members that are not also static.
The keyword
void indicates that the main method does not return any value to the caller. If a Java program is to exit with an error code, it must call System.exit explicitly.
The method name "
main" is not a keyword in the Java language. It is simply the name of the method the Java launcher calls to pass control to the program. Java classes that run in managed environments such as applets and
Enterprise JavaBeanEnterprise JavaBeans is a managed, server-side component architecture for modular construction of enterprise applications.The EJB specification is one of several Java APIs in the Java EE specification. EJB is a server-side model that encapsulates the business logic of an application...
do not use or need a
main method. A Java program may contain multiple classes that have
main methods, which means that the VM needs to be explicitly told which class to launch from.
The main method must accept an
arrayIn computer science, an array type is a data type that is meant to describe a collection of elements , each selected by one or more indices that can be computed at run time by the program. Such a collection is usually called an array variable, array value, or simply array...
of
objects. By convention, it is referenced as
args although any other legal identifier name can be used. Since Java 5, the main method can also use
variable argumentsIn computer programming, a variadic function is a function of indefinite arity, i.e., one which accepts a variable number of arguments. Support for variadic functions differs widely among programming languages....
, in the form of
public static void main(String... args), allowing the main method to be invoked with an arbitrary number of
String arguments. The effect of this alternate declaration is semantically identical (the
args parameter is still an array of
String objects), but allows an alternative syntax for creating and passing the array.
The Java launcher launches Java by loading a given class (specified on the command line or as an attribute in a
JARIn software, JAR is an archive file format typically used to aggregate many Java class files and associated metadata and resources into one file to distribute application software or libraries on the Java platform.JAR files are built on the ZIP file format and have the .jar file extension...
) and starting its
public static void main(String[]) method. Stand-alone programs must declare this method explicitly. The
String[] args parameter is an
arrayIn computer science, an array type is a data type that is meant to describe a collection of elements , each selected by one or more indices that can be computed at run time by the program. Such a collection is usually called an array variable, array value, or simply array...
of objects containing any arguments passed to the class. The parameters to
main are often passed by means of a
command lineA command-line interface is a mechanism for interacting with a computer operating system or software by typing commands to perform specific tasks...
.
Printing is part of a Java standard library: The
class defines a public static field called
. The
out object is an instance of the class and provides many methods for printing data to
standard outIn Unix and Unix-like operating systems , as well as certain programming language interfaces, the standard streams are preconnected input and output channels between a computer program and its environment when it begins execution...
, including
which also appends a new line to the passed string.
The string "Hello, world!" is automatically converted to a String object by the compiler.
A more comprehensive example
// OddEven.java
import javax.swing.JOptionPane;
public class OddEven {
// "input" is the number that the user gives to the computer
private int input; // a whole number("int" means integer)
/*
* This is the constructor method. It gets called when an object of the OddEven type
* is being created.
*/
public OddEven {
/*
* In most Java programs constructors can initialize objects with default values, or create
* other objects that this object might use to perform its functions. In some Java programs, the
* constructor may simply be an empty function if nothing needs to be initialized prior to the
* functioning of the object. In this program's case, an empty constructor would suffice, even if
* it is empty. A constructor must exist, however if the user doesn't put one in then the compiler
* will create an empty one.
*/
}
// This is the main method. It gets called when this class is run through a Java interpreter.
public static void main(String[] args) {
/*
* This line of code creates a new instance of this class called "number" (also known as an
* Object) and initializes it by calling the constructor. The next line of code calls
* the "showDialog" method, which brings up a prompt to ask you for a number
*/
OddEven number = new OddEven;
number.showDialog;
}
public void showDialog {
/*
* "try" makes sure nothing goes wrong. If something does,
* the interpreter skips to "catch" to see what it should do.
*/
try {
/*
* The code below brings up a JOptionPane, which is a dialog box
* The String returned by the "showInputDialog" method is converted into
* an integer, making the program treat it as a number instead of a word.
* After that, this method calls a second method, calculate that will
* display either "Even" or "Odd."
*/
input = Integer.parseInt(JOptionPane.showInputDialog("Please Enter A Number"));
calculate;
} catch (NumberFormatException e) {
/*
* Getting in the catch block means that there was a problem with the format of
* the number. Probably some letters were typed in instead of a number.
*/
System.err.println("ERROR: Invalid input. Please type in a numerical value.");
}
}
/*
* When this gets called, it sends a message to the interpreter.
* The interpreter usually shows it on the command prompt (For Windows users)
* or the terminal (For *nix users).(Assuming it's open)
*/
private void calculate {
if (input % 2 0) {
System.out.println("Even");
} else {
System.out.println("Odd");
}
}
}
- The import statement imports the class from the package
A Java package is a mechanism for organizing Java classes into namespaces similar to the modules of Modula. Java packages can be stored in compressed files called JAR files, allowing classes to download faster as a group rather than one at a time...
.
- The
OddEven class declares a single private fieldIn computer science, data that has several parts can be divided into fields. Relational databases arrange data as sets of database records, also called rows. Each record consists of several fields; the fields of all records form the columns....
of type int named input. Every instance of the OddEven class has its own copy of the input field. The private declaration means that no other class can access (read or write) the input field.
-
OddEven is a public constructor. Constructors have the same name as the enclosing class they are declared in, and unlike a method, have no return typeIn computer programming, the return type defines and constrains the data type of value returned from a method or function...
. A constructor is used to initialize an objectIn computer science, an object is any entity that can be manipulated by the commands of a programming language, such as a value, variable, function, or data structure...
that is a newly created instance of the class.
- The
calculate method is declared without the static keyword. This means that the method is invoked using a specific instance of the OddEven class. (The referenceIn computer science, a reference is a value that enables a program to indirectly access a particular data item, such as a variable or a record, in the computer's memory or in some other storage device. The reference is said to refer to the data item, and accessing those data is called...
used to invoke the method is passed as an undeclared parameter of type OddEven named thisIn many object-oriented programming languages, this is a keyword that is used in instance methods to refer to the object on which they are working. C++ and languages which derive in style from it generally use this...
.) The method tests the expression input % 2 0 using the if keyword to see if the remainder of dividing the input field belonging to the instance of the class by two is zero. If this expression is true, then it prints Even; if this expression is false it prints Odd. (The input field can be equivalently accessed as this.input, which explicitly uses the undeclared this parameter.)
-
OddEven number = new OddEven; declares a local object referenceIn computer science, a reference is a value that enables a program to indirectly access a particular data item, such as a variable or a record, in the computer's memory or in some other storage device. The reference is said to refer to the data item, and accessing those data is called...
variable in the main method named number. This variable can hold a reference to an object of type OddEven. The declaration initializes number by first creating an instance of the OddEven class, using the new keyword and the OddEven constructor, and then assigning this instance to the variable.
- The statement
number.showDialog; calls the calculate method. The instance of OddEven object referenced by the number local variableIn computer science, a local variable is a variable that is given local scope. Such a variable is accessible only from the function or block in which it is declared. In programming languages with only two levels of visibility, local variables are contrasted with global variables...
is used to invoke the method and passed as the undeclared this parameter to the calculate method.
-
input = Integer.parseInt(JOptionPane.showInputDialog("Please Enter A Number")); is a statement that converts the type of String to the primitive data type int by using a utility function in the primitive wrapper classA primitive wrapper class in the Java programming language is one of eight classes provided in the package to provide object methods for the eight primitive types. All of the primitive wrapper classes in Java are immutable...
Integer.
Applet
Java applets are programs that are embedded in other applications, typically in a Web page displayed in a
Web browserA web browser is a software application for retrieving, presenting, and traversing information resources on the World Wide Web. An information resource is identified by a Uniform Resource Identifier and may be a web page, image, video, or other piece of content...
.
// Hello.java
import javax.swing.JApplet;
import java.awt.Graphics;
public class Hello extends JApplet {
public void paintComponent(Graphics g) {
g.drawString("Hello, world!", 65, 95);
}
}
The
import statements direct the
Java compilerA Java compiler is a compiler for the Java programming language. The most common form of output from a Java compiler is Java class files containing platform-neutral Java bytecode...
to include the
and
classes in the compilation. The import statement allows these classes to be referenced in the
source codeIn computer science, source code is text written using the format and syntax of the programming language that it is being written in. Such a language is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source...
using the
simple class name (i.e.
JApplet) instead of the
fully qualified class name (i.e.
javax.swing.JApplet).
The
Hello class
extends (subclasses) the
JApplet (Java Applet) class; the
JApplet class provides the framework for the host application to display and control the
lifecycleIn computer science, the object lifetime of an object in object-oriented programming is the time between an object's creation till the object is no longer used, and is destructed or freed.In object-oriented programming , the meaning of creating objects is far more subtle than simple...
of the applet. The
JApplet class is a JComponent (Java Graphical Component) which provides the applet with the capability to display a
graphical user interfaceIn computing, a graphical user interface is a type of user interface that allows users to interact with electronic devices with images rather than text commands. GUIs can be used in computers, hand-held devices such as MP3 players, portable media players or gaming devices, household appliances and...
(GUI) and respond to user
eventsIn computer programming, event-driven programming or event-based programming is a programming paradigm in which the flow of the program is determined by events—i.e., sensor outputs or user actions or messages from other programs or threads.Event-driven programming can also be defined as an...
.
The
Hello class overrides the
method (additionally indicated with the
annotationAn annotation, in the Java computer programming language, is a special form of syntactic metadata that can be added to Java source code. Classes, methods, variables, parameters and packages may be annotated...
, supported as of JDK 1.5,
Override) inherited from the superclass to provide the code to display the applet. The
paintComponent method is passed a
Graphics object that contains the graphic context used to display the applet. The
paintComponent method calls the graphic context
method to display the
"Hello, world!" string at a
pixelIn digital imaging, a pixel, or pel, is a single point in a raster image, or the smallest addressable screen element in a display device; it is the smallest unit of picture that can be represented or controlled....
offset of (
65, 95) from the upper-left corner in the applet's display.
"http://www.w3.org/TR/html4/strict.dtd">
Hello World Applet
An applet is placed in an
HTMLHyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....
document using the
HTML elementAn HTML element is an individual component of an HTML document. HTML documents are composed of a tree of HTML elements and other nodes, such as text nodes. Each element can have attributes specified. Elements can also have content, including other elements and text. HTML elements represent...
. The
applet tag has three attributes set:
code="Hello" specifies the name of the
JApplet class and
width="200" height="200" sets the pixel width and height of the applet. Applets may also be embedded in HTML using either the
object or
embed element, although support for these elements by Web browsers is inconsistent. However, the
applet tag is deprecated, so the
object tag is preferred where supported.
The host application, typically a Web browser, instantiates the
Hello applet and creates an for the applet. Once the applet has initialized itself, it is added to the AWT display hierarchy. The
paintComponent method is called by the AWT
event dispatching threadThe event dispatching thread is a background thread used in Java to process events from the Abstract Window Toolkit graphical user interface event queue. These events are primarily update events that cause user interface components to redraw themselves, or input events from input devices such as...
whenever the display needs the applet to draw itself.
Servlet
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-sideServer-side refers to operations that are performed by the server in a client–server relationship in computer networking.Typically, a server is a software program, such as a web server, that runs on a remote server, reachable from a user's local computer or workstation...
Java EE components that generate responses (typically
HTMLHyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....
pages) to requests (typically
HTTPThe Hypertext Transfer Protocol is a networking protocol for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web....
requests) from
clientsA client is an application or system that accesses a service made available by a server. The server is often on another computer system, in which case the client accesses the service by way of a network....
. A servlet can almost be thought of as an applet that runs on the server side—without a face.
// Hello.java
import java.io.*;
import javax.servlet.*;
public class Hello extends GenericServlet {
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
final PrintWriter pw = response.getWriter;
try {
pw.println("Hello, world!");
} finally {
pw.close;
}
}
}
The
import statements direct the Java compiler to include all of the public classes and
interfacesAn interface in the Java programming language is an abstract type that is used to specify an interface that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations...
from the
and
packages in the compilation.
The
Hello class
extends the
class; the
GenericServlet class provides the interface for the
serverIn the context of client-server architecture, a server is a computer program running to serve the requests of other programs, the "clients". Thus, the "server" performs some computational task on behalf of "clients"...
to forward requests to the servlet and control the servlet's lifecycle.
The
Hello class overrides the
method defined by the
interfaceAn interface in the Java programming language is an abstract type that is used to specify an interface that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations...
to provide the code for the service request handler. The
service method is passed a
object that contains the request from the client and a
object used to create the response returned to the client. The
service method declares that it
throws the
exceptionsException handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions, special conditions that change the normal flow of program execution....
and if a problem prevents it from responding to the request.
The
method in the response object is called to set the
MIMEMultipurpose Internet Mail Extensions is an Internet standard that extends the format of email to support:* Text in character sets other than ASCII* Non-text attachments* Message bodies with multiple parts...
content type of the returned data to
"text/html". The
method in the response returns a
object that is used to write the data that is sent to the client. The
method is called to write the
"Hello, world!" string to the response and then the
method is called to close the print writer, which causes the data that has been written to the stream to be returned to the client.
JavaServer Pages
JavaServer Pages (JSP) are
server-sideServer-side refers to operations that are performed by the server in a client–server relationship in computer networking.Typically, a server is a software program, such as a web server, that runs on a remote server, reachable from a user's local computer or workstation...
Java EE components that generate responses, typically
HTMLHyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....
pages, to
HTTPThe Hypertext Transfer Protocol is a networking protocol for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web....
requests from
clientsA client is an application or system that accesses a service made available by a server. The server is often on another computer system, in which case the client accesses the service by way of a network....
. JSPs embed Java code in an HTML page by using the special
delimiterA delimiter is a sequence of one or more characters used to specify the boundary between separate, independent regions in plain text or other data streams. An example of a delimiter is the comma character, which acts as a field delimiter in a sequence of comma-separated values.Delimiters represent...
s
<% 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.
Swing application
SwingSwing is the primary Java GUI widget toolkit. It is part of Oracle's Java Foundation Classes — an API for providing a graphical user interface for Java programs....
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 feelPluggable look and feel is a mechanism used in the Java Swing widget toolkit allowing to change the look and feel of the graphical user interface at runtime....
system of Swing. Clones of
WindowsMicrosoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
,
GTK+GTK+ is a cross-platform widget toolkit for creating graphical user interfaces. It is licensed under the terms of the GNU LGPL, allowing both free and proprietary software to use it. It is one of the most popular toolkits for the X Window System, along with Qt.The name GTK+ originates from GTK;...
and
MotifIn computing, Motif refers to both a graphical user interface specification and the widget toolkit for building applications that follow that specification under the X Window System on Unix and other POSIX-compliant systems. It emerged in the 1980s as Unix workstations were on the rise, as a...
are supplied by Sun. Apple also provides an
AquaAqua is the GUI and primary visual theme of Apple Inc.'s Mac OS X operating system. It is based around the theme of water, as its name suggests, with droplet-like elements and liberal use of translucency and reflection effects...
look and feel for
Mac OS XMac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...
. 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.
This example Swing application creates a single window with "Hello, world!" inside:
// Hello.java (Java SE 5)
import javax.swing.*;
public class Hello extends JFrame {
public Hello {
super("hello");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
add(new JLabel("Hello, world!"));
pack;
setVisible(true);
}
public static void main(String[] args) {
new Hello;
}
}
The first
import includes all of the public classes and interfaces from the
package.
The
Hello class
extends the
class; the
JFrame class implements a
windowIn computing, a window is a visual area containing some kind of user interface. It usually has a rectangular shape that can overlap with the area of other windows...
with a
title barIn computing, the title bar consists of that part of a window where the title of the window appears. Most graphical operating systems and window managers position the title bar at the top of the application window as a horizontal bar....
and a close control.
The
Hello constructor initializes the frame by first calling the superclass constructor, passing the parameter
"hello", which is used as the window's title. It then calls the
method inherited from
JFrame to set the default operation when the close control on the title bar is selected to
— this causes the
JFrame to be disposed of when the frame is closed (as opposed to merely hidden), which allows the JVM to exit and the program to terminate. Next, a
is created for the string
"Hello, world!" and the
method inherited from the superclass is called to add the label to the frame. The
method inherited from the superclass is called to size the window and lay out its contents.
The
main method is called by the JVM when the program starts. It
instantiatesIn computer science, an object is any entity that can be manipulated by the commands of a programming language, such as a value, variable, function, or data structure...
a new
Hello frame and causes it to be displayed by calling the
method inherited from the superclass with the boolean parameter
true. Once the frame is displayed, exiting the
main method does not cause the program to terminate because the AWT
event dispatching threadThe event dispatching thread is a background thread used in Java to process events from the Abstract Window Toolkit graphical user interface event queue. These events are primarily update events that cause user interface components to redraw themselves, or input events from input devices such as...
remains active until all of the Swing top-level windows have been disposed.
Generics
In 2004,
genericsIn a broad definition, generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters...
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 a large number of container classes, each containing almost identical code.
Criticism
A number of criticisms have been leveled at Java for various design choices in the language and platform. Such criticisms include the implementation of generics, the handling of unsigned numbers, the implementation of floating-point arithmetic, and security vulnerabilities.
Class libraries
- The Java Class Library
The Java Class Library is a set of dynamically loadable libraries that Java applications can call at run time. Because the Java Platform is not dependent on any specific operating system, applications cannot rely on any of the existing libraries...
are the compiled bytecodeBytecode, also known as p-code , is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software interpreter as well as being suitable for further compilation into machine code...
s of source codeIn computer science, source code is text written using the format and syntax of the programming language that it is being written in. Such a language is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source...
developed by the JRE implementor to support application development in Java. Examples of these libraries are:
- The core libraries, which include:
- Collection libraries
The Java collections framework is a set of classes and interfaces that implement commonly reusable collection data structures.Although it is a framework, it works in a manner of a library...
that implement data structureIn computer science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.Different kinds of data structures are suited to different kinds of applications, and some are highly specialized to specific tasks...
s such as lists, dictionariesIn computer science, an associative array is an abstract data type composed of a collection of pairs, such that each possible key appears at most once in the collection....
, treesA tree structure is a way of representing the hierarchical nature of a structure in a graphical form. It is named a "tree structure" because the classic representation resembles a tree, even though the chart is generally upside down compared to an actual tree, with the "root" at the top and the...
, setsIn computer science, a set is an abstract data structure that can store certain values, without any particular order, and no repeated values. It is a computer implementation of the mathematical concept of a finite set...
, queues and double-ended queue, or stacksIn computer science, a stack is a last in, first out abstract data type and linear data structure. A stack can have any abstract data type as an element, but is characterized by only three fundamental operations: push, pop and stack top. The push operation adds a new item to the top of the stack,...
- XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....
Processing (Parsing, Transforming, Validating) libraries
- Security
- Internationalization and localization
In computing, internationalization and localization are means of adapting computer software to different languages, regional differences and technical requirements of a target market...
libraries
- The integration libraries, which allow the application writer to communicate with external systems. These libraries include:
- The Java Database Connectivity
Java DataBase Connectivity, commonly referred to as JDBC, is an API for the Java programming language that defines how a client may access a database. It provides methods for querying and updating data in a database. JDBC is oriented towards relational databases...
(JDBC) APIAn application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...
for database access
- Java Naming and Directory Interface
The Java Naming and Directory Interface is a Java API for a directory service that allows Java software clients to discover and look up data and objects via a name. Like all Java APIs that interface with host systems, JNDI is independent of the underlying implementation...
(JNDI) for lookup and discovery
- RMI
The Java Remote Method Invocation Application Programming Interface , or Java RMI, is a Java application programming interface that performs the object-oriented equivalent of remote procedure calls ....
and CORBAThe Common Object Request Broker Architecture is a standard defined by the Object Management Group that enables software components written in multiple computer languages and running on multiple computers to work together .- Overview:CORBA enables separate pieces of software written in different...
for distributed application development
- JMX
Java Management Extensions is a Java technology that supplies tools for managing and monitoring applications, system objects, devices and service oriented networks. Those resources are represented by objects called MBeans...
for managing and monitoring applications
- User interface
The user interface, in the industrial design field of human–machine interaction, is the space where interaction between humans and machines occurs. The goal of interaction between a human and a machine at the user interface is effective operation and control of the machine, and feedback from the...
libraries, which include:
- The (heavyweight, or native
The term native mode or native code is used in computing in two related senses.*to describe something running on a computer natively or in native mode meaning that it is running without any external support as contrasted to running in emulation....
) Abstract Window ToolkitThe Abstract Window Toolkit is Java's original platform-independent windowing, graphics, and user-interface widget toolkit. The AWT is now part of the Java Foundation Classes — the standard API for providing a graphical user interface for a Java program.AWT is also the GUI toolkit for a...
(AWT), which provides GUIIn computing, a graphical user interface is a type of user interface that allows users to interact with electronic devices with images rather than text commands. GUIs can be used in computers, hand-held devices such as MP3 players, portable media players or gaming devices, household appliances and...
components, the means for laying out those components and the means for handling events from those components
- The (lightweight) Swing
Swing is the primary Java GUI widget toolkit. It is part of Oracle's Java Foundation Classes — an API for providing a graphical user interface for Java programs....
libraries, which are built on AWT but provide (non-native) implementations of the AWT widgetry
- APIs for audio capture, processing, and playback
- A platform dependent implementation of Java Virtual Machine
A Java virtual machine is a virtual machine capable of executing Java bytecode. It is the code execution component of the Java software platform. Sun Microsystems stated that there are over 4.5 billion JVM-enabled devices.-Overview:...
(JVM) that is the means by which the byte codes of the Java libraries and third party applications are executed
- Plugins, which enable applets
A Java applet is an applet delivered to users in the form of Java bytecode. Java applets can run in a Web browser using a Java Virtual Machine , or in Sun's AppletViewer, a stand-alone tool for testing applets...
to be run in Web browserA web browser is a software application for retrieving, presenting, and traversing information resources on the World Wide Web. An information resource is identified by a Uniform Resource Identifier and may be a web page, image, video, or other piece of content...
s
- Java Web Start
In computing, Java Web Start is a framework developed by Sun Microsystems that allows users to start application software for the Java Platform directly from the Internet using a web browser....
, which allows Java applications to be efficiently distributed to end-userEconomics and commerce define an end user as the person who uses a product. The end user or consumer may differ from the person who purchases the product...
s across the InternetThe Internet is a global system of interconnected computer networks that use the standard Internet protocol suite to serve billions of users worldwide...
- Licensing and documentation.
Documentation
JavadocJavadoc is a documentation generator from Sun Microsystems for generating API documentation in HTML format from Java source code.The "doc comments" format used by Javadoc is the de facto industry standard for documenting Java classes. Some IDEs, such as Netbeans and Eclipse automatically generate...
is a comprehensive documentation system, created by
Sun MicrosystemsSun Microsystems, Inc. was a company that sold :computers, computer components, :computer software, and :information technology services. Sun was founded on February 24, 1982...
, used by many Java developers. It provides developers with an organized system for documenting their code. Javadoc comments have an extra asterisk at the beginning, i.e. the tags are /** and */, whereas the normal multi-line comment tags comments in Java and
CC is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
are set off with /* and */.
Editions
Sun has defined and supports four editions of Java targeting different application environments and segmented many of its
APIsAn application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...
so that they belong to one of the platforms. The platforms are:
- Java Card
Java Card refers to a technology that allows Java-dd applications to be run securely on smart cards and similar small memory footprint devices. Java Card is the tiniest of Java targeted for embedded devices. Java Card gives the user ability to program the device and make them application...
for smartcards.
- Java Platform, Micro Edition
Java Platform, Micro Edition, or Java ME, is a Java platform designed for embedded systems . Target devices range from industrial controls to mobile phones and set-top boxes...
(Java ME) — targeting environments with limited resources.
- Java Platform, Standard Edition
Java Platform, Standard Edition or Java SE is a widely used platform for programming in the Java language. It is the Java Platform used to deploy portable applications for general use...
(Java SE) — targeting workstation environments.
- Java Platform, Enterprise Edition
Java Platform, Enterprise Edition or Java EE is widely used platform for server programming in the Java programming language. The Java platform differs from the Java Standard Edition Platform in that it adds libraries which provide functionality to deploy fault-tolerant, distributed, multi-tier...
(Java EE) — targeting large distributed enterprise or Internet environments.
The
classesIn object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...
in the Java APIs are organized into separate groups called
packagesA Java package is a mechanism for organizing Java classes into namespaces similar to the modules of Modula. Java packages can be stored in compressed files called JAR files, allowing classes to download faster as a group rather than one at a time...
. Each package contains a set of related
interfacesAn interface in the Java programming language is an abstract type that is used to specify an interface that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations...
, classes and
exceptionsException handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions, special conditions that change the normal flow of program execution....
. Refer to the separate platforms for a description of the packages available.
The set of APIs is controlled by Sun Microsystems in cooperation with others through the
Java Community ProcessThe Java Community Process or JCP, established in 1998, is a formalized process that allows interested parties to get involved in the definition of future versions and features of the Java platform....
program. Companies or individuals participating in this process can influence the design and development of the APIs. This process has been a subject of controversy.
Sun also provided an edition called
PersonalJavaPersonalJava was a Java edition for mobile and embedded systems based on Java 1.1.8 . It has been superseded by the CDC's Personal Profile which is not yet widely deployed.-External links:*...
that has been superseded by later, standards-based Java ME configuration-profile pairings.
See also
- Comparison of programming languages
Programming languages are used for controlling the behavior of a machine . Like natural languages, programming languages conform to rules for syntax and semantics.There are thousands of programming languages and new ones are created every year...
- Comparison of Java and C++
This is a comparison of the Java programming language with the C++ programming language.- Design aims :The differences between the C++ and Java programming languages can be traced to their heritage, as they have different design goals....
- Comparison of Java and C#
- C#
- JavaOne
JavaOne is an annual conference inaugurated in 1996 by Sun Microsystems to discuss Java technologies, primarily among Java developers. JavaOne is held in San Francisco, California typically running from Monday to Thursday. Technical sessions on a variety of topics are held during the day. In the...
- Javapedia
The Javapedia project was launched in June 2003 during the JavaOne developer conference. It is part of . The website is promoted by Sun Microsystems as the central meeting place for the Java community....
- List of Java virtual machines
- List of Java APIs
- List of JVM languages
- Java version history
The Java language has undergone several changes since JDK 1.0 as well as numerous additions of classes and packages to the standard library. Since J2SE 1.4, the evolution of the Java language has been governed by the Java Community Process , which uses Java Specification Requests to propose and...
External links
- java.com - Java for end-users
- Oracle's Developer Resources for Java Technology.
- Oracle's Beginner's tutorial for Java SE Programming
- A Brief History of the Green Project
- Michael O'Connell: Java: The Inside Story, SunWord, July 1995.
- Patrick Naughton: Java Was Strongly Influenced by Objective-C (no date).
- David Bank: The Java Saga, Wired Issue 3.12 (December 1995).
- Shahrooz Feizabadi: A history of Java in: Marc Abrams, ed., World Wide Web – Beyond the Basics, Prentice Hall, 1998.
- Patrick Naughton: The Long Strange Trip to Java, March 18, 1996.
- Open University (UK): M254 Java Everywhere (free open content documents).
- is-research GmbH: List of programming languages for a Java Virtual Machine.
- How Java's Floating-Point Hurts Everyone Everywhere, by W. Kahan and Joseph D. Darcy, University of California, Berkeley
The University of California, Berkeley , is a teaching and research university established in 1868 and located in Berkeley, California, USA...
.