Skip to content
C

Introduction to Java

Java is a programming language that lets you write instructions a computer can follow to solve a problem or run an application.


1. What is Java?

Java is a programming language that lets you write instructions a computer can follow to solve a problem or run an application. It was built to be simple to read, safe to use, and able to run on almost any device without changes to the code. Today, Java powers everything from Android apps to banking software to large enterprise systems.

2. Why is it used?

Companies choose Java because one Java program can run on Windows, Linux, or Mac without being rewritten. It also has strong safety checks built in, a huge collection of ready-made tools (called libraries), and a massive community, so help is always available when you get stuck.

3. Real-Life Example

Think of Java like a universal remote control. A normal remote only works with one brand of TV, but a universal remote works with almost any TV brand. In the same way, a Java program, once written, can run on almost any computer or device that has Java installed.

4. Syntax

java
// A Java program always starts inside a class public class MyFirstProgram { public static void main(String[] args) { // instructions go here } }

5. Example Program

java
public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } }

Output:

Welcome to Java!

6. Key Points to Remember

  • Java is a general-purpose, object-oriented programming language.
  • "Write once, run anywhere" is Java's biggest selling point.
  • Java is used in mobile apps, web servers, desktop software, and more.

Practice Problems

Try each question yourself first, then check the answer.

1. Explain the slogan

In one sentence, explain what "write once, run anywhere" means and name the component that makes it possible.

Answer: You compile a Java program once into bytecode, and it then runs on any device that has a JVM. The JVM is the component that provides this portability.

2. Predict the output

java
public class Main { public static void main(String[] args) { System.out.println("Java"); System.out.println("powers Android apps"); } }

What exactly is printed?

Answer: Two lines:

Java
powers Android apps

3. Spot the mistake

A beginner writes their print statements straight into a file with no class around them, and the program will not compile. Which rule did they break?

Answer: Every Java instruction must live inside a class. A Java program needs at least one class, and execution begins in a main method inside it.

4. Recall

Name three real-world areas where Java is used, as mentioned in the notes.

Answer: Any three of: Android apps, banking software, large enterprise systems, desktop software, web servers.

Mock Tests

  • Introduction to Java - Quick Test

    A quick 4-question check on Java basics — what Java is, classes, the JVM and the program entry point.

    4 questions · 10 min · Easy
    Start Mock Test
  • Introduction to Java - Quick Test

    10 questions on what Java is, why it is used, and how a Java program is shaped.

    10 questions · 10 min · Easy
    Start Mock Test

Coding Problems