A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer.... originally developed by James Gosling
James Gosling
James A. Gosling, Order of Canada, Doctor of Philosophy is a famous software developer, best known as the father of the Java .... at Sun Microsystems
Sun Microsystems
Sun Microsystems, Inc. is a multinational corporation vendor of computers, computer components, computer software, and information technology services, founded on February 24, 1982.... and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax
Syntax of programming languages
In computer science, the syntax of a programming language is the set of rules that define the combinations of symbols that are considered to be syntactically correct computer programs in that language.... from C
C (programming language)
C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system.... and C++
C++
C++ is a general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level programming language and low-level programming language language features.... but has a simpler object model
Object model
In computing, object model has two related but distinct meanings:# The properties of object in general, in a specific computer programming language, technology, notation or methodology that uses them.... and fewer low-level facilities. Java applications are typically compiled
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language . The most common reason for wanting to transform source code is to create an executable program.... to bytecode
Java bytecode
Java bytecode is the form of instructions that the Java virtual machine executes. Each bytecode instruction or opcode is one byte in length; however, not all of the possible 256 instructions are used.... that can run on any Java virtual machine
Java Virtual Machine
A Java Virtual Machine is a set of computer software programs and data structures which use a virtual machine model for the execution of other computer programs and Scripting language.... (JVM) regardless of computer architecture
Computer architecture
Computer architecture in computer engineering is the conceptual design and fundamental operational structure of a computer system. It is a blueprint and functional description of requirements and design implementations for the various parts of a computer, focusing largely on the way by which the central processing unit performs internally an... .
The original and reference implementation Java compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language . The most common reason for wanting to transform source code is to create an executable program.... s, virtual machines, and class libraries were developed by Sun from 1995.
Discussion
Ask a question about 'Java (programming language)'
Start a new discussion about 'Java (programming language)'
A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer.... originally developed by James Gosling
James Gosling
James A. Gosling, Order of Canada, Doctor of Philosophy is a famous software developer, best known as the father of the Java .... at Sun Microsystems
Sun Microsystems
Sun Microsystems, Inc. is a multinational corporation vendor of computers, computer components, computer software, and information technology services, founded on February 24, 1982.... and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax
Syntax of programming languages
In computer science, the syntax of a programming language is the set of rules that define the combinations of symbols that are considered to be syntactically correct computer programs in that language.... from C
C (programming language)
C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system.... and C++
C++
C++ is a general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level programming language and low-level programming language language features.... but has a simpler object model
Object model
In computing, object model has two related but distinct meanings:# The properties of object in general, in a specific computer programming language, technology, notation or methodology that uses them.... and fewer low-level facilities. Java applications are typically compiled
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language . The most common reason for wanting to transform source code is to create an executable program.... to bytecode
Java bytecode
Java bytecode is the form of instructions that the Java virtual machine executes. Each bytecode instruction or opcode is one byte in length; however, not all of the possible 256 instructions are used.... that can run on any Java virtual machine
Java Virtual Machine
A Java Virtual Machine is a set of computer software programs and data structures which use a virtual machine model for the execution of other computer programs and Scripting language.... (JVM) regardless of computer architecture
Computer architecture
Computer architecture in computer engineering is the conceptual design and fundamental operational structure of a computer system. It is a blueprint and functional description of requirements and design implementations for the various parts of a computer, focusing largely on the way by which the central processing unit performs internally an... .
The original and reference implementation Java compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language . The most common reason for wanting to transform source code is to create an executable program.... 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 Process
Java Community Process
The 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 made available most of their Java technologies as free software
Free software
Free Software or software libre 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 minimal restrictions only to ensure that further recipients can also do these things and to prevent consumer-facing hardware... under the GNU General Public License
GNU General Public License
The GNU General Public License is a widely used free software license, originally written by Richard Stallman for the GNU project. The GPL is the most popular and well-known example of the type of strong copyleft license that requires derived works to be available under the same copyleft.... . Others have also developed alternative implementations of these Sun technologies, such as the GNU Compiler for Java
GNU Compiler for Java
The GNU Compiler for Java , a free software compiler for the Java , forms part of the GNU Compiler Collection.GCJ can compile Java source code to either Java Virtual Machine bytecode, or directly to machine code for any of a number of CPU architectures.... and GNU Classpath
GNU Classpath
GNU Classpath is a project aiming to create a free software implementation of the standard Java Class Library for the Java . 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.... .
James A. Gosling, Order of Canada, Doctor of Philosophy is a famous software developer, best known as the father of the Java .... initiated the Java language project in June 1991 for use in one of his many set-top box
Set-top box
A set-top box or set-top unit is a information appliance that connects to a television and an external source of signal , turning the signal into content which is then displayed on the television screen.... projects. The language, initially called Oak after an oak tree
Oak Tree
Oak Tree usually refers to any of several hundred species of trees and shrubs; however, there are also other uses.*Oak, the tree... that stood outside Gosling's office, also went by the name Green and ended up later renamed as Java, from a list of random words. Gosling aimed to implement a virtual machine
Virtual machine
In computer science, a virtual machine is a software implementation of a machine that executes programs like a real machine.Definitions... and a language that had a familiar C/C++ style of notation.
Sun released the first public implementation as Java 1.0 in 1995. It promised "Write Once, Run Anywhere
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 .... " (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 applet
Applet
An applet is a software component that runs in the context of another program, for example a web browser. An applet usually performs a very narrow function that has no independent use.... s within web pages, and Java quickly became popular. With the advent of Java 2 (released initially as J2SE 1.2 in December 1998), 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. J2SE designated the Standard Edition. In 2006, for marketing purposes, Sun renamed new J2 versions as Java EE, Java ME, and Java SE, respectively.
The International Organization for Standardization , widely known as ISO , is an international standard-setting body composed of representatives from various national standards organizations.... and later the Ecma International
Ecma International
'Ecma 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 international reach.... to formalize Java, but it soon withdrew from the process. Java remains a de facto
De facto
De facto is a Latin expression that means "concerning the fact" or in practice but not necessarily ordained by law. It is commonly used in contrast to de jure when referring to matters of law, governance, or technique that are found in the common experience as created or developed without or contrary to a regulation.... standard, controlled through the Java Community Process
Java Community Process
The 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 software
Proprietary software
Proprietary software is a term coined by advocates of the free software movement to describe computer software which is the legal property of one party.... 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)
Software development kit
A software development kit is typically a set of development tools that allows a software engineer to create application software for a certain software package, software framework, hardware platform, computer system, video game console, operating system, or similar platform.... and Runtime Environment (JRE)
Hotspot
A hot spot is a region of high or special activity within a larger area of low or normal activity. It may refer to:... (a subset of the SDK); the primary distinction involves the JRE's lack of the compiler, utility programs, and header files.
Free and open source software, also F/OSS, FOSS, or FLOSS is software which is liberally software licence to grant the right of users to study, change, and improve its design through the availability of its source code.... under the terms of the GNU General Public License
GNU General Public License
The GNU General Public License is a widely used free software license, originally written by Richard Stallman for the GNU project. The GPL is the most popular and well-known example of the type of strong copyleft license that requires derived works to be available under the same copyleft.... (GPL). On 8 May 2007 Sun finished the process, making all of Java's core code free and open-source, aside from a small portion of code to which Sun did not hold the copyright.
Philosophy
Primary goals
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".
Java Platform
One characteristic of Java is portability, which means that computer programs written in the Java language must run similarly on any supported hardware/operating-system platform. One should be able to write a program once, compile it once, and run it anywhere.
This is achieved by compiling the Java language code, not to machine code but to Java bytecode
Java bytecode
Java bytecode is the form of instructions that the Java virtual machine executes. Each bytecode instruction or opcode is one byte in length; however, not all of the possible 256 instructions are used.... – instructions analogous to machine code but intended to be interpreted
Interpreter (computing)
In computer science, an interpreter normally means a computer program that execution , i.e. performs, instructions written in a programming language.... by a virtual machine
Virtual machine
In computer science, a virtual machine is a software implementation of a machine that executes programs like a real machine.Definitions... (VM) written specifically for the host hardware. End-user
End-user
Economics 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 Environment (JRE) installed on their own machine for standalone Java applications, or in a Web browser for Java applet
Applet
An applet is a software component that runs in the context of another program, for example a web browser. An applet usually performs a very narrow function that has no independent use.... s.
Standardized libraries provide a generic way to access host specific features such as graphics, threading
Thread (computer science)
In computer science, a thread of execution is a Fork of a computer program into two or more Concurrency running task s. The implementation of threads and process es differs from one operating system to another, but in most cases, a thread is contained inside a process.... and networking
Computer network
A computer network is a group of interconnected computers. Networks may be classified according to a wide variety of characteristics. This article provides a general overview of some types and categories and also presents the basic components of a network.... . In some JVM versions, bytecode can be compiled to native code, either before or during program execution, resulting in faster execution.
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, and Java suffered a reputation for poor performance. This gap has been narrowed by a number of optimisation techniques introduced in the more recent JVM implementations.
In computing, just-in-time compilation , also known as dynamic translation, is a technique for improving the runtime performance of a computer program.... , translates Java bytecode into native code the first time that code is executed, then caches it. This results in a program that starts and executes faster than pure interpreted code can, at the cost of introducing occasional compilation overhead during execution. More sophisticated VMs also use dynamic recompilation
Dynamic recompilation
In computer science, dynamic recompilation is a feature of some emulators and virtual machines, where the system may compile some part of a Computer program during execution.... , in which the VM analyzes the behavior of the running program and selectively recompiles and optimizes parts of the program. Dynamic recompilation can achieve optimizations superior to static compilation because the dynamic compiler can base optimizations on knowledge about the runtime environment and the set of loaded classes, and can identify hot spots - parts of the program, often inner loops, that take up the most execution time. JIT compilation and dynamic recompilation allow Java programs to approach the speed of native code without losing portability.
An Ahead-of-Time compiler is a compiler that implements Ahead of Time Compilation. This refers to the act of compiling an intermediate language, such as Java bytecode, .NET Common Intermediate Language , or IBM System/38 or IBM System i "Technology Independent Machine Interface" code, into a system-dependent binary.... , is to compile directly into native code like a more traditional compiler. Static Java compilers translate the Java source or bytecode to native object code. This achieves good performance compared to interpretation, at the expense of portability; the output of these compilers can only be run on a single architecture
Computer architecture
Computer architecture in computer engineering is the conceptual design and fundamental operational structure of a computer system. It is a blueprint and functional description of requirements and design implementations for the various parts of a computer, focusing largely on the way by which the central processing unit performs internally an... . AOT could give Java something close to native performance, yet it is still not portable since there are no compiler directives, and all the pointers are indirect with no way to micro manage garbage collection.
Programs written in Java have had a reputation for being slower and requiring more memory than those written in compiled languages such as C or C++ .... has improved substantially since the early versions, and performance of JIT compilers relative to native compilers has in some tests been shown to be quite similar. The performance of the compilers does not necessarily indicate the performance of the compiled code; only careful testing can reveal the true performance issues in any system.
One of the unique advantages of the concept of a runtime engine is that errors (exceptions) should not 'crash' the system. Moreover, in runtime engine environments such as Java there exist tools that attach to the runtime engine and every time that an exception of interest occurs they record debugging information that existed in memory at the time the exception was thrown (stack and heap values). These Automated Exception Handling
Automated Exception Handling
Automated Exception Handling is a computing term referring to the computerized handling of errors. Runtime engines such as those for the Java language or Microsoft .Net lend themselves to an automated mode of exception or error handling.... tools provide 'root-cause' information for exceptions in Java programs that run in production, testing or development environments.
Implementations
Sun Microsystems officially licenses the Java Standard Edition platform for Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of software operating systems and graphical user interfaces produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces .... , Linux
Linux
Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration; typically all the underlying source code can be used, freely modified, and redistributed by anyone under the terms of the GNU GPL license... , Mac OS X
Mac OS X
Mac OS X is a line of computer operating systems developed, marketed, and sold by Apple Inc., and since 2002 has been included with all new Macintosh computer systems.... , and Solaris. Through a network of third-party vendors and licensees, alternative Java environments are available for these and other platforms.
Sun's trademark license for usage of the Java brand insists that all implementations be "compatible". This resulted in a legal dispute with Microsoft
Microsoft
Microsoft Corporation is a multinational corporation computer technology corporation that develops, manufactures, licenses, and supports a wide range of computer software products for computing devices.... after Sun claimed that the Microsoft implementation did not support RMI
Java remote method invocation
The Java Remote Method Invocation Application Programming Interface, or Java RMI, a Java application programming interface, performs the object-oriented equivalent of remote procedure calls.... or JNI
Java Native Interface
The Java Native Interface is a software framework that allows 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 language.... and had added platform-specific features of their own. Sun sued in 1997, and in 2001 won a settlement of $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 Windows
Microsoft Windows
Microsoft Windows is a series of software operating systems and graphical user interfaces produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces .... , and in recent versions of Windows, Internet Explorer
Internet Explorer
Windows Internet Explorer , commonly abbreviated to IE, is a series of graphical user interface web browsers developed by Microsoft and included as part of the Microsoft Windows line of operating systems starting in 1995.... 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 EE
Java Platform, Enterprise Edition
Java Platform, Enterprise Edition or Java EE is a widely used Platform for Server programming in the Java programming language. The Java Platform differs from the Java Platform, Standard Edition in that it adds libraries which provide functionality to deploy fault-tolerant, Distributed computing, multitier architecture Java Applicat... strategy, and an even more rigorous validation is required to certify an implementation. This environment enables portable server-side applications, such as Web service
Web service
A Web service is defined by the W3C as "a software system designed to support interoperability Machine to Machine interaction over a computer network".... s, servlets, and Enterprise JavaBean
Enterprise JavaBean
Enterprise JavaBeans is a managed, server-side component architecture for modular construction of enterprise applications.The EJB specification is one of several Java platform Application programming interfaces in the Java Platform, Enterprise Edition.... s, as well as with embedded system
Embedded system
An embedded system is a special-purpose computer system designed to perform one or a few dedicated functions, often with real-time computing constraints.... s based on OSGi
OSGi
The OSGi Alliance is an open standards organization founded in March 1999. The Alliance and its members have specified a Java -based Service platform that can be remotely managed.... , using Embedded Java
Embedded Java
In discussions of Java Platform, Micro Edition specifications, such as the Connected Device Configuration/Connected Limited Device Configuration device capability sets and the MIDP profile definition, attention needs to be given to Embedded Java, which additionally requires very specialized, optimized Java virtual machines, and the means to update... environments. Through the new GlassFish
Glassfish
Glassfish may refer to:* The Asiatic glassfishes in the family Ambassidae* GlassFish, a Java Enterprise Edition application server project... project, Sun is working to create a fully functional, unified open-source implementation of the Java EE technologies.
Sun also distributes a superset of the JRE called the Java 2 SDK
SDK
SDK may refer to:* Slovak Democratic Coalition* Software development kit... (more commonly known as the JDK), which includes development tools such as the Java compiler
Java compiler
A Java compiler is a compiler for the Java . The most common form of output from a Java compiler are Class containing platform-neutral Java bytecode.... , Javadoc
Javadoc
Javadoc is a documentation generator from Sun Microsystems for generating Application programming interface documentation in HTML format from Java source code.... , Jar
JAR (file format)
In computing, a JAR file aggregates many files into one. Software developers generally use .jar files to distribute Java platform class and associated metadata.... and debugger
Debugger
A debugger 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 will typically be much slower than executing the code directly on... .
Automatic memory management
Java uses an automatic garbage collector to manage memory in the object lifecycle
Object lifetime
In 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.... . 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 object becomes eligible to be freed automatically by the garbage collector. Something similar to a memory leak may still occur if a programmer's code holds a reference to an object that is no longer needed, typically when objects that are no longer needed are stored in containers that are still in use. 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 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. Either way the responsibility of managing memory resides with the programmer. If the program does not deallocate an object, a memory leak
Memory leak
In computer science, a memory leak is a particular type of unintentional memory consumption by a computer program where the program fails to release dynamic memory when no longer needed.... 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 pointers, but these add overhead and complexity.
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. Where performance or response time is important, explicit memory management and object pools are often used.
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.
C++ is a general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level programming language and low-level programming language language features.... and some other object-oriented languages, variables of Java's primitive type
Primitive type
In computer science, primitive type can refer to either of the following concepts:* a basic type is a data type provided by a programming language as a basic building block.... s are not objects. Values of primitive types are either stored directly in fields (for objects) or on the stack
Stack-based memory allocation
Stack s in computing architectures are regions of memory where data is added or removed in a LIFO manner.In most modern computer systems, each Thread has a reserved region of memory referred to as its stack.... (for methods) rather than on the heap, as commonly true for objects (but see Escape analysis
Escape analysis
In 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
Object type
In computer science, an object type is a datatype which is used in object-oriented programming to wrapper pattern a non-object type to make it look like a Reference type object .... enables programmers to proceed as if primitive types are instances of their wrapper classes.
C++ is a general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level programming language and low-level programming language language features.... . 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 intrinsic data types (ordinal and real numbers, boolean values, and characters), which are not classes for performance reasons.
In computer programming, operator overloading is a specific case of polymorphism in which some or all of operator s like +, =, or have different implementations depending on the types of their arguments.... and multiple inheritance
Multiple inheritance
Multiple inheritance refers to a feature of some object-oriented programming programming languages in which a class can inheritance behaviors and features from more than one superclass .... ) for classes in order to simplify the language and to prevent possible errors and anti-pattern design.
A "Hello World" program is a computer program that prints out "Hello world!" on a display device. It is used in many introductory tutorials for teaching a programming language.... can be written in Java as:
/*
* Outputs "Hello, World!" and then exits
*/
public class HelloWorld
By convention, source files are named after the public class they contain, appending the suffix .java, for example, HelloWorld.java. It must first be compiled into bytecode, using a Java compiler
Java compiler
A Java compiler is a compiler for the Java . The most common form of output from a Java compiler are Class containing platform-neutral Java bytecode.... , producing a file named HelloWorld.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 class
Inner class
In object-oriented programming, an inner class is a class declared entirely within the body of another class or interface.Inner classes became a feature of the Java starting with version 1.1.... es.
A class that is declared private 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 was 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.
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 method variables that are not 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
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 Java Beans 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.
In computer science, an array is a data structure consisting of a group of element s that are accessed by index . In most programming languages each element has the same data type and the array occupies a contiguous area of computer memory.... 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 (the args parameter is still an array of String objects), but allows an alternate 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
JAR (file format)
In computing, a JAR file aggregates many files into one. Software developers generally use .jar files to distribute Java platform class and associated metadata.... ) and starting its public static void main(String[]) method. Stand-alone programs must declare this method explicitly. The String[] args parameter is an array
Array
In computer science, an array is a data structure consisting of a group of element s that are accessed by index . In most programming languages each element has the same data type and the array occupies a contiguous area of computer memory.... of objects containing any arguments passed to the class. The parameters to main are often passed by means of a command line.
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
Standard streams
In 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
The import statement imports the class from the package.
In computer science, data that has several parts can be divided into fields. For example, a computer may represent today's date as three distinct fields: the day, the month and the year.... 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.
In object-oriented programming, a constructor in a class is a special block of statements called when an object lifetime#Creating objects, either when it is declared or dynamically constructed on the heap-based memory allocation through the keyword ?new?.... . Constructors have the same name as the enclosing class they are declared in, and unlike a method, have no return type
Return type
In computer programming, the return type defines and constrains the type of value returned from a method or Subroutine. In many programming languages the return type must be explicitly specified when declaring a function.... . A constructor is used to initialize an object
Object (computer science)
In its simplest embodiment, an object is an allocated region of storage. Since programming languages use variable#Computer_programmings to access objects, the terms object and variable are often used interchangeably.... that is a newly created instance of the class.
The dialog returns a String that is converted to an int by the method.
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 reference
Reference (computer science)
In computer science, a reference is an object containing information about how to locate and access the particular data item, as opposed to containing the data itself.... used to invoke the method is passed as an undeclared parameter of type OddEven named 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 reference
Reference (computer science)
In computer science, a reference is an object containing information about how to locate and access the particular data item, as opposed to containing the data itself.... 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 numberlocal variable
Local variable
In computer science, a local variable is a variable that is given local scope . Such a variable is accessible only from the subroutine or statement block in which it is declared.... is used to invoke the method and passed as the undeclared this parameter to the calculate method.
input = new Integer(JOptionPane.showInputDialog("Please Enter A Number")); is a statement that converts the type of String to the primitive type
Primitive type
In computer science, primitive type can refer to either of the following concepts:* a basic type is a data type provided by a programming language as a basic building block.... int by taking advantage of the wrapper class Integer.
Special Classes
Applet
Java applets are programs that are embedded in other applications, typically in a Web page displayed in a Web browser
Web browser
A Web browser is a application software which enables a user to display and interact with text, images, videos, music, games and other information typically located on a Web page at a website on the World Wide Web or a local area network.... .
A Java compiler is a compiler for the Java . The most common form of output from a Java compiler are Class 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 code
Source code
In computer science, source code is any collection of statements or declarations written in some human-readable computer programming language.... using the simple class name (i.e. JApplet) instead of the fully qualified class name (i.e. javax.swing.JApplet).
In object-oriented programming, a subclass is a class that Inheritance some properties from its superclass .You can usually think of the subclass as being "a kind of" its superclass, as in a "a Manx is a kind of cat", or "a square is a kind of rectangle":... ) the JApplet (Java Applet) class; the JApplet class provides the framework for the host application to display and control the lifecycle
Object lifetime
In 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.... of the applet. The JApplet class is a JComponent (Java Graphical Component) which provides the applet with the capability to display a graphical user interface
Graphical user interface
A graphical user interface is a type of user interface which allows people to human-computer interaction such as computers; hand-held devices such as MP3 Players, Portable Media Players or Gaming devices; household appliances and office equipment.... (GUI) and respond to user events
Event-driven programming
In computer programming, event-driven programming or event-based programming is a programming paradigm in which the Program flow is determined by event s — i.e., sensor outputs or user actions or Message passing from other programs or Thread_.... .
Method overriding, in object oriented programming, is a language feature that allows a Subclass to provide a specific implementation of a method that is already provided by one of its superclass es.... the method inherited from the superclass
Superclass (computer science)
In computer science, a superclass is a class from which other classes are derived. A superclass is also called a parent class. The classes that are derived from a superclass are known as child classes, derived classes, or subclass .... to provide the code to display the applet. The paint 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 pixel
Pixel
In digital imaging, a pixel is the smallest item of information in an image. Pixels are normally arranged in a 2-dimensional grid, and are often represented using dots, squares, or rectangles.... offset of (65, 95) from the upper-left corner in the applet's display.
HTML, an Acronym and initialism of HyperText Markup Language, is the predominant markup language for Web pages. It provides a means to describe the structure of text-based information in a document?by denoting certain text as links, headings, paragraphs, lists, and so on?and to supplement that text with interactive forms, embedded '... document using the HTML element
HTML element
In computing, an HTML element indicates structure in an HTML document and a way of hierarchically arranging content. More specifically, an HTML element is an Standard Generalized Markup Language element that meets the requirements of one or more of the HTML Document Type Definitions .... . 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 paint method is called by the AWT event dispatching thread
Event dispatching thread
The event dispatching thread is a background Thread used in Java to process events from the Abstract Window Toolkit graphical user interface event queue.... 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-side
Server-side
Server-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 HTML
HTML
HTML, an Acronym and initialism of HyperText Markup Language, is the predominant markup language for Web pages. It provides a means to describe the structure of text-based information in a document?by denoting certain text as links, headings, paragraphs, lists, and so on?and to supplement that text with interactive forms, embedded '... pages) to requests (typically HTTP requests) from client
Client (computing)
A client is an Application software or system that accesses a remote service on another computer system, known as a Server , by way of a Computer network.... s. A servlet can almost be thought of as an applet that runs on the server side—without a face.
The import statements direct the Java compiler to include all of the public classes and interfaces
Interface (Java)
An interface in the Java is an abstract type that is used to specify an interface that class must implement. Interfaces are declared using the interface Java keywords, and may only contain Method signatures and constant declarations .... from the and packages
Java package
A Java package is a mechanism for organizing Java class into namespace 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.... in the compilation.
The Hello class extends the class; the GenericServlet class provides the interface for the server
Server (computing)
A server is a computer program that provides services to other computer programs , in the same or other computer. The physical computer that runs a server program is also often referred to as server.... to forward requests to the servlet and control the servlet's lifecycle.
The Hello class overrides the method defined by the interface
Interface (Java)
An interface in the Java is an abstract type that is used to specify an interface that class must implement. Interfaces are declared using the interface Java keywords, and may only contain Method signatures 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 exceptions
Exception handling
Exception 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 execution.... and if a problem prevents it from responding to the request.
The method in the response object is called to set the MIME
MIME
Multipurpose Internet Mail Extensions is an Internet standard that extends the format of electronic mail to support:* Text in character sets other than ASCII... 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.
Server-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 HTML
HTML
HTML, an Acronym and initialism of HyperText Markup Language, is the predominant markup language for Web pages. It provides a means to describe the structure of text-based information in a document?by denoting certain text as links, headings, paragraphs, lists, and so on?and to supplement that text with interactive forms, embedded '... pages, to HTTP requests from client
Client (computing)
A client is an Application software or system that accesses a remote service on another computer system, known as a Server , by way of a Computer network.... s. JSPs embed Java code in an HTML page by using the special delimiter
Delimiter
A delimiter is a sequence of one or more character s used to specify the boundary between separate, independent regions in plain text or other data stream.... 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 is a widget toolkit for Java . It is part of Sun Microsystems' Java Foundation Classes — an Application programming interface for providing a graphical user interface for Java programs.... is a graphical user interface library
Library (computer science)
In computer science, a library is a collection of subroutines or Class used to develop software. Libraries contain code and data that provide services to independent programs.... 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
Pluggable look and feel is a mechanism used in the Java Swing_ widget toolkit allowing to change the Look and feel#Look and Feel in Widget Toolkits of the graphical user interface at runtime.... system of Swing. Clones of Windows
Microsoft Windows
Microsoft Windows is a series of software operating systems and graphical user interfaces produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces .... , GTK and Motif
Motif (widget toolkit)
In 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.... are supplied by Sun. Apple
Apple Computer
Apple Inc., formerly Apple Computer Inc., is an United States multinational corporation which designs and manufactures consumer electronics and software products.... also provides an Aqua look and feel for Mac OS X
Mac OS X
Mac OS X is a line of computer operating systems developed, marketed, and sold by Apple Inc., and 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 widget
Widget (computing)
In computer programming, a widget is an element of a graphical user interface that displays an information arrangement changeable by the user, such as a window or a text box.... drawing routines of the underlying platforms.
This example Swing application creates a single window with "Hello, world!" inside:
// Hello.java (Java SE 5)
import java.awt.BorderLayout;
import javax.swing.*;
public class Hello extends JFrame
The first import statement directs the Java compiler to include the class from the package in the compilation; the second import includes all of the public classes and interfaces from the package.
The Hello class extends the class; the JFrame class implements a window
Window (computing)
In computing, a window is a visual area, usually rectangular in shape, containing some kind of user interface, displaying the output of and allowing input for one of a number of simultaneously running computer processes.... with a title bar
Title bar
In 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 software window as a horizontal bar.... and a close control
Widget (computing)
In computer programming, a widget is an element of a graphical user interface that displays an information arrangement changeable by the user, such as a window or a text box.... .
In object-oriented programming, a constructor in a class is a special block of statements called when an object lifetime#Creating objects, either when it is declared or dynamically constructed on the heap-based memory allocation through the keyword ?new?.... 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, the layout
Layout manager
Layout managers are software components used in widget toolkits which have the ability to lay out Widget by their relative positions without using distance units.... of the frame is set to a BorderLayout; this tells Swing how to arrange the components that will be added to the frame. 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, in the manner indicated by the BorderLayout.
The main method is called by the JVM when the program starts. It instantiates 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 thread
Event dispatching thread
The event dispatching thread is a background Thread used in Java to process events from the Abstract Window Toolkit graphical user interface event queue.... remains active until all of the Swing top-level windows have been disposed.
Generics
Prior to 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.
In computer science, a library is a collection of subroutines or Class used to develop software. Libraries contain code and data that provide services to independent programs.... are the compiled byte codes of source code
Source code
In computer science, source code is any collection of statements or declarations written in some human-readable computer programming language.... developed by the JRE implementor to support application development in Java. Examples of these libraries are:
A data structure in computer science is a way of storing data in a computer so that it can be used efficiently. It is an organization of mathematical and logical concepts of data.... s such as lists
List (computing)
In computer science, a list is an ordered Multiset of entity/items.In the context of object-oriented programming languages, a list is defined as an instance of an abstract data type , formalizing the concept of an order theoryed Collection class of entity.... , dictionaries
Associative array
An associative array is an abstract data type composed of a Collection of unique keys and a collection of values, where each key is associated with one value .... , trees
Tree structure
A tree structure is a way of representing the hierarchy nature of a structure in a graphical form.It is named a "tree structure" because the graph looks a bit like a tree, even though the tree is generally shown upside down compared with a real tree; that is to say with the root at the top and the leaves at the bottom.... and sets
Set (computer science)
In computer science, a set is a collection of certain values, without any particular Canonical order, and no repeated values. It corresponds with a finite set in mathematics....
XML Processing (Parsing, Transforming, Validating) libraries
Security
Internationalization and localization libraries
The integration libraries, which allow the application writer to communicate with external systems. These libraries include:
Java Database Connectivity is an Application programming interface for the Java that defines how a client may access a database. It provides methods for querying and updating data in a database.... (JDBC) API
Application programming interface
An application programming interface is a set of subroutine, data structures, class and/or Protocol provided by library and/or operating system Service s in order to support the building of applications.... for database access
The Java Naming and Directory Interface is a Java Application programming interface for a directory service that allows Java software clients to discover and look up data and objects via a name.... (JNDI) for lookup and discovery
The Java Remote Method Invocation Application Programming Interface, or Java RMI, a Java application programming interface, performs the object-oriented equivalent of remote procedure calls.... and CORBA
Çorba
Chorba , shurpa , sorpa , or shorpo is one of various kinds of soup or stew found in national cuisines across Eurasia. The term is likely of Persian language or Turkic languages origin.... for distributed application development
The user interface is the aggregate of means by which people—the User s—Interaction with the system—a particular machine, device, computer program or other complex tools.... libraries, which include:
The term native mode 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 Toolkit
Abstract Window Toolkit
The Abstract Window Toolkit is Java 's original platform-independent Windowing system, graphics, and user-interface widget toolkit. The AWT is now part of the Java Foundation Classes — the standard Application programming interface for providing a graphical user interface for a Java program.... (AWT), which provides GUI
Graphical user interface
A graphical user interface is a type of user interface which allows people to human-computer interaction such as computers; hand-held devices such as MP3 Players, Portable Media Players or Gaming devices; household appliances and office equipment.... components, the means for laying out those components and the means for handling events from those components
Swing is a widget toolkit for Java . It is part of Sun Microsystems' Java Foundation Classes — an Application programming interface for providing a graphical user interface for Java programs.... libraries, which are built on AWT but provide (non-native) implementations of the AWT widgetry
A Java Virtual Machine is a set of computer software programs and data structures which use a virtual machine model for the execution of other computer programs and Scripting language.... (JVM) that is the means by which the byte codes of the Java libraries and third party applications are executed
A Java applet is an applet delivered to the users in the form of Java bytecode. Java applets can run in a Web browser using a Java Virtual Machine , or in Sun Microsystems's AppletViewer, a stand-alone tool for testing applets.... s to be run in Web browser
Web browser
A Web browser is a application software which enables a user to display and interact with text, images, videos, music, games and other information typically located on a Web page at a website on the World Wide Web or a local area network.... s
In computing, Java Web Start , a Software framework developed by Sun Microsystems, 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 users across the Internet
Internet
The Internet is a global network of interconnected computers, enabling users to share information along multiple channels. Typically, a computer that connects to the Internet can access information from a vast array of available server and other computers by moving information from them to the computer's local memory....
Licensing and documentation.
Editions
Sun has defined and supports four editions of Java targeting different application environments and segmented many of its API
Application programming interface
An application programming interface is a set of subroutine, data structures, class and/or Protocol provided by library and/or operating system Service s in order to support the building of applications.... s so that they belong to one of the platforms. The platforms are:
Java Card refers to a technology that allows small Java platform-based applications to be run securely on smart cards and similar small memory footprint devices.... for smartcards
In computing, the Java Platform, Micro Edition or Java ME is a specification of a subset of the Java platform aimed at providing a certified collection of Java Application Programming Interfaces for the development of software for tiny, small and resource-constrained devices.... (Java ME) — targeting environments with limited resources,
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 porting Application software for general use.... (Java SE) — targeting workstation environments, and
Java Platform, Enterprise Edition or Java EE is a widely used Platform for Server programming in the Java programming language. The Java Platform differs from the Java Platform, Standard Edition in that it adds libraries which provide functionality to deploy fault-tolerant, Distributed computing, multitier architecture Java Applicat... (Java EE) — targeting large distributed enterprise or Internet environments.
In object-oriented programming, a class is a programming language construct that is used as a blueprint to create Object s. This blueprint includes Attribute s and Method s that the created objects all share.... in the Java APIs are organized into separate groups called packages
Java package
A Java package is a mechanism for organizing Java class into namespace 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 interface
Interface (Java)
An interface in the Java is an abstract type that is used to specify an interface that class must implement. Interfaces are declared using the interface Java keywords, and may only contain Method signatures and constant declarations .... s, classes and exceptions
Exception handling
Exception 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 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 Process
Java Community Process
The 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.
PersonalJava is a Java platform for mobile and embedded systems based on Java 1.1.8 . It has been superseded by the Connected Device Configuration's Personal Profile which is not yet widely deployed.... that has been superseded by later, standards-based Java ME configuration-profile pairings.
Programming languages are used for controlling the behavior of a machine . Like natural languages, programming languages conform to rules for syntax and semantics....
JavaOne is an annual conference put on by Sun Microsystems to discuss Java technologies, primarily among Java developers. JavaOne is held at the Moscone Center in San Francisco, California usually between April and June and typically runs from Sunday to Friday....
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....
This article provides non-exhaustive lists of J2SE Java virtual machines . It does not include a large number of Java Platform, Micro Edition vendors....
There are three types of Java Application programming interface :* the official core Java API, contained in the Java Development Kit or Java Runtime Environment, of one of the editions of the Java Platform....
This list of JVM Languages comprises computer programming languages that are used to produce software that runs on the Java Virtual Machine. Some of these languages are interpreted language by a Java , and some are compiled to Java bytecode and Just-in-time compilation during execution as regular Java programs to improve performance....
The Java has undergone several changes since Java Development Kit 1.0 as well as numerous additions of classes and packages to the standard library ....
External links
[https://duke.dev.java.net/green/ A Brief History of the Green Project]