Welcome to Java
Why Java? Why now? And your first compiled program
Quick check before you start: Can you explain what a compiler does? If not, that is fine — read on. If you can, skip to Your First Java Program.
After this lesson, you will be able to:
- Explain the difference between compiled and interpreted languages
- Describe what the JDK, JRE, and JVM do and how they relate
- Write, compile, and run a Java program with a proper class and main method
- Apply the IPO-CDS framework to break down any programming problem
What Are You Actually Learning This Quarter?
In CSCD 110, you learned to think like a programmer. You wrote Python code that solved problems — calculating tips, checking if a year is a leap year, finding averages.
Here is the secret no one told you: Python was holding your hand.
Not because Python is bad — it is brilliant for what it was designed to do. But Python made many decisions for you automatically. It figured out what type a variable was. It decided when to convert between numbers and text. It ran your code immediately, line by line, without asking questions.
This quarter, you are going to learn a different way to program. Java will force you to be explicit about everything:
- What type is this variable?
- What exactly does this code do?
- What happens if someone tries to store text in a number?
This seems annoying at first. And honestly? It kind of is — for about two weeks. Then something clicks. The compiler becomes your safety net. It catches bugs before your program ever runs, not after.
From CSCD 110: In Python, you wrote
age = 25and Python figured out it was a number. In Java, you must sayint age = 25;— you declare the type upfront. Yes, it is more typing. But now the compiler can tell you immediately if you accidentally try to treatageas text.
This is not a Java course. It is a computer science course that uses Java as its vehicle. The destination is problem-solving: taking a real-world question and translating it into precise, unambiguous instructions that a computer can execute.
Why Java? Four Reasons
You might wonder: “I already know Python. Why learn another language?” Fair question. Here are the answers:
1. Java is everywhere
Android apps. Enterprise backend systems. Financial trading platforms. Scientific computing. Java has been one of the top three most-used programming languages for over 25 years. When you learn Java, you learn a language that employers value.
2. Java teaches type discipline
Python lets you put anything in a variable. Java demands that you declare the type first. This forces you to think carefully about your data before you write logic.
In a small Python script, flexibility is nice. In a 100,000-line codebase maintained by a team of 20 engineers, Java’s strictness prevents entire categories of bugs.
3. Java is a stepping stone
The concepts you learn in Java — strong typing, compilation, object-oriented programming — transfer directly to C#, C++, Kotlin, Swift, and many other languages. Python is excellent for scripting and data science. Java prepares you for systems programming and the deeper CS curriculum.
4. Platform independence
Java’s promise is “write once, run anywhere.” You compile your code once, and the resulting bytecode runs on any machine — Windows, Mac, Linux — as long as the Java Virtual Machine (JVM) is installed.
Compiled vs. Interpreted: The Big Shift
One of the biggest changes from CSCD 110 is how your code gets executed.
In Python, the process was invisible: you wrote a .py file, ran it, and saw output. Behind the scenes, the Python interpreter read your code line by line and executed each line immediately.
Java works differently. There is an extra step between writing code and running it: compilation.
The Python Workflow (CSCD 110)
- Write your code in a
.pyfile (e.g.,hello.py) - Run it:
python hello.py - The Python interpreter reads each line and executes it immediately
- You see output
This is called interpretation. The interpreter translates and executes your code on the fly, line by line.
The Java Workflow
- Write your code in a
.javafile (e.g.,Hello.java) - Compile it:
javac Hello.java - The compiler checks your code for errors and translates it into bytecode (a
.classfile) - Run it:
java Hello - The Java Virtual Machine (JVM) executes the bytecode
- You see output
This is called compilation. The compiler translates your entire program before it runs, catching syntax errors and type mismatches at compile time rather than at runtime.
The trick: Think of Python as a live translator at a conference — translating each sentence as the speaker says it. Java is like a published translation — the entire book is translated once (compilation), and then anyone who reads the target language (the JVM) can read it. The upfront translation takes time, but you only do it once, and the result is portable and pre-checked for errors.
The Three Layers: JDK, JRE, JVM
When people say “install Java,” they usually mean install the JDK. But there are actually three nested layers to understand — like Russian nesting dolls.
JVM — Java Virtual Machine
The JVM is the engine that runs your bytecode. It is called “virtual” because it is not a physical processor — it is a software layer that simulates a standardized computer.
Every operating system has its own JVM implementation (Windows, Mac, Linux), but they all understand the same bytecode. This is the key to Java’s portability.
JRE — Java Runtime Environment
The JRE is the JVM plus the standard library — the collection of pre-built classes like String, Scanner, Math, and thousands of others. If you only want to run Java programs, the JRE is sufficient.
JDK — Java Development Kit
The JDK is the JRE plus developer tools: the javac compiler, the debugger, documentation tools, and more. If you want to write and compile Java programs, you need the JDK.
Watch out: Students sometimes think “compilation” means the program is running. It does not. Compilation is a translation step. If your code compiles successfully, it means the syntax and types are correct — but it does not mean the program does what you want. You still need to run the bytecode and test the output.
Your First Java Program
Every Java program lives inside a class. The execution starts in a special method called main. Here is the classic first program:
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
If you run this program, it prints:
Hello, World!
That is it. Five lines of code, and you have a working Java program.
File Name Requirement
The file name must match the class name. If your class is named Hello, the file must be Hello.java. This is a hard requirement in Java.
Anatomy of “Hello, World!”
Let us examine every piece of our first program, piece by piece:
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
public class Hello
public— The class is accessible from anywhereclass— This declares a class, which is a blueprint for creating objects (you will learn more about this in Week 9)Hello— The name of the class. The file must be namedHello.java
public static void main(String[] args)
public— The method is accessible from anywherestatic— The method belongs to the class, not to any specific object (we will explain this in Week 9)void— This method does not return a valuemain— The name of the method. The JVM looks for this specific method as the entry point(String[] args)— The parameters the method accepts. This is an array of Strings (we will cover arrays later). For now, just know this is required.
System.out.println("Hello, World!");
System— A built-in Java class that provides access to system resources.out— An object insideSystemthat represents the standard output stream — the console.println()— A method that prints text followed by a newline"Hello, World!"— A String literal: a piece of text enclosed in double quotes;— The semicolon marks the end of the statement. Every statement in Java ends with a semicolon.
println stand for?println stands for "print line" — it prints the text and then advances to the next line. You will learn about print (without ln) in the next lesson — it prints without advancing to the next line.
public class Hello, the file must be Hello.java. This is enforced by the compiler.
The Development Workflow
In this course, we use VS Code as our editor and Gradle as our build tool. Gradle handles the compilation step for you — you do not need to type javac manually. Here is the workflow you will follow every time you write a program:
- Edit your code in VS Code. Your Java source file lives inside your Gradle project.
- Run your program with
./gradlew runin the terminal (or click the Run button in VS Code). Gradle automatically:- Calls
javacto compile your.javafile into a.classfile - Calls
javato run the bytecode on the JVM
- Calls
- Read the output in the terminal
- Fix and repeat. Read the error message carefully — it tells you the line number and the nature of the problem.
The key habit: Run early, run often. Do not write 50 lines of code and then run for the first time. Write a few lines, run, verify, then add more. This keeps errors small and manageable.
Watch out: When you see an error message, read it. Do not panic and randomly change code. The compiler is trying to help you. It tells you:
- The file name where the error occurred
- The line number of the problem
- A description of what went wrong (e.g., “’;’ expected” or “cannot find symbol”)
Your Master Framework: IPO-CDS
For the rest of this quarter — and for every programming problem you ever solve — we will use a framework called IPO-CDS. It is a systematic, step-by-step process for turning an English problem description into working code.
Most students struggle not because they cannot write code, but because they do not know what code to write. IPO-CDS is the bridge between English and Java. It gives you a repeatable algorithm for breaking down any problem before you type a single line of code.
The letters stand for:
| Letter | Stands For | Question |
|---|---|---|
| I | Inputs | What data goes into the program? |
| P | Processing | What do we do with that data? |
| O | Outputs | What result comes out? |
| C | Constructs | What Java structures do we need? |
| D | Data Types | What types do the values have? |
| S | Steps | What is the order of operations? |
IPO: The “What”
The first three letters — I, P, O — answer the question “What does this program need to do?”
- Inputs (I): What information does the program need? Does the user type something? Does the program read a file? Are there constants or given values?
- Processing (P): What calculations, transformations, or decisions must the program make?
- Outputs (O): What does the program produce? What text does it print?
CDS: The “How”
The last three letters — C, D, S — answer the question “How do I translate this into Java?”
- Constructs (C): Does this problem need sequential code only? Conditionals (if/else)? Loops (for/while)? Methods? Words like “if,” “depending on,” and “when” suggest conditionals. Words like “repeat,” “for each,” and “until” suggest loops.
- Data Types (D): What type is each value? Is the age an
int? Is the GPA adouble? Is the name aString? - Steps (S): In what order do we write the code?
Applying IPO-CDS to Hello World
Even our tiny first program follows the framework:
| Step | Hello World Analysis |
|---|---|
| I (Inputs) | None — no user input, no file, no data |
| P (Processing) | None — no calculation or transformation |
| O (Outputs) | Print the text “Hello, World!” to the console |
| C (Constructs) | Sequential only (one statement, no decisions or loops) |
| D (Data Types) | One String literal: "Hello, World!" |
| S (Steps) | Step 1: Call System.out.println("Hello, World!") |
This analysis is trivial for Hello World, but the habit is what matters. As problems grow more complex, IPO-CDS keeps you organized.
The trick: Before writing any code, ask yourself the six IPO-CDS questions. Write your answers in comments at the top of your file. Then translate those answers into Java. This prevents the “blank screen” problem — staring at an empty editor with no idea where to start.
Practice
Try It Yourself
Write a program that prints your name and major on separate lines. Example output:
Alice Chen
Computer Science
IPO-CDS Analysis:
- I: None (the data is hardcoded)
- P: None (no calculations)
- O: Two lines of text to the console
- C: Sequential (two print statements)
- D: Two String literals
- S: Step 1: Print name. Step 2: Print major.
Solution:
public class MyInfo {
public static void main(String[] args) {
System.out.println("Alice Chen");
System.out.println("Computer Science");
}
}
What you learned
We covered a lot of ground in this first lesson:
-
Java is a compiled language. You write
.javasource code, thejavaccompiler translates it to.classbytecode, and the JVM runs the bytecode. The compilation step catches syntax and type errors before your program ever runs. -
The JDK contains the JRE contains the JVM. The JVM runs bytecode. The JRE adds the standard library. The JDK adds developer tools like the compiler. You have the JDK installed.
-
Every Java program needs a class with a main method. The
public static void main(String[] args)method is where execution begins. The file name must match the class name. -
Your workflow is: edit, run (via Gradle), read output, fix, repeat. Run early and run often. Read error messages carefully.
-
IPO-CDS is your master framework. For every problem: identify the Inputs, Processing, and Outputs (the “what”), then determine the Constructs, Data Types, and Steps (the “how”).
What Comes Next
Next: println() vs print(), escape sequences (\n, \t), and using output as a debugging tool.
Related Resources
- Reges & Stepp, Chapter 1 — Additional reading on introductory concepts