Java, a robust and widely-used programming language, offers a range of applications and is known for its versatility. When learning Java, it's helpful to explore practical examples to understand its syntax and functionality better. W3Schools provides an array of Java programs with their respective outputs, which can be a goldmine for beginners and seasoned developers alike.

Let's delve into some Java program examples from W3Schools, along with their outputs, to enhance your understanding and skill set.

Simple Java Programs
These programs demonstrate basic Java syntax and concepts.

First, let's look at a simple "Hello, World!" program.
Hello, World!

The following code prints "Hello, World!" on the console.
```java public class Main { public static void main(String[] args) { System.out.println("Hello, World!"); } } ```
The output of this program is:
```bash Hello, World! ```
Data Types & Variables

This program showcases different data types and variables in Java.
```java public class Main { public static void main(String[] args) { int myAge = 30; double mySalary = 40000.50; String myName = "John"; System.out.println(myName + " is " + myAge + " years old."); System.out.println("He earns " + mySalary + " per year."); } } ```
The output of this program is:
```bash John is 30 years old. He earns 40000.5 per year. ```
Control Structures

Java's control structures allow us to control the flow of our programs.
Let's explore an example of an if-else statement.



















IF-ELSE Statement
This program checks if a number is positive, negative, or zero.
```java public class Main { public static void main(String[] args) { int num = -5; if (num > 0) { System.out.println(num + " is positive."); } else if (num < 0) { System.out.println(num + " is negative."); } else { System.out.println(num + " is zero."); } } } ```
The output of this program is:
```bash -5 is negative. ```
For Loop
The following program prints the numbers 1 to 5 using a for loop.
```java public class Main { public static void main(String[] args) { for (int i = 1; i <= 5; i++) { System.out.println(i); } } } ```
The output of this program is:
```bash 1 2 3 4 5 ```
To fully master Java, it's crucial to practice more examples like these. W3Schools offers an extensive collection of Java programs, along with their outputs, to help you learn and understand concepts better.
So, start exploring, writing, and running your own Java programs today. The more you practice, the more proficient you'll become, and before you know it, you'll be developing impressive Java applications.