Java Tutorial
- What is Java
- History of Java
- Features of Java
- C++ vs Java
- Hello Java Program
- Program Internal
- Program Internal
- JDK, JRE and JVM
- JVM: Java Virtual Machine
- Java Variables
- Java Data Types
- Unicode System
- Operators
- Keywords
Control Statements
- Java Control Statements
- Java If-else
- Java Switch
- Java For Loop
- Java While Loop
- Java Do While Loop
- Java Break
- Java Continue
- Java Comments
- Java Programs
Java Object Class
- Java OOPs Concepts
- Naming Convention
- Object and Class
- Method
- Constructor
- static keyword
- this keyword
Java Inheritance
- Inheritance(IS-A)
- Aggregation(HAS-A)
Java Polymorphism
- Method Overloading
- Method Overriding
- Covariant Return Type
- super keyword
- Instance Initializer block
- final keyword
- Runtime Polymorphism
- Dynamic Binding
- instanceof operator
Java Abstraction
- Abstract class
- Interface
- Abstract vs Interface
Java Encapsulation
- Package
- Access Modifiers
- Encapsulation
Java Array
- Java Array
Java Tutorial
Our Java programming tutorial is suitable for students and professionals. Java is a versatile, widely used programming language known for its object-oriented, class-based, concurrent, and secure features.
What is Java?
Java is a high-level, class-based, object-oriented programming language developed by Sun Microsystems (now owned by Oracle) in the year 1995. James Gosling is known as the father of Java. Before Java, its name was Oak. Since Oak was already a registered company, so James Gosling and his team changed the name from Oak to Java.
Here’s a breakdown of its key characteristics:
- High-Level: Java code resembles natural language, making it easier to read, write, and maintain compared to machine-level languages.
- Class-Based: Java revolves around creating classes, which act as blueprints for objects. Classes encapsulate data (attributes) and behavior (methods).
- Object-Oriented: In Java, everything is an object or a class. Objects represent real-world entities with properties and actions. Object-oriented programming promotes modularity, reusability, and maintainability of code.
- Platform-Independent (WORA – Write Once, Run Anywhere): Java code is compiled into bytecode, an intermediate format that can run on any platform with a Java Virtual Machine (JVM). The JVM translates bytecode into instructions specific to the underlying hardware, enabling Java applications to run on Windows, macOS, Linux, and more.
Java Example
Here’s a simple Java program that prints “Hello, World!”:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
This code is a simple Java program that prints “Hello, World!” to the console. Let’s break it down:
- public class HelloWorld: This line declares a class named ‘HelloWorld’. In Java, every application must have at least one class, and the filename must match the class name. In this case, the filename should be HelloWorld.java.
- public static void main(String[] args): This line defines the ‘main’ method, which serves as the entry point of the program. When you execute a Java program, it starts executing from the ‘main’ method. The ‘public’ keyword indicates that the method can be accessed from outside the class. The ‘static’ keyword means that the method belongs to the class itself, not to any specific instance of the class. The ‘void’ keyword indicates that the method doesn’t return any value. ‘String[] args’ declares a parameter named ‘args’, which is an array of strings. This parameter allows you to pass command-line arguments to the program.
- System.out.println(“Hello, World!”);: This line prints the string “Hello, World!” to the console. ‘System.out’ is an object that represents the standard output stream, and ‘println’ is a method of the ‘PrintStream’ class that prints the specified string followed by a newline character.
So, when you run this program, it will print “Hello, World!” to the console. It’s often used as a simple introductory example for learning a new programming language.’
Applications of Java
Java is used in a wide range of applications, including:
- Enterprise Applications: Java’s robustness and scalability are well-suited for large-scale, mission-critical business applications like banking systems, e-commerce platforms, and enterprise resource planning (ERP) software.
- Web Applications: Java, along with frameworks like Spring and JavaServer Faces (JSF), is a powerful tool for building web applications and web services.
- Mobile Applications: While not as dominant as Kotlin for Android development now, Java can still be used to create Android apps through frameworks like Java ME and the Android SDK (though primarily for legacy applications).
- Desktop Applications: Java can be used to develop cross-platform desktop applications with a rich user interface using toolkits like Swing and JavaFX.
- Embedded Systems: Java’s ability to run on constrained devices makes it suitable for developing applications for embedded systems like smart devices and industrial controllers.
- Scientific Computing: Java libraries like Apache Commons Math and Java Numerics provide tools for scientific and numerical computing.
- Big Data and Analytics: Java platforms like Hadoop and Spark leverage Java’s capabilities for processing large datasets.
- Machine Learning: Java libraries like TensorFlow and Weka facilitate machine learning development using Java.
Types of Java Applications
Java applications can be broadly categorized into:
- Standalone Applications: These are applications that run on a single computer and do not require a network connection. Examples include desktop applications and command-line tools.
- Web Applications: These are applications that run on a web server and are accessed through a web browser. Java Servlets and JavaServer Pages (JSP) are commonly used technologies for developing web applications.
- Enterprise Applications: These are large-scale applications that are used by organizations to manage their business processes. Java EE (Enterprise Edition) provides a set of specifications for developing enterprise applications.
- Mobile Applications: Java is used to develop applications for mobile devices, including Android and iOS. Java ME (Micro Edition) is specifically designed for mobile devices.
Java Platforms / Editions
Java has several editions, each tailored for different types of applications:
- Java SE (Standard Edition): This is the core Java platform and is used for developing standalone applications. It includes the Java Development Kit (JDK) and the Java Runtime Environment (JRE).
- Java EE (Enterprise Edition): This edition is used for developing large-scale, multi-tiered, scalable, reliable, and secure network applications. It includes APIs for web services, database connectivity, messaging, and more.
- Java ME (Micro Edition): Designed for embedded systems and devices with limited resources, such as mobile phones and set-top boxes.
- JavaFX: A software platform for creating and delivering desktop applications, as well as rich internet applications (RIAs) that can run across a wide variety of devices.