This article aims to give you an overview of Java as a programming language and a step-by-step guide on setting up your local machine to run Java programs.
What is Java?
Java is an Object-oriented general-purpose programming language intended to let programmers write once, run anywhere (WORA). This means that compiled Java code can run on all platforms that support Java without the need to recompile. It is widely used in the development of web apps, mobile apps, and enterprise software.
Basic Concepts of Java Programming.
The following are just a few of the basic concepts of Java programming. There are many more, such as data types, control structures, arrays, and strings, that are essential for writing Java programs.
Object-oriented programming (OOP): Java is an object-oriented programming language, which means that it is based on the concept of objects. Objects are instances of classes, and they have properties (attributes) and behaviors (methods).
Platform independence: Java code can run on different platforms (operating systems) without any modifications, thanks to the Java Virtual Machine (JVM).
Syntax: Java has a syntax that is similar to other programming languages like C++ and C#. It uses curly braces {} to denote code blocks and semicolons; to separate statements.
Memory management: Java has automatic memory management, which means that the programmer does not have to worry about allocating and deallocating memory for objects. The JVM takes care of this task.
Exception handling: Java has a robust exception-handling mechanism that allows the programmer to handle errors and unexpected events gracefully.
Multithreaded − With Java's multithreaded feature, it is possible to write programs that can perform many tasks simultaneously. This design feature allows the developers to construct interactive applications that can run smoothly.
Interpreted − Java is both compiled and interpreted. Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development process is more rapid and analytical since the linking is an incremental and lightweight process.
High Performance − With the use of Just-In-Time compilers, Java enables high performance.
Distributed − Java is designed for the distributed environment of the internet.
Dynamic − Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment. Java programs can carry an extensive amount of run-time information that can be used to verify and resolve accesses to objects on run-time.
Prerequisites
Although this is targeted at beginners, readers should have reasonable exposure to any programming environment and knowledge of basic concepts such as variables, commands, syntax, etc.
Computer with a minimum of 64 MB of RAM (128 MB of RAM recommended).
Linux 7.1 or Windows 10/11 operating system
Any code editor. IntelliJ IDEA is preferred for beginners.
Enviroment setup
- JDK Download: The JDK includes both a Java Runtime Environment (JRE) and a Java Virtual Machine (JVM). it also includes programming tools, like a compiler and a Java web server, for programmers who need to install Java on Windows. You need to have at least 500 MB of hard drive space for both the download and installation
Download JDK here and get your OS (Operating System) selection tab.
Run the Java installation wizard and install
Add the Java binary files directory to the path of the environmental variables.
Go to the directory where you have installed the installer earlier. In this case, the default directory is always the C drive.
Go into the Program Files folder.
Go into the Java folder.
Go into the
jdk-17
folder. Here,17
represents the JDK version. In your case, the version might be different as the JDK will get updated in the future, but the process is the same.Go into the bin folder.
The binary files are kept here.
Copy the directory path (directory address) of this folder.
Go to Environment Variables.
Select the Path and click Edit.
Click New.
Paste the directory path.
Click OK.
Confirm Java was installed correctly.
Open the terminal (CMD or Powershell).
Type
java --version
If it provides the version you have just installed, then you are good to go!
Run your first Java program.
Open a code editor and write your first program
Compile your program using
javac Main.java
.Run your program class file using
java Main
.
Great news! Your machine is now fully equipped to execute any Java programs flawlessly.