Few pieces of technologies have the impact Java has created on the industry. From the early days of the internet to the era of cloud computing, it is never late to learn and master this programming language.
These Java tutorials will help you understand what sets Java apart from the rest of the pack and how to get started with it.
What Is Java?
Java is a programming language originally created by James Gosling when he worked at Sun Microsystems in 1995. Oracle assumed its development when it acquired Sun Microsystems in 2010.
The Java language is the core of the software development platform of the same name, which allows developers to create applications written in Java and able to run on various platforms.
Important Characteristics Of Java
Compared to other programming languages, Java has several advantages that have helped it earn widespread adoption in the industry.
If you are coming from other high-level languages like C/C++, Java offers a more cleaned-up syntax. There is no need to declare the header files or carry out pointer arithmetic.
Object-oriented programming (OOP) is at the core of the Java language. Many places choose Java to teach programming as this language provides a great introduction to OOP.
Java can sandbox your applications by running them in a dedicated virtual machine. Programs in this execution environment can’t reach other parts of the system. This actually contributed a big part to the early success of Java, when downloading programs from the internet was a huge concern.
Java’s original slogan was Write once, run anywhere (WORA). You can expect your programs to run on any device as long as they can run a Java virtual machine (JVM).
You don’t need to spend much effort adjusting your code to different systems since Java is platform-independent and architecture-neutral. With the presence of the runtime system, the compiled code can be easily interpreted and translated into native machine code at runtime.
Modern software development pays more attention to concurrency because computer systems have faster processors with more cores. Java supports this out of the box and makes it quite manageable, even though concurrent programming isn’t easy to master.
Before getting started with your first Java programs, make sure to familiarize yourself with these fundamental concepts. You will run into them frequently when learning and writing in Java.
Java Virtual Machine (JVM)
To make Java platform-independent, you don’t need to compile your program to native executable code. Instead, your Java code will be turned into bytecode.
This is a special instruction set designed to be run inside a Java virtual machine. As the name suggests, it is a virtual machine running on top of your operating system. Part of a runtime environment, It is what executes the Java bytecode.
There are plenty of JVM implementations. You can use any of them to run Java programs as long as they follow the JVM specification. The official (reference implementation) is HotSpot, which is developed by Oracle.
Java Runtime Environment (JRE)
A JRE consists of a JVM, the class loader, class libraries, and other runtime utilities.
It combines the bytecode produced from a Java program with the required libraries before creating a JVM instance to execute the resulting code. Like JVMs, there are plenty of JRE options you can install.
Java Development Kit (JDK)
This is the set of tools for creating Java applications. The official JDK distribution from Oracle is based on the open-source implementation OpenJDK.
As a beginner to Java programming, you will need to install a JDK and an IDE (integrated development environment).
You can use the free OpenJDK installers and similar implementations. They don’t require you to sign an agreement or create an account like Oracle’s commercial builds.
Many distributions have binary packages for OpenJDK that you can install with their package manager.
sudo apt install default-jdk
sudo dnf install java-latest-openjdk.x86_64
sudo pacman -S jdk-openjdk
You can use the java formula from Homebrew to install the latest version of OpenJDK:
brew install java
Go to https://jdk.java.net/ and select the latest stable version (19, as of right now). Download the zip file for Windows, extract it, and follow the instructions inside.
There are plenty of great free IDEs that provide excellent support for Java programming:
- IntelliJ IDEA (Community Edition)
In this tutorial, we use the free version of IntelliJ IDEA. Go to https://www.jetbrains.com/idea/download/
and click the Download button for the Community edition. The download will automatically start, wait for it to complete, and follow the instructions of the installer.
We will show you how to create a Java program with IntelliJ IDEA.
Open the program, and from the menu, select File > New > Project…
Name your project and select the directory to save it. Make sure the Language and Build system sections are set to Java and IntelliJ, respectively. The IDE should automatically detect the available JDK installation on your system and show it in the JDK section.
Click Click. IntelliJ IDEA will automatically create a file named Main.java.
Type in this snippet if the file doesn’t already have it:
On the menu, select Run > Run ‘Main.java’ (or select the right arrow icon on the toolbar) to compile the code and run the resulting program in a terminal at the bottom of the window.
You should see this line in the output:
Basic Java Syntax
The Hello world program demonstrates how a class declaration works, including some basic elements of Java syntax.
This public keyword defines the scope of the class Main, making it “public” and accessible to all other classes.
In its body, we declare the method main – the most important method in Java. It is the entry point of every Java program and takes a String array as its sole argument. When running a Java program, the runtime will look for this method and will throw an error if it isn’t found.
This method needs to be public so the JRE can execute it. The static keyword indicates that this method belongs to the class Main itself, not an instance of that class. As a result, you don’t need to create an instance of Main in order to invoke the main() method. The void keyword means the method shouldn’t return anything.
By using System.out.println, we are using the println() method of System.out to write into the standard output stream.
Java Tutorials – Summary
- Could not reserve enough space for 2097152kb object heap
- Java Was Started But Returned Exit Code=13 Error In Eclipse
- Exception in Thread “Main” Java.util.nosuchelementexception
- ERROR : ‘compileJava’ task (current target is 11) and ‘compileKotlin’ task (current target is 1.8) jvm target compatibility should be set to the same Java version in Java
- java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment
- Error: Non-static Variable/Method ‘#’ Cannot be Referenced from a Static Context
- How To Fix “Failed to introspect Class [org.springframework.security.config.annotation. web.configuration.WebSecurityConfiguration]”
- How To Fix “org.springframework.core.io.buffer. DataBufferLimitException: Exceeded limit on max bytes to buffer”
- How To Fix “Unrecognized option: –add-opens = jdk.compiler / com.sun.tools.javac.code = ALL-UNNAMED” In Java IntelliJ IDEA
Java is a popular object-oriented language that you can use to develop a wide array of cross-platform applications. Your code will be translated to Java bytecode, which the JRE on the end-user system will run.
Follow Java tutorials on our website to learn more about this programming language and its features.
My name is Robert. I have a degree in information technology and two years of expertise in software development. I’ve come to offer my understanding on programming languages. I hope you find my articles interesting.
Name of the university: HUST