- Java Tutorial
- What is Java?
- Installing the Java SDK
- Your First Java App
- Java Main Method
- Java Project Overview, Compilation and Execution
- Java Core Concepts
- Java Syntax
- Java Variables
- Java Data Types
- Java Math Operators and Math Class
- Java Arrays
- Java String
- Java Operations
- Java if statements
- Java Ternary Operator
- Java switch Statements
- Java instanceof operator
- Java for Loops
- Java while Loops
- Java Classes
- Java Fields
- Java Methods
- Java Constructors
- Java Packages
- Java Access Modifiers
- Java Inheritance
- Java Nested Classes
- Java Abstract Classes
- Java Record
- Java Interfaces
- Java Interfaces vs. Abstract Classes
- Java Enums
- Java Annotations
- Java Lambda Expressions
- Java Modules
- Java Exercises
What is Java?
Java was originally a programming language invented by Sun Microsystems, by James Gosling. Today Oracle owns Sun, and therefore Java too. Java is thus Oracle's trademark. Over time Java has evolved into more than just a language. It is a full platform with lots of standard APIs, open source APIs, tools, a big developer community with millions of developers etc. It may be a bit unclear what all this means, but you will get a better feeling for it when you start learning more about Java, and start working with it.
When people talk about Java they often refer to several different parts of the total concept. That is because Java is more than just a programming language. For a beginner, all these different "meanings" can be confusing, so I will explain them briefly so you know what people are talking about. The most commonly concepts associated with Java are:
I will explain these Java parts briefly in the sections below.
First and foremost Java is a programming language. This means that there exists a Java language specification that explicitly tells what elements are part of the Java language itself. What the Java language is capable of doing, in other words.
It is the Java language itself that this tutorial trail is focused on.
Java files are stored in files suffixed with
.java . These files are then compiled into Java byte code
using the Java compiler, and the byte code is then executed using the Java Virtual Machine (JVM). The Java compiler and
the JVM are part of the Java Development Kit.
Java programs written in the Java language are compiled into Java bytecode which can be executed by the Java Virtual Machine.
The Java bytecode is stored in binary
Java Virtual Machine
Java is an interpreted language. What does that mean? Well, the Java language is compiled into Java bytecode. This Java bytecode is then executed by the Java Virtual Machine.
The Java Virtual Machine is like a computer. It can execute Java bytecode just like a PC can execute assembler instructions.
The Java Virtual Machine is implemented for several different operating systems, like Windows, Mac OS, Linux, IBM mainframes, Solaris etc. Thus, if your Java program can run on a Java Virtual Machine on Windows, it can normally also run on a Java Virtual Machine on Mac OS or Linux. Sometimes there are a OS specific issues that make your applications behave differently, but most of the time they behave very much alike. Sun referred to this as "Write once, run anywhere".
The Java Virtual Machine is a program itself. You start up the JVM and tell it what Java code to execute. This is typically done via a command line interface (CLI), like e.g. bash, or the command line interface in Windows. On the command line you tell the JVM what Java class (bytecode) to execute.
The Java language enables you to package components written in the Java language into APIs (Application Programming Interfaces) which can be used by others in their Java applications. Java comes bundled with a lot such components. These components are known as the standard Java APIs . These APIs enable your Java programs to access the local file system, the network and many other things.
The standard Java APIs provide a lot of basic functionality which you would otherwise have had to program yourself. Thus, the APIs help you develop your applications faster.
The standard Java APIs are available to all Java applications. The standard Java APIs come bundled with the Java Runtime Environment (JRE) or with the Java SDK which also includes a JRE.
Java Runtime Environment (JRE)
The Java Runtime Environment (JRE) is the Java Virtual Machine and the standard Java APIs coming with Java Standard Edition (JSE). The JRE contains enough to execute a Java application, but not to compile it.
Java Software Development Kit (Java SDK)
The Java Software Development Kit (Java SDK) is the JRE plus the Java compiler, and a set of other tools.
If you need to develop Java programs you need the full Java SDK. The JRE is not enough then. Only the full
Java SDK contains the Java compiler which turns your
.java source files into byte code
Additionally, some Java servers may need some of the tools in the JDK to e.g. compile JSPs (Java Server Pages) into Java byte code. In that case it is not enough to run the server with the JRE. You must use the full Java SDK so the server has the extra tools from the Java SDK available.
Java Code Conventions
The Java Code Conventions are a set of conventions for how to format your Java code, and how to name classes, variables, files etc. Most of the time you do not have to follow these conventions, but most developers follow most of them.
Java Standard Edition (JSE)
Java has evolved into three different sets of APIs, or "profiles" as some like to call them:
- The Java Standard Edition for desktop and standalone server applications.
- The Java Enterprise Edition for developing and executing Java components that run embedded in a Java server.
- The Java Micro Edition for developing and executing Java applications on mobile phones and embedded devices.
The Java Standard Edition contains the basic Java APIs for standalone desktop and command line applications. There is both a JRE and JDK for the Java Standard Edition.
Java Enterprise Edition (JEE)
The Java Enterprise Edition contains a lot of extra tools and APIs for executing Java components inside a Java Enterprise Server. Examples of enterprise Java components are:
- Java Server Pages (JSP)
- Java Server Faces (JSF)
- Enterprise Java Beans (EJB)
- Two-phase commit transactions
- Java Message Service message queue APIs (JMS)
Please note, that the Java Enterprise Edition has been moved to its own project which is now independent of the core Java SDK. This has been done to make the Java platform smaller.
Java Application Servers
The Java Enterprise Edition (Jakarta EE) is only a specification. Software vendors like IBM, Oracle etc. are free to implement this specification. And they have. Their implementations are usually called Java Application Servers, because the servers are capable of running Java applications, while offering a lot of standardized services to these Java applications.
Java Micro Edition
The Java Micro Edition is a version of Java targeted at small and embedded devices like PDAs, mobile phones etc.
Today (2015) the most popular Java platform to develop on for mobile phones is Google's Android platform. Android does not use the Java Micro Edition, by the way. It uses its own subset of Java combined with a lot of Android specific components (APIs).
A Java Applet is a Java program that is downloaded and executed inside a web browser. Thus, Java Applets can be part of a web application.
Today (around 2020) most Java developers develop on the server side, on Java application servers, or other server side platforms like Vert.x or the Play framework. There seems to be something brewing around client side Java with JavaFX though. See next section.
JavaFX is a RIA (Rich Internet Application) framework. JavaFX started as alternative to Java Applets but with a lot more features, and with a completely different GUI API. JavaFX was inspired by Flex (Flash) and Silverlight for .NET (Microsoft). Both Flash and Silverlight has died, though. You can read more about JavaFX in my JavaFX Tutorial.
Java Developer Community
The Java Developer Community consists of all the many Java developers out there which participate in the debate about Java and its future. The Java developer community has developed a lot of open source APIs and products which greatly expands the ecosystem around Java.