Getting Started with Java – Setup & Your First Program

 

1. Introduction – Why Java?

Java is one of the most popular programming languages in the world.
It’s used to create:

  • Mobile Apps (especially Android)

  • Web Applications

  • Desktop Software

  • Games

  • Enterprise-level applications

Why beginners love Java:

  • Platform Independent – Code runs anywhere (Write Once, Run Anywhere).

  • Easy to Learn – Syntax is simple and close to English.

  • Huge Community – Tons of tutorials, forums, and help available.


2. How Java Works (In Simple Words)

When you write Java code:

  1. You write source codeHelloWorld.java

  2. Compiler converts it into BytecodeHelloWorld.class

  3. Java Virtual Machine (JVM) runs the bytecode on any OS

This is why Java runs on Windows, Mac, Linux, and Android without changes.


3. Setting Up Java on Your Computer

Step 1: Install Java JDK (Java Development Kit)

Check installation:

java -version

If it shows a version number, you’re ready to go! ✅


Step 2: Install an IDE (Integrated Development Environment)

An IDE makes coding easier with features like syntax highlighting, auto-complete, and debugging.

Recommended IDEs:


4. Your First Java Program – “Hello World”

Here’s the simplest Java program:

public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }

Step-by-step Explanation:

  • public class HelloWorld → Defines a class named HelloWorld.

  • public static void main(String[] args) → The starting point of any Java program.

  • System.out.println("Hello, World!"); → Prints text to the console.


How to Run This Program in IntelliJ IDEA:

  1. Open IntelliJ IDEA and create a New Project → Java → Next → Finish.

  2. Right-click the src folder → New → Java Class → Name it HelloWorld.

  3. Paste the above code inside it.

  4. Click the green Run button.

  5. You’ll see:

Hello, World!

5. Your First Interactive Java Program

Let’s take user input and display it back.

import java.util.Scanner; public class GreetUser { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter your name: "); String name = sc.nextLine(); System.out.println("Hello, " + name + "! Welcome to Java."); } }

How it works:

  • Scanner → A class used to take input from the user.

  • nextLine() → Reads a line of text from the console.

  • + → Used to join (concatenate) strings.


6. Common Beginner Errors & Fixes

ErrorReasonFix
Main method not foundWrong method name or syntaxEnsure public static void main(String[] args) is exactly correct
Cannot find symbolVariable or method not declaredDeclare variables before using them
Class not foundWrong filename or missing .class fileSave with the same name as the class

7. Practice Tasks for You

  1. Modify the “Hello World” program to print your name and age.

  2. Write a program that takes two numbers from the user and prints their sum.

  3. Write a program that greets the user based on the time of day (Morning, Afternoon, Evening).


8. What’s Next?

In Blog 2, we’ll explore:

  • Variables & Constants

  • Data Types

  • Operators

  • Taking user input in more detail


💡 Tip: Practice typing code yourself instead of just copy pasting your fingers will learn faster than your eyes

Comments

Popular posts from this blog

Java for Beginners – Control Flow in Java Decisions & Loops

Understanding OOP -Inheritance, Polymorphism, Encapsulation

Java for Beginners – Functions & Object-Oriented Basics