HOME

TheInfoList




Java is a
high-level High-level and low-level, as technical terms, are used to classify, describe and point to specific Objective (goal), goals of a systematic operation; and are applied in a wide range of contexts, such as, for instance, in domains as widely varied as ...
, class-based,
object-oriented Object-oriented programming (OOP) is a programming paradigm Program, programme, programmer, or programming may refer to: Business and management * Program management, the process of managing several related projects * Time management * P ...
programming language A programming language is a formal language In logic, mathematics, computer science, and linguistics, a formal language consists of string (computer science), words whose symbol (formal), letters are taken from an alphabet (computer science) ...

programming language
that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let
programmer A computer programmer, sometimes called a software developer, a programmer or more recently a coder (especially in more informal contexts), is a person who creates computer software Software is a collection of Instruction (computer science) ...

programmer
s ''write once, run anywhere'' (WORA), meaning that
compiled In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily ...

compiled
Java code can run on all platforms that support Java without the need for recompilation. Java applications are typically compiled to
bytecode Bytecode, also termed portable code or p-code, is a form of instruction set In computer science, an instruction set architecture (ISA), also called computer architecture, is an abstract model of a computer. A device that executes instructions ...

bytecode
that can run on any Java virtual machine (JVM) regardless of the underlying
computer architecture In computer engineering, computer architecture is a set of rules and methods that describe the functionality, organization, and implementation of computer systems. The architecture of a system refers to its structure in terms of separately specifi ...
. The
syntax In linguistics Linguistics is the scientific study of language, meaning that it is a comprehensive, systematic, objective, and precise study of language. Linguistics encompasses the analysis of every aspect of language, as well as the ...
of Java is similar to C and
C++ C++ () is a general-purpose programming language In computer software, a general-purpose programming language is a programming language dedicated to a general-purpose, designed to be used for writing software in a wide variety of application ...

C++
, but has fewer low-level facilities than either of them. The Java runtime provides dynamic capabilities (such as
reflectionReflection or reflexion may refer to: Philosophy * Self-reflection Science * Reflection (physics), a common wave phenomenon ** Specular reflection, reflection from a smooth surface *** Mirror image, a reflection in a mirror or in water ** Signal r ...
and runtime code modification) that are typically not available in traditional compiled languages. , Java was one of the most popular programming languages in use according to
GitHub __FORCETOC__ GitHub, Inc. is a provider of Internet hosting service, Internet hosting for software development and version control using Git. It offers the distributed version control and source code management (SCM) functionality of Git, plus ...

GitHub
, particularly for client–server
web application A web application (or web app) is application software that runs on a web server, unlike computer-based software programs that are run locally on the operating system (OS) of the device. Web applications are accessed by the user through a web bro ...
s, with a reported 9 million developers. Java was originally developed by
James Gosling James Arthur Gosling, often referred to as "Dr. Java," Order of Canada, OC (born May 19, 1955) is a Canadian computer scientist, best known as the founder and lead designer behind the Java (programming language), Java programming language. Gosli ...
at
Sun Microsystems Sun Microsystems, Inc. (Sun for short) was an American technology company that sold computer A computer is a machine that can be programmed to Execution (computing), carry out sequences of arithmetic or logical operations automatically. M ...
( which has since been acquired by Oracle) and released in 1995 as a core component of Sun Microsystems'
Java platform Java ( id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 147.7 million people, Java is the world's List of ...
. The original and
reference implementation In the software development process In software engineering, a software development process is the process of dividing software development work into smaller, parallel or sequential steps or subprocesses to improve Software design, design, So ...
Java
compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily ...

compiler
s, virtual machines, and class libraries were originally released by Sun under
proprietary license Proprietary software, also known as non-free software or closed-source software, is computer software for which the software's publisher or another person reserves some rights from licenses to use, modify, share modifications, or share the softwar ...
s. As of May 2007, in compliance with the specifications of the
Java Community Process The Java Community Process (JCP), established in 1998, is a formalized mechanism that allows interested parties to develop standard technical specifications for Java technology. Anyone can become a JCP Member by filling a form available at thJCP w ...
, Sun had relicensed most of its Java technologies under the GPL-2.0-only license. Oracle offers its own HotSpot Java Virtual Machine, however the official
reference implementation In the software development process In software engineering, a software development process is the process of dividing software development work into smaller, parallel or sequential steps or subprocesses to improve Software design, design, So ...
is the
OpenJDK OpenJDK (Open Java Development Kit) is a free and open-source Free and open-source software (FOSS) is software that is both free software and open-source software where anyone is free software license, freely licensed to use, copy, study, and ...
JVM which is free open-source software and used by most developers and is the default JVM for almost all Linux distributions. , Java 17 is the latest version. Java 8, 11 and 17 are the current
long-term support Long-term support (LTS) is a product lifecycle management policy in which a stable release of computer software is Software maintenance, maintained for a longer period of time than the standard edition. The term is typically reserved for open-source ...
(LTS) versions.
Oracle An oracle is a person or agency Agency may refer to: * a governmental or other institution Institutions, according to Samuel P. Huntington, are "stable, valued, recurring patterns of behavior". Institutions can refer to mechanisms which go ...
released the last zero-cost public update for the
legacy In law, a legacy is something held and transferred to someone as their inheritance Inheritance is the practice of passing on private property Private property is a legal designation for the ownership of property by non-governmental legal ...
version
Java 8 The Java language Java is a class-based, object-oriented programming language A programming language is a formal language comprising a Instruction set architecture, set of instructions that produce various kinds of Input/output, output. ...
LTS in January 2019 for commercial use, although it will otherwise still support Java 8 with public updates for personal use indefinitely. Other vendors have begun to offer zero-cost builds of OpenJDK 8 and 11 that are still receiving security and other upgrades. Oracle (and others) highly recommend uninstalling outdated and unsupported versions of Java, because of serious risks due to unresolved security issues. Oracle advises its users to immediately transition to a supported version, such as one of the LTS versions (8, 11, 17).


History

James Gosling James Arthur Gosling, often referred to as "Dr. Java," Order of Canada, OC (born May 19, 1955) is a Canadian computer scientist, best known as the founder and lead designer behind the Java (programming language), Java programming language. Gosli ...
, Mike Sheridan, and
Patrick Naughton Patrick Naughton is an American software developer, one of the creators of the Java (programming language), Java programming language. Career Early career In 1983, Naughton co-wrote a MacPaint Clone (computing), clone, ''Painter's Apprentice' ...
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 ''
Oak An oak is a tree In botany, a tree is a perennial plant with an elongated Plant stem, stem, or trunk (botany), trunk, supporting branches and leaves in most species. In some usages, the definition of a tree may be narrower, including on ...
'' after an
oak An oak is a tree In botany, a tree is a perennial plant with an elongated Plant stem, stem, or trunk (botany), trunk, supporting branches and leaves in most species. In some usages, the definition of a tree may be narrower, including on ...

oak
tree that stood outside Gosling's office. Later the project went by the name ''Green'' and was finally renamed ''Java'', from
Java coffee Indonesia Indonesia ( ), officially the Republic of Indonesia ( id, Republik Indonesia, links=yes ), is a country in Southeast Asia Southeast Asia, also spelled South East Asia and South-East Asia, and also known as Southeastern Asi ...
, a type of coffee from
Indonesia Indonesia ( ), officially the Republic of Indonesia ( id, Republik Indonesia, links=yes ), is a country in Southeast Asia Southeast Asia, also spelled South East Asia and South-East Asia, and also known as Southeastern Asia or SEA, is t ...

Indonesia
. Gosling designed Java with a C/
C++ C++ () is a general-purpose programming language In computer software, a general-purpose programming language is a programming language dedicated to a general-purpose, designed to be used for writing software in a wide variety of application ...

C++
-style syntax that system and application programmers would find familiar. Sun Microsystems released the first public implementation as Java 1.0 in 1996. It promised
write once, run anywhereWrite once, run anywhere (WORA), or sometimes Write once, run everywhere (WORE), was a 1995 slogan created by Sun Microsystems Sun Microsystems, Inc. (Sun for short) is a defunct American company that sold computers, computer components, software ...
(WORA) functionality, providing no-cost run-times on popular platforms. Fairly secure and featuring configurable security, it allowed network- and file-access restrictions. Major
web browser A web browser (commonly referred to as a browser) is application software for accessing the World Wide Web. When a User (computing), user requests a web page from a particular website, the web browser retrieves the necessary content from a web ...

web browser
s soon incorporated the ability to run
Java applet Java applets were small applications written in the Java Java ( id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a ...

Java applet
s within web pages, and Java quickly became popular. The Java 1.0 compiler was re-written in Java by
Arthur van Hoff Arthur van Hoff (born 16 February 1963) is a Dutch computer scientist and businessman. Biography After studying computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of ...

Arthur van Hoff
to comply strictly with the Java 1.0 language specification. With the advent of Java 2 (released initially as J2SE 1.2 in December 1998 1999), new versions had multiple configurations built for different types of platforms.
J2EE Jakarta EE, formerly Java Platform, Enterprise Edition (Java EE) and Java 2 Platform, Enterprise Edition (J2EE), is a set of specifications, extending Java SE with specifications for enterprise features such as distributed computing and web servic ...
included technologies and APIs for enterprise applications typically run in server environments, while J2ME featured APIs optimized for mobile applications. The desktop version was renamed J2SE. In 2006, for marketing purposes, Sun renamed new J2 versions as ''
Java EE Jakarta EE, formerly Java Platform, Enterprise Edition (Java EE) and Java 2 Platform, Enterprise Edition (J2EE), is a set of specifications, extending Java SE Java Platform, Standard Edition (Java SE) is a computing platform A computing platfo ...
'', ''
Java ME Java Platform, Micro Edition or Java ME is a computing platform A computing platform or digital platform is an environment in which a piece of software Software is a collection of instructions that tell a computer A computer is a ...
'', and ''
Java SE Java Platform, Standard Edition (Java SE) is a computing platform A computing platform or digital platform is an environment in which a piece of software Software is a collection of instructions that tell a computer A computer is a ma ...
'', respectively. In 1997, Sun Microsystems approached the
ISO/IEC JTC 1 ISO/IEC JTC 1, entitled "Information technology", is a joint technical committee (JTC) of the International Organization for Standardization The International Organization for Standardization (ISO ) is an international standard An internat ...
standards body and later the
Ecma International Ecma International () is a Nonprofit organization, nonprofit standards organization for information and communication systems. It acquired its current name in 1994, when the European Computer Manufacturers Association (ECMA) changed its name to ...
to formalize Java, but it soon withdrew from the process. Java remains a ''de facto'' standard, controlled through the
Java Community Process The Java Community Process (JCP), established in 1998, is a formalized mechanism that allows interested parties to develop standard technical specifications for Java technology. Anyone can become a JCP Member by filling a form available at thJCP w ...
. At one time, Sun made most of its Java implementations available without charge, despite their
proprietary software Proprietary software, also known as non-free software or closed-source software, is computer software for which the software's publisher or another person reserves some rights from licenses to use, modify, share modifications, or share the softwa ...
status. Sun generated revenue from Java through the selling of licenses for specialized products such as the Java Enterprise System. On November 13, 2006, Sun released much of its Java virtual machine (JVM) as
free and open-source software Free and open-source software (FOSS) is software Software is a collection of Instruction (computer science), instructions that tell a computer how to work. This is in contrast to Computer hardware, hardware, from which the system is built ...
(FOSS), under the terms of the GPL-2.0-only license. On May 8, 2007, Sun finished the process, making all of its JVM's core code available under
free software Free software (or libre software) is computer software distributed under terms that allow users to run the software for any purpose as well as to study, change, and distribute it and any adapted versions. Free software is a matter of liberty ...

free software
/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 regard to Java was as an ''evangelist''. Following
Oracle Corporation Oracle Corporation is an American multinational Multinational may refer to: * Multinational corporation, a corporate organization operating in multiple countries * Multinational force, a military body from multiple countries * Multinational ...
's acquisition of Sun Microsystems in 2009–10, Oracle has described itself as the steward of Java technology with a relentless commitment to fostering a community of participation and transparency. This did not prevent Oracle from filing a lawsuit against Google shortly after that for using Java inside the
Android SDK Android software development is the process by which applications are created for devices running the Android operating system Android is a mobile operating system A mobile operating system is an operating system An operating system (O ...
(see the ''
Android Android may refer to: Science and technology * Android (robot), a humanoid robot or synthetic organism designed to imitate a human * Android (operating system), Google's mobile operating system ** Android (operating system)#Mascot, Unnamed Androi ...
'' section). On April 2, 2010, James Gosling resigned from
Oracle An oracle is a person or agency Agency may refer to: * a governmental or other institution Institutions, according to Samuel P. Huntington, are "stable, valued, recurring patterns of behavior". Institutions can refer to mechanisms which go ...
. In January 2016, Oracle announced that Java run-time environments based on JDK 9 will discontinue the browser plugin. Java software runs on everything from laptops to
data center A data center (American English American English (AmE, AE, AmEng, USEng, en-US), sometimes called United States English or U.S. English, is the set of varieties of the English language native to the United States. Currently, American Eng ...
s,
game consoles A video game console is an electronic device that output Output may refer to: * The information produced by a computer, see * An output state of a system, see * , the amount of goods and services produced ** in economics, the value of net ...
to scientific
supercomputer upright=1.5, Computing power of the top 1 supercomputer each year, measured in FLOPS A supercomputer is a computer with a high level of performance as compared to a general-purpose computer. The performance of a supercomputer is commonly mea ...

supercomputer
s.


Principles

There were five primary goals in the creation of the Java language:
# It must be simple,
object-oriented Object-oriented programming (OOP) is a programming paradigm Programming paradigms are a way to classify programming languages based on their features. Languages can be classified into multiple paradigms. Some paradigms are concerned mai ...
, and familiar. # It must be robust and secure. # It must be architecture-neutral and portable. # It must execute with high performance. # It must be interpreted,
thread Thread or threads may refer to: Objects * Thread (yarn), a kind of thin yarn used for sewing ** Thread (unit of measurement), a cotton yarn measure * Screw thread, a helical ridge on a cylindrical fastener Arts and entertainment * Thread (film), ...
ed, and
dynamic Dynamics (from Greek Greek may refer to: Greece Anything of, from, or related to Greece Greece ( el, Ελλάδα, , ), officially the Hellenic Republic, is a country located in Southeast Europe. Its population is approximately 10.7 million ...
.


Versions

, Java 8, 11 and 17 are supported as
Long-Term Support Long-term support (LTS) is a product lifecycle management policy in which a stable release of computer software is Software maintenance, maintained for a longer period of time than the standard edition. The term is typically reserved for open-source ...
(LTS) versions. Major release versions of Java, along with their release dates:


Editions

Sun has defined and supports four editions of Java targeting different application environments and segmented many of its
APIs Apis or APIS may refer to: *Apis (deity) In ancient Egyptian religion Ancient Egyptian religion was a complex system of polytheistic beliefs and rituals that formed an integral part of ancient Egypt Ancient Egypt was a civilization ...
so that they belong to one of the platforms. The platforms are: *
Java Card Java Card is a software technology that allows Java Java ( id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population ...
for smart-cards. *
Java Platform, Micro Edition Java Platform, Micro Edition or Java ME is a computing platform A computing platform or digital platform is an environment in which a piece of software Software is a collection of instructions that tell a computer A computer is a ...
(Java ME) – targeting environments with limited resources. *
Java Platform, Standard Edition Java Platform, Standard Edition (Java SE) is a computing platform A computing platform or digital platform is an environment in which a piece of software is executed. It may be the Computer hardware, hardware or the operating system (OS), even ...
(Java SE) – targeting workstation environments. *
Java Platform, Enterprise Edition Jakarta EE, formerly Java Platform, Enterprise Edition (Java EE) and Java 2 Platform, Enterprise Edition (J2EE), is a set of specifications, extending Java SE Java Platform, Standard Edition (Java SE) is a computing platform A computing platfo ...
(Java EE) – targeting large distributed enterprise or Internet environments. The
classes Class or The Class may refer to: Common uses not otherwise categorized * Class (biology), a taxonomic rank * Class (knowledge representation), a collection of individuals or objects * Class (philosophy), an analytical concept used differently f ...
in the Java APIs are organized into separate groups called
packages Package may refer to: Enclosures * Packaging and labeling Packaging is the art Art is a diverse range of (products of) human activities involving creative imagination to express technical proficiency, beauty, emotional power, or concep ...
. Each package contains a set of related
interfaces Interface or interfacing may refer to: Academic journals * Interface (journal), ''Interface'' (journal), by the Electrochemical Society * ''Interface, Journal of Applied Linguistics'', now merged with ''ITL International Journal of Applied Lin ...
, classes, subpackages and exceptions. Sun also provided an edition called Personal Java that has been superseded by later, standards-based Java ME configuration-profile pairings.


Execution system


Java JVM and bytecode

One design goal of Java is portability, which means that programs written for the Java platform must run similarly on any combination of hardware and operating system with adequate run time support. This is achieved by compiling the Java language code to an intermediate representation called
Java bytecode Java bytecode is the bytecode Bytecode, also termed portable code or p-code, is a form of instruction set In computer science, an instruction set architecture (ISA), also called computer architecture, is an abstract model of a computer. A dev ...

Java bytecode
, instead of directly to architecture-specific
machine code In computer programming Computer programming is the process of designing and building an executable In computing, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, c ...
. Java bytecode instructions are analogous to machine code, but they are intended to be executed by a
virtual machine In computing, a virtual machine (VM) is the virtualization In computing, virtualization or virtualisation (sometimes abbreviated v12n, a numeronym) is the act of creating a virtual (rather than actual) version of something, including virtual co ...
(VM) written specifically for the host hardware.
End-user In product development, an end user (sometimes end-user) is a person who ultimately uses or is intended to ultimately use a product. The end user stands in contrast to users who support or maintain the product, such as sysop A sysop (; an abbre ...
s commonly use a Java Runtime Environment (JRE) installed on their device for standalone Java applications or a web browser for
Java applet Java applets were small applications written in the Java Java ( id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a ...

Java applet
s. Standard libraries provide a generic way to access host-specific features such as graphics, threading, and networking. The use of universal bytecode makes porting simple. However, the overhead of
interpreting Interpreting is a Translation studies, translational activity in which one produces a first and final translation on the basis of a one-time exposure to an expression in a Source language (translation), source language. The most common two modes ...
bytecode into machine instructions made interpreted programs almost always run more slowly than native
executable In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and ...
s.
Just-in-time#REDIRECT Just in Time {{Redirect category shell, 1= {{R from other capitalisation {{R from ambiguous page ...
(JIT) compilers that compile byte-codes to machine code during runtime were introduced from an early stage. Java's Hotspot compiler is actually two compilers in one; and with
GraalVM GraalVM is a Java VM and JDK based on HotSpot/OpenJDK OpenJDK (Open Java Development Kit) is a free and open-source software, free and open-source implementation of the Java Platform, Standard Edition (Java SE). It is the result of an effort ...
(included in e.g. Java 11, but removed as of Java 16) allowing tiered compilation. Java itself is platform-independent and is adapted to the particular platform it is to run on by a Java virtual machine (JVM) for it, which translates the
Java bytecode Java bytecode is the bytecode Bytecode, also termed portable code or p-code, is a form of instruction set In computer science, an instruction set architecture (ISA), also called computer architecture, is an abstract model of a computer. A dev ...

Java bytecode
into the platform's machine language.


Performance

Programs written in Java have a reputation for being slower and requiring more memory than those written in
C++ C++ () is a general-purpose programming language In computer software, a general-purpose programming language is a programming language dedicated to a general-purpose, designed to be used for writing software in a wide variety of application ...

C++
. However, Java programs' execution speed improved significantly with the introduction of
just-in-time compilation In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and soft ...
in 1997/1998 for Java 1.1, the addition of language features supporting better code analysis (such as inner classes, the StringBuilder class, optional assertions, etc.), and optimizations in the Java virtual machine, such as HotSpot becoming Sun's default JVM in 2000. With Java 1.5, the performance was improved with the addition of the java.util.concurrent package, including lock-free implementations of the ConcurrentMaps and other multi-core collections, and it was improved further with Java 1.6.


Non-JVM

Some platforms offer direct hardware support for Java; there are micro controllers that can run Java bytecode in hardware instead of a software Java virtual machine, and some
ARM In human anatomy The human body is the structure of a human being Humans (''Homo sapiens'') are the most abundant and widespread species In biology, a species is the basic unit of biological classification, classification and ...
-based processors could have hardware support for executing Java bytecode through their
Jazelle Jazelle DBX (direct bytecode execution) is an extension that allows some ARM In human anatomy, the arm is the part of the upper limb The upper Limb (anatomy), limbs or upper extremities are the forelimbs of an upright posture, upright-postured t ...
option, though support has mostly been dropped in current implementations of ARM.


Automatic memory management

Java uses an automatic garbage collector to manage memory in the object lifecycle. The programmer determines when objects are created, and the Java runtime is responsible for recovering the memory once objects are no longer in use. Once no references to an object remain, the
unreachable memory In computer science, unreachable memory is a block of dynamic memory, memory Dynamic memory allocation, allocated dynamically where the computer program, program that allocated the memory no longer has any reachable pointer (computer programming), ...
becomes eligible to be freed automatically by the garbage collector. Something similar to a
memory leak In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of , , ...
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 non-existent object are called, a
null pointer In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and softwar ...
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 stack or explicitly allocated and deallocated from the
heap Heap or HEAP may refer to: Computing and mathematics * Heap (data structure), a data structure commonly used to implement a priority queue * Heap (mathematics), a generalization of a group * Heap (programming) (or free store), an area of memory for ...
. In the latter case, the responsibility of managing memory resides with the programmer. If the program does not deallocate an object, a
memory leak In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of , , ...
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 or crash. This can be partially remedied by the use of
smart pointer In computer science, a smart pointer is an abstract data type that simulates a Pointer (computer programming), pointer while providing added features, such as automatic memory management or bounds checking. Such features are intended to reduce bug ...
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 can be arithmetically manipulated (e.g. by adding or subtracting an offset). This allows the garbage collector to relocate referenced objects and ensures type safety and security. As in C++ and some other object-oriented languages, variables of Java's
primitive data type In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Algori ...
s are either stored directly in fields (for objects) or on the stack (for methods) rather than on the heap, as is commonly true for non-primitive data types (but see
escape analysis In compiler optimization In computing, an optimizing compiler is a compiler that tries to minimize or maximize some attributes of an executable computer program. Common requirements are to minimize a computer program, program's execution time, memo ...
). This was a conscious decision by Java's designers for performance reasons. Java contains multiple types of garbage collectors. Since Java 9, HotSpot uses the Garbage First Garbage Collector (G1GC) as the default. However, there are also several other garbage collectors that can be used to manage the heap. For most applications in Java, G1GC is sufficient. Previously, th
Parallel Garbage Collector
was used in Java 8. Having solved the memory management problem does not relieve the programmer of the burden of handling properly other kinds of resources, like network or database connections, file handles, etc., especially in the presence of exceptions.


Syntax

The syntax of Java is largely influenced by
C++ C++ () is a general-purpose programming language In computer software, a general-purpose programming language is a programming language dedicated to a general-purpose, designed to be used for writing software in a wide variety of application ...

C++
and C. Unlike C++, which combines the syntax for structured, generic, and object-oriented programming, Java was built almost exclusively as an object-oriented language. All code is written inside classes, and every data item is an object, with the exception of the primitive data types, (i.e. integers, floating-point numbers, boolean values, and characters), which are not objects for performance reasons. Java reuses some popular aspects of C++ (such as the method). Unlike C++, Java does not support
operator overloading In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a particular task. Programming involves tasks such as analysis, gen ...
or
multiple inheritance Multiple inheritance is a feature of some object-oriented Object-oriented programming (OOP) is a programming paradigm Program, programme, programmer, or programming may refer to: Business and management * Program management, the process ...

multiple inheritance
for classes, though multiple inheritance is supported for
interface Interface or interfacing may refer to: Academic journals * Interface (journal), ''Interface'' (journal), by the Electrochemical Society * ''Interface, Journal of Applied Linguistics'', now merged with ''ITL International Journal of Applied Lin ...
s. Java uses comments similar to those of C++. There are three different styles of comments: a single line style marked with two slashes (//), a multiple line style opened with /* and closed with */, and the
Javadoc Javadoc (originally cased JavaDoc) is a documentation generator A documentation generator is a programming tool A programming tool or software development tool is a computer program A computer program is a collection of instructions that can b ...
commenting style opened with /** and closed with */. The Javadoc style of commenting allows the user to run the Javadoc executable to create documentation for the program and can be read by some
integrated development environment An integrated development environment (IDE) is a software application Application software (app for short) is computing software designed to carry out a specific task other than one relating to the operation of the computer itself, typically ...
s (IDEs) such as
Eclipse ECLiPSe is a software system for the development and deployment of Constraint Programming Constraint programming (CP) is a paradigm for solving combinatorial Combinatorics is an area of mathematics Mathematics (from Ancient Greek, Gr ...

Eclipse
to allow developers to access documentation within the IDE.


Hello world example

The traditional
Hello world program ''Hello'' is a salutation or greeting habits, greeting in the English language. It is first attested in writing from 1826. Early uses ''Hello'', with that spelling, was used in publications in the US as early as the 18 October 1826 edition of ...
can be written in Java as: public class HelloWorldApp All 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 compiler A Java compiler is a compiler for the programming language Java (programming language), Java. The most common form of output from a Java compiler is Java class files containing platform-neutral Java bytecode, but there are also compilers that outp ...
, producing a file with the .class suffix (HelloWorldApp.class, in this case). Only then can it be executed or launched. The Java source file may only contain one public class, but it can contain multiple classes with a non-public access modifier and any number of public
inner classIn object-oriented programming Object-oriented programming (OOP) is a programming paradigm based on the concept of "Object (computer science), objects", which can contain data and code: data in the form of Field (computer science), fields (often ...
es. When the source file contains multiple classes, it is necessary to make one class (introduced by the class keyword) public (preceded by the public keyword) and name the source file with that public class name. 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, 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. This is called an access level modifier. Other access level modifiers include the keywords private (a method that can only be accessed in the same class) and protected (which allows code from the same package to access). If a piece of code attempts to access private methods or protected methods, the JVM will throw a SecurityException The keyword static in front of a method indicates a
static method A method in object-oriented programming Object-oriented programming (OOP) is a programming paradigm Programming paradigms are a way to classify programming languages based on their features. Languages can be classified into multiple pa ...
, 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. Methods that are not designated static are instance methods and require a specific instance of a class to operate. 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 JavaBeans Jakarta Enterprise Beans (EJB; formerly Enterprise JavaBeans) is one of several Java APIs for modular construction of enterprise softwareEnterprise software, also known as enterprise application software (EAS), is computer software Software i ...
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
array ARRAY, also known as ARRAY Now, is an independent distribution company launched by film maker and former publicist Ava DuVernay Ava Marie DuVernay (; born August 24, 1972) is an American filmmaker. She won the directing award in the U.S. dram ...
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 arguments, 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 (to the args parameter which is still an array of String objects), but it 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
JAR A jar is a rigid, cylindrical or slightly conical container, typically made of , , or , with a wide mouth or opening that can be closed with a , , lug cap, , roll-on cap, crimp-on cap, press-on cap, , heat sealed lidding film, an inner seal, ...
) and starting its public static void main(String[]) method. Stand-alone programs must declare this method explicitly. The String[] args parameter is an array of String objects containing any arguments passed to the class. The parameters to main are often passed by means of a
command line A command-line interface (CLI) processes command COMMAND.COM is the default command-line interpreter A command-line interface (CLI) processes command (computing), commands to a computer program in the form of lines of text. The progra ...
. 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 out, including which also appends a new line to the passed
string String or strings may refer to: *String (structure), a long flexible structure made from threads twisted together, which is used to tie, bind, or hang other objects Arts, entertainment, and media Films * Strings (1991 film), ''Strings'' (1991 fil ...
. The string "Hello World!" is automatically converted to a String object by the compiler.


Example with methods

// 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. */ package fibsandlies; import java.util.Map; import java.util.HashMap; /** * This is an example of a Javadoc comment; Javadoc can compile documentation * from this text. Javadoc comments must immediately precede the class, method, * or field being documented. * @author Wikipedia Volunteers */ public class FibCalculator extends Fibonacci implements Calculator


Special classes


Applet

Java applets were programs that were embedded in other applications, typically in a Web page displayed in a web browser. The Java applet API is now deprecated since Java 9 in 2017.


Servlet

Java servlet A Jakarta Servlet (formerly Java Servlet) is a Java Java ( id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a populatio ...
technology provides Web developers with a simple, consistent mechanism for extending the functionality of a Web server and for accessing existing business systems. Servlets are
server-side In the client–server model Client-server model is a distributed application Distributed computing is a field of computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures ...
Java EE components that generate responses to requests from clients. Most of the time, this means generating
HTML The HyperText Markup Language, or HTML is the standard markup language #REDIRECT Markup language In computer text processing, a markup language is a system for annotation, annotating a document in a way that is Syntax (logic), syntacticall ...

HTML
pages in response to
HTTP The Hypertext Transfer Protocol (HTTP) is an application layer An application layer is an abstraction layer that specifies the shared communications protocols and Interface (computing), interface methods used by Host (network), hosts in a c ...
requests, although there are a number of other standard servlet classes available, for example for
WebSocket WebSocket is a computer communications protocol A communication protocol is a system of rules that allows two or more entities of a communications system 400px, Communication system A communications system or communication system is a ...
communication. The Java servlet API has to some extent been superseded (but still used under the hood) by two standard Java technologies for web services: * the Java API for RESTful Web Services (JAX-RS 2.0) useful for AJAX, JSON and REST services, and * the
Java API for XML Web Services The Jakarta XML Web Services (JAX-WS; formerly Java API for XML Web Services) is a Jakarta EE API In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and exp ...
(JAX-WS) useful for
SOAP Soap is a salt (chemistry), salt of a fatty acid used in a variety of cleansing and lubricating products. In a domestic setting, soaps are surfactants usually used for washing, bathing, and other types of housekeeping. In industrial settings, ...

SOAP
Web Service The term Web service (WS) is either: * a service offered by an electronic device to another electronic device, communicating with each other via the World Wide Web The World Wide Web (WWW), commonly known as the Web, is an information ...
s. Typical implementations of these APIs on Application Servers or Servlet Containers use a standard servlet for handling all interactions with the HTTP requests and responses that delegate to the web service methods for the actual business logic.


JavaServer Pages

JavaServer Pages (JSP) are
server-side In the client–server model Client-server model is a distributed application Distributed computing is a field of computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures ...
Java EE components that generate responses, typically
HTML The HyperText Markup Language, or HTML is the standard markup language #REDIRECT Markup language In computer text processing, a markup language is a system for annotation, annotating a document in a way that is Syntax (logic), syntacticall ...

HTML
pages, to
HTTP The Hypertext Transfer Protocol (HTTP) is an application layer An application layer is an abstraction layer that specifies the shared communications protocols and Interface (computing), interface methods used by Host (network), hosts in a c ...
requests from clients. JSPs embed Java code in an HTML page by using the special
delimiter A delimiter is a sequence of one or more character Character(s) may refer to: Arts, entertainment, and media Literature * ''Character'' (novel), a 1936 Dutch novel by Ferdinand Bordewijk * ''Characters'' (Theophrastus), a classical Greek ...
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

Swing Swing or swinging may refer to: Apparatus * Swing (seat), a hanging seat that swings back and forth * Russian swing, a swing-like circus apparatus * Sex swing, a type of harness for sexual intercourse * Swing ride, an amusement park ride consistin ...
is a graphical user interface
library A library is a collection of materials, books or media that are easily accessible for use and not just for display purposes. It is responsible for housing updated information in order to meet the user's needs on a daily basis. A library provi ...
for the Java SE platform. It is possible to specify a different look and feel through the
pluggable look and feel Pluggable look and feel is a mechanism used in the Java (programming language), Java Swing (Java), Swing widget toolkit allowing to change the Look and feel#Look and Feel in Widget Toolkits, look and feel of the graphical user interface at runtime. ...
system of Swing. Clones of
Windows Microsoft Windows, commonly referred to as Windows, is a group of several proprietary {{Short pages monitor