Java (not to be confused with JavaScript) is a class-based, object-oriented, strongly typed, reflective language and run-time environment (JRE). Java programs are compiled to bytecode and run in a virtual machine (JVM) enabling a "write once, run anywhere" (WORA) methodology.
Java is a high-level, platform-independent, object-oriented programming language and run-time environment. The Java language derives much of its syntax from c and c++, but its object model is simpler than that of c++ and it has fewer low-level facilities. Java applications are typically compiled to bytecode (called class files) that can be executed by a Java Virtual Machine jvm, independent of computer architecture. The jvm manages memory with the help of a garbage collector (see garbage-collection) in order to handle object removal from memory when not used anymore, as opposed to manually deallocating memory, like other languages such as c++.
java is designed to have as few implementation dependencies as possible, and is intended to allow application developers to "write once, run anywhere" (WORA): code that executes on one platform need not be recompiled to run on another.
Principles
The Java language was created with the following primary goals:
- Simple, object-oriented, and familiar.
- Robust and secure.
- Architecture-neutral and portable.
- Execute with high performance.
- Interpreted, multi-threaded, and dynamic.
- Write once, run anywhere (WORA).
- Inheritance.
- Encapsulation.
- Polymorphic.
Background
Java is a high-level, platform-independent, object-oriented programming language originally developed by James Gosling for Sun Microsystems and released in 1995. The Java trademark is currently owned by Oracle, which purchased Sun Microsystems on April 20, 2009.
The main reference implementation of Java is open source (the OpenJDK), and is supported by major companies including Oracle, Apple, SAP and IBM.
Very few computers can run Java programs directly. Therefore, the Java environment is normally made available by installing a suitable software component. For Windows computers, this is usually done by downloading the free Java Runtime Environment (JRE) from java.com. On Macintosh computers, the user is prompted to download Java when an application requiring it is started. On linux-like systems, Java is typically installed via the package manager.
Developers frequently need additional tools which are available in the free Java Development Kit (JDK) alternative to the JRE, which for Windows must be downloaded from Oracle and installed manually.
Java is compiled into bytecode which is interpreted on the JVM by compiling into native code. The compilation is done just-in-time (JIT). Initially, this was viewed as a performance hit, but JVM and JIT compilation improvements have made this less of a concern. In some cases, the JVM may even be faster than native code compiled to target an older version of a processor for backward-compatibility reasons.
Note: Other vendors exist, though almost all have license fees. For linux and other platforms, consult the operating system documentation.
Versions
Notable Java versions, code names, and release dates include:
JDK 1.0 (January 23, 1996)
JDK 1.1 (February 19, 1997)
J2SE 1.2 [Playground] (December 8, 1998)
J2SE 1.3 [Kestrel] (May 8, 2000)
J2SE 1.4 [Merlin] (February 6, 2002)
J2SE 5.0 [Tiger] (September 30, 2004)
Java SE 6 [Mustang] (December 11, 2006)
Java SE 7 [Dolphin] (July 28, 2011)
Java SE 8 [JSR 337] (March 18, 2014)
For more code names and release dates, visit J2SE Code Names. To see release notes for each version of the JDK, visit the Wikipedia article on Java version history.
The End Of Public Updates (Formerly called End Of Life) dates are:
J2SE 1.4 - Oct 2008
J2SE 5.0 - Oct 2009
Java SE 6 - Feb 2013
Java SE 7 - Mar 2015
Initial help
- New to Java – need help to get your first Java program running? See the Oracle Java Tutorials section on Getting Started.
Naming conventions
Java programs should adhere to the following naming conventions to increase readability and decrease chances of accidental errors. By following these naming conventions, you will make it easier for others to understand your code and help you.
- Type names (classes, interfaces, enums, etc.) should begin with a capital letter, and capitalize the first letter of each subsequent word. Examples include:
String
,ThreadLocal
, andNullPointerException
. This is sometimes known as PascalCase. - Method names should be camelCased; that is, they should begin with a lowercase letter and capitalize the first letter of each subsequent word. Examples:
indexOf
,printStackTrace
,interrupt
. - Field names should be camelCased just like method names.
- Constant expression names (
static final
immutable objects) should be written in ALL_CAPS, with underscores separating each word. Examples:YELLOW
,DO_NOTHING_ON_CLOSE
. This also applies to values of anEnum
class. However,static final
references to non-immutable objects should be camelCased.
Hello World
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Compilation and invocation of Hello World:
javac -d . HelloWorld.java
java -cp . HelloWorld
Java source code is compiled to an intermediate form (bytecode instructions for the Java Virtual Machine) that can be executed with the java
command.
More information:
Beginners' resources
- The Java Tutorials - Starts from scratch on Windows/Linux/Mac and covers most of the standard library.
- Generics
- Coding Bat (Java) - After learning some basics, refine and hone your Java skills with Coding Bat.
- Code Conventions for the Java Programming Language
- Stanford Video Lectures on Java
- Udemy free course on Java
Day-to-day resources
Advanced resources
Free Java programming books and resources
- Java Application Development on Linux by Carl Albing and Michael Schwarz(PDF)
- How to Think Like a Computer Scientist
- The Java EE6 Tutorial (PDF)
- Java Thin-Client Programming
- Oracle's Java Tutorials
- Thinking in Java
- OSGi in Practice (PDF)
- Category wise tutorials - J2EE
- Java Example Codes and Tutorials - J2EE
- Java Design Pattern Video Training
- Head First JAVA
Frequently Asked Questions
People often ask about the following Java topics:
- Difference between
equals()
and==
- How do I compare strings in Java?
- Overriding
equals()
andhashCode()
in Java - Why NoClassDefFoundError?
- Why did Java have the reputation of being slow?
- How do I avoid null checks in Java?
- How can I convert my java program to an .exe file
- Is
List<Dog>
a subclass ofList<Animal>
? Why aren't Java's generics implicitly polymorphic? - Compare dates in Java
- Is Java pass by reference?
- NoSuchMethodError in Java
- Why can't I print a double correctly?
- Java: Efficient Equivalent to Removing while Iterating a Collection
- Scanner issue when using nextLine after nextInt
- [StringBuilder and StringBuffer in Java] 53
- What does java.lang.Thread.interrupt() do?
- What is a stack trace, and how can I use it to debug my application errors?
- Java Generics: What is PECS?
- How to sort a Map<Key, Value> on the values in Java?
- What's the advantage of a Java enum versus a class with public static final fields?
- When to use LinkedList<> over ArrayList<>?
- Boolean.valueOf(String) and BooleanUtils.toBoolean(String) in java?
- Arrays.asList() in java?
- Differences between HashMap and Hashtable?
- Difference between Public,Protected,Private and Default in JAVA
(Submitters, please only list questions which actually are frequently asked.)