Update appNew update is available. Click here to update.
Last Updated: Sep 6, 2023

Java Tutorial


Java is a versatile and widely-used programming language known for its platform independence, making it compatible with various devices and operating systems. It's renowned for its strong security features, making it a popular choice for building robust and secure software applications. Java's extensive libraries and active developer community contribute to its enduring popularity in web development, mobile apps, and enterprise-level software.

java tutorial

If you're new to programming or want to broaden your skill set, this article will be a valuable resource for helping you understand the strength of Java.

This article will examine the core ideas behind the Java programming language, its advantages, some of the tools and frameworks that Java programmers frequently use, and some tips for beginners.

Also read, Duck Number in Java and Hashcode Method in Java.

What is Java?

Java is a high-level, object-oriented programming language commonly used to create software, video games, and mobile apps. It can function on any device running a Java Virtual Machine (JVM), regardless of the operating system.

It offers built-in functions that lessen programming errors and facilitate software development.

Java Example

Here's a simple Java program example:


This code asks the user to type their name before displaying a customised greeting.

import java.util.Scanner;
public class Main
public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Please enter your name: ");
        String name = input.nextLine();
        System.out.println("Hello, " + name + "!");


Please enter your name: John
Hello, John!


This code is a straightforward Java program that asks users for their names before addressing them by name. Next, the "Please enter your name:" string is printed to the console using the "print" method. The next step is to read a line of text the user enters and store it in the String variable "name" using the Scanner class' "nextLine" method. The program then prints a customised greeting to the console using the user's name, entered earlier, using the "println" method.

Also read, Swap Function in Java

History of Java

Java is a programming language that James Gosling and his team at Sun Microsystems created in the middle of the 1990s. It was initially developed for consumer electronics but later gained popularity for web applications and business software.

Java's "write once, run anywhere" guiding principle made it portable and platform-adaptable. Oracle now owns it, and many applications are developed using it.

How Java Works?

Java works by using a two-step process: compilation and execution. First, the Java source code is written and saved in files with a ".java" extension. Then, a special program called the Java Compiler translates this source code into a format called bytecode, which is platform-independent.

When you want to run a Java program, a software component called the Java Virtual Machine (JVM) takes over. The JVM interprets or compiles the bytecode into machine-specific code, allowing it to run on any device or operating system with a compatible JVM. This "write once, run anywhere" approach makes Java versatile and popular for creating cross-platform applications, from web apps to mobile and desktop software.

Features of Java

Here are some features of Java:

  1. Programmers can create objects with data and functions using Java, an object-oriented language.
  2. Java programs can be run on any computer with a Java Virtual Machine (JVM) regardless of the hardware or software configuration.
  3. Manual allocation and deallocation are unnecessary because Java's garbage collector automates memory management.
  4. A built-in mechanism for handling errors called exceptions enables Java programmes to recover from mistakes and continue running gracefully.
  5. Java supports concurrent programming, enabling the simultaneous operation of multiple threads.
  6. Platform independence is maintained while high performance is made possible by Java's just-in-time (JIT) compiler.

Applications Of Java 

Here are some concrete examples of Java applications:

  • Java's scalability and robustness make it a popular choice for creating large-scale enterprise applications.
  • Java can be used to create IoT applications because it offers excellent network connectivity support.
  • Due to its performance, scalability, and cross-platform support, Java is a popular choice for Big Data technology.
  • Due to its capacity for handling sophisticated graphics and sound, Java has been demonstrated to be an excellent platform for creating gaming applications.
  • Because it offers excellent support for network programming and server-side development, Java is frequently used for creating APIs.
  • Java is a great option for creating messaging applications because it strongly supports messaging systems.
  • Java offers robust web development support, including web servers.

Types of Java Applications

Here are some types of Java applications:

Web Development

Java is used to build dynamic and interactive websites and web applications. Popular Java web frameworks like Spring and JavaServer Faces (JSF) simplify web development.

Mobile Apps

Java is a primary language for developing Android apps. Android Studio, the official Android development environment, uses Java extensively.

Desktop Applications

Java's rich graphical libraries enable the creation of cross-platform desktop applications. JavaFX and Swing are commonly used for this purpose.

Enterprise Software

Java is a staple in building large-scale enterprise applications. It's known for its reliability, scalability, and compatibility with various databases and servers.

Game Development

Java is used for developing 2D and 3D games. Game engines like LibGDX and jMonkeyEngine are popular among Java game developers.

Big Data Processing

Hadoop, a widely used framework for processing big data, is built in Java. It's employed for tasks like data analysis and processing massive datasets.

Characteristics of Java

Here are some characteristics of Java:

  1. Simple: Java is designed to be easy to learn and use, with a straightforward syntax and a consistent programming model.
  2. Secure: Java's robust security model allows code from untrusted sources to be safely executed.
  3. Portable: Java code can be created once and executed anywhere, making switching between hardware platforms and operating systems simple.
  4. Robust: Java's robust type-checking system and automatic memory management avoid common programming errors like memory leaks and null pointer exceptions.

Versions of Java

New versions of Java are consistently being released as it continues to develop. Every new version typically keeps backward compatibility with previous versions while adding new features and improvements.

Since its initial release in 1996, Java has undergone several revisions, adding new functions and improvements. Java 1.0, Java 2, Java 5, Java 8, Java 11 (LTS), and Java 12–18 are notable versions.

Java 1.0: Platform independence, automatic memory management, and rubbish collection were just a few of the crucial features that Java 1.0 introduced.

Java 2: The Swing GUI toolkit, Java Naming and Directory Interface (JNDI), and Java Database Connectivity (JDBC) API are just a few of the new features that came with Java 2.

Java 5: With Java 5, new language features like generics, annotations, and autoboxing were available.

Java 8: Introduced several significant new features, including lambda expressions and the recent Date & Time API. It also included improvements to security and performance.

Java 11 (LTS): It included several critical new features, such as the HttpClient API for making HTTP requests, improvements to the garbage collector, and support for Unicode 10.

Java 12-18: These releases have introduced various new features and improvements, including switch expressions, improved error messages, and new APIs for working with collections. 

Functions in Java

Functions are referred to as methods in Java. A method in Java is a group of instructions that carry out a particular function. A method is a small program that the main program can call whenever required. Methods can process inputs, and results can be returned afterwards. They are used to make the code simpler.

Let's see some of the functions of methods in Java

  • Reusability: methods can be used in different places in the program making the program looks modular 
  • Abstraction:  methods can hide the complex details so that code looks redable and easy to understand 
  • Encapsulation: methods are used to encapsulate the data making the code secure.
  • Extensibility: methods can be extended to add new functionality

Java Platforms

Java is a general-purpose programming language that provides a variety of platforms for developing and running applications, each with its own set of APIs and tools to meet particular application requirements.

  1. Java SE, the familiar environment for developing and running Java applications on desktops and servers, is one of these platforms.
  2. Suitable for enterprise-level applications is Java EE.
  3. Software for embedded systems and mobile devices is created using Java ME.
  4. Rich client applications for multimedia are made using JavaFX.
  5. Apps for Android-based devices are created using Android.

Java SE 

let's describe it in main points :

  • Java SE is known as Standard Edition.
  • Java SE is the core of the Java programming language.
  • It is used to develop applications for a wide variety of devices, including desktops, laptops, servers, and mobile devices. 
  • Java SE includes a comprehensive set of APIs for networking, database access and user interface development to name a few.

Java EE 

let's describe it in main points :

  • Java EE also Java Platform Enterprise Edition. 
  • A platform for creating and deploying enterprise applications.
  • It includes a set of APIs for web development, messaging, security, and more. 
  • Mostly it is used by the business to build scalable, reliable and secured web applications.

Java ME 

let's describe it in main points :

  • Java ME is a framework also known as Micro Edition. 
  • It is used for creating and releasing software for smaller devices like mobile phones and set-top boxes. 
  • Java ME includes a subset of the Java SE APIs and some APIs for specific devices. 
  • Java ME is used by businesses to develop applications that can be run on a variety of small devices.


let's describe it in main points :

  • JavaFX serves as a platform to develop rich internet applications(RIAs). 
  • RIAs are online applications that communicate with users through a graphical user interface (GUI).
  • JavaFX includes a set of APIs for GUI development and also has APIs for multimedia and animation. 
  • Businesses use JavaFX to create e interesting and interactive Rich Internet Applications (RIAs).

Java Classes (OOPs)


A class in Java is a blueprint or a template for creating objects. It represents an abstract concept or idea and defines the attributes (data) and behavior (methods) that the objects of the class will have. A class can have various fields, methods, constructors, and access modifiers. The state and behavior of an object are specified by its class.

A class in Java is similar to a recipe that outlines how to build objects. A class lists fields (the ingredients) and methods (the instructions) for creating objects, just like a recipe lists ingredients and directions for preparing a food item.


An object in Java is a particular instance of a class. When a class is defined, you can use that class to create multiple objects with the same structure and behavior.

An object in Java is similar to a physical object with unique properties and capabilities. Each object has a state represented by the contents of its fields, and it is possible to manipulate that state using the methods defined by the class. An object in Java is something that possesses both data and behavior. Fields are used to represent the data, and methods are used to describe the behavior. We use objects to represent these entities in code to write programs that interact with real-world entities in a structured manner.


constructor is a unique way to initialize an object's properties in Java. The constructor is automatically called when a new class object is created to set the object's initial state. It may accept parameters for other initialization tasks, such as initializing the object's fields. A constructor is a recipe for producing an object of a specific type. It instructs Java on constructing the object and what default values to assign to each property. Java automatically creates the object and sets its initial values when you create an object with the new keyword.


Inheritance in Java refers to the capacity to build new classes on top of pre-existing ones. The superclass's code may be reused by the subclass, which may also add additional properties and methods as necessary. This can make the code easier to maintain, reduce duplication, and increase reusability. The class that inherits from the parent class is called the superclass, and the class that inherits from the child class is called the subclass. Java uses inheritance to establish hierarchical relationships between classes to organize your code and reuse pre-existing functionality.


In Java, the idea of abstraction states that you should concentrate on an object's core characteristics rather than the specifics of how it was implemented. In other words, you shield the user from unnecessary information while exposing only the essential implementation details. As a result, code is made simpler and more straightforward to use and understand.


In Java, it refers to an object's capacity to adopt various forms or carry out multiple functions depending on the context of usage. This idea is made possible by inheritance and method overriding, which allows a subclass to provide a different implementation of a method defined in a superclass. Because objects from other classes can be treated as belonging to a single superclass when using polymorphism, more generic code that can handle various object types can be written.


In Java, encapsulation combines data and code into a single unit while preventing access or modification by outside code. Put another way; it means limiting access to only what is required and concealing the user from the user's code complexity. Encapsulation helps in keeping the code organized, maintainable, and secure.

Java Frameworks

There are many popular frameworks for Java that developers can use. Several of the most well-liked Java frameworks include


 A Java framework frequently used to create business applications. Model-view-controller (MVC) architecture, dependency injection, and other features provided by Spring make it possible to build dependable applications.


Java programmers can map Java objects to relational database tables using the Object-Relational Mapping (ORM) framework Hibernate. This streamlines the data persistence process and makes working with databases in Java applications easier.


A Java web application framework built on the Model-View-Controller (MVC) design pattern. It offers a collection of tools and resources that can be used to quickly and effectively build web applications.


A Java testing framework that allows writing and running unit tests for Java code. JUnit comes with various tools and utilities for assessing Java code and ensuring it functions as intended.

These are some of the most well-known and frequently used Java frameworks, though many more can be used for different purposes.

Advantages Of Java

Here are some of the advantages of Java:

  1. Efficiency: Java programs can carry out complicated tasks quickly and effectively without burdening the system's resources. Thanks to its scalability and low latency, Java can handle numerous users or requests simultaneously without compromising performance. Java can run complex and large-scale programs smoothly and quickly.
  2. Cross-platform compatibility: Java-written code can be used without modification on any platform or operating system. This is possible due to the Java Virtual Machine's ability to interpret Java code after it has been compiled into bytecode (JVM). The same Java code can run on a given platform without recompiling as long as the JVM is accessible. It results in developers being able to write code once and run it across various platforms, saving time and effort.
  3. Safety: Security is a priority in the design of Java. It has features that ensure the code being executed is secure and untainted. It also supports digital signatures and encryption, which helps protect sensitive data in enterprise applications.
  4. Garbage Collection: Java does not require programmers to manually allocate and deallocate memory because the program automatically controls how much memory newly created objects use. This makes programming simpler and less prone to errors while preventing memory leaks.

Limitations Of Java

Although Java is a widely used and well-liked programming language, it has shortcomings. These are a few of Java's shortcomings.

  1. In Java, giving new meanings to the well-known operators +, -, *, /, etc., is impossible. This implies that you cannot define particular behavior for them when these operators are applied to objects of your classes. Writing expressive and understandable code can be more difficult in some circumstances.
  2. A virtual machine must first translate Java programs into machine code before they can be executed. The program is then run afterward. This process could make Java programs slower than C or C++, which are compiled straight into machine code. Java programs take longer to start up or complete specific tasks, which, in some cases, can be a performance constraint.
  3. It is more challenging to write code that generates other code or perform meta-programming tasks where runtime code is developed in Java because of its limited support for macros. This might be a limitation for particular applications that require these features, such as code generators.

It's important to note that many of these restrictions are not specific to Java and that each programming language has advantages and disadvantages.

Frequently Asked Questions

What is Java?

Java is a computer programming language intended to be safe, simple, and compatible with various devices. It includes many built-in tools that make programming quicker and simpler. Many websites, apps, and computer programs are created using Java.

What are the three types of Java?

Standard Edition (SE), Enterprise Edition (EE), and Mobile Edition (ME) are the three main editions of Java (Micro Edition). Java EE builds on Java SE for large-scale enterprise applications, Java ME is for building applications on small devices with limited resources, and Java SE provides the core language and libraries for desktop and server-side applications.

How to do Java programming?

To do Java programming, you basically need an IDE or a text editor to write the code and then execute it using the JVM (Java virtual machine) but before that, the code needs to get compiled using the Java compiler.

Where do I write Java code?

You can write Java code using any text editor, but it is preferred to switch to some IDEs like Eclipse or Visual Code Studio as they provide many features that make programming easier. 


We've discussed a lot of crucial facets of the Java programming language in this article. It also emphasizes why it is such a popular programming language. As we've seen, Java is a robust language for creating complex applications because it includes advanced features like inheritance, polymorphism, and multithreading. We reviewed its main advantages, drawbacks, and applications in various fields. In conclusion, this article thoroughly overviews Java, covering everything from its fundamental topics to more complex subjects.

Next article
Is Java an Object-Oriented language?