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:
-
You write source code →
HelloWorld.java -
Compiler converts it into Bytecode →
HelloWorld.class -
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)
-
Download from Oracle JDK or OpenJDK.
-
Install it like a normal software.
Check installation:
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:
Step-by-step Explanation:
-
public class HelloWorld→ Defines a class namedHelloWorld. -
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:
-
Open IntelliJ IDEA and create a New Project → Java → Next → Finish.
-
Right-click the
srcfolder → New → Java Class → Name itHelloWorld. -
Paste the above code inside it.
-
Click the green Run button.
-
You’ll see:
5. Your First Interactive Java Program
Let’s take user input and display it back.
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
| Error | Reason | Fix |
|---|---|---|
Main method not found | Wrong method name or syntax | Ensure public static void main(String[] args) is exactly correct |
Cannot find symbol | Variable or method not declared | Declare variables before using them |
Class not found | Wrong filename or missing .class file | Save with the same name as the class |
7. Practice Tasks for You
-
Modify the “Hello World” program to print your name and age.
-
Write a program that takes two numbers from the user and prints their sum.
-
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
Post a Comment