Module 1 · Getting Started with Java — topic 1 of 3
Introduction to Java
What Java is, where it is used, the ideas behind its design and how a Java program turns into something your computer can run.
Learning objectives
- Describe what Java is and where it is used
- Explain 'write once, run anywhere' and the role of bytecode
- List the main features that distinguish Java from C and C++
Definition
Java is a statically typed, object-oriented, general-purpose programming language whose programs are compiled to platform-independent bytecode and executed by the Java Virtual Machine (JVM).
Introduction
Java was created at Sun Microsystems in the mid-1990s by a team led by James Gosling, and it is now maintained by Oracle together with the open-source OpenJDK community. Three decades later it is still one of the most widely used languages in the world.
If you have seen C, Java will look familiar: braces, semicolons, if, for and while all work the same way. The big differences are underneath. Java has no manual memory management, no pointer arithmetic and no undefined behaviour from reading past the end of an array — the runtime checks those things for you.
Why it matters
Java powers a huge share of the software that businesses depend on: banking systems, e-commerce back ends, Android apps (historically), big-data tools such as Hadoop, Kafka and Spark, and servers built with Spring Boot.
Because it is so common in industry and in campus placements, Java is often the language used in technical interviews and data-structures courses. Learning it well opens many doors.
Detailed explanation
Compiled to bytecode. The javac compiler does not produce machine code for your processor. It produces *bytecode* — instructions for an imaginary machine — stored in .class files. The Java Virtual Machine reads that bytecode and runs it, translating hot code paths into fast native code with a just-in-time (JIT) compiler.
Platform independence. Because every operating system has its own JVM, the same .class files run on Windows, macOS and Linux without recompiling. This is the famous slogan *write once, run anywhere*.
Object-oriented. Almost everything in Java lives inside a class. Programs are built from objects that combine data (fields) with behaviour (methods). You will learn the four pillars — encapsulation, inheritance, polymorphism and abstraction — in module 5.
Statically and strongly typed. Every variable has a type that the compiler knows. Mixing up a String and an int is a compile-time error rather than a surprise at run time.
Automatic memory management. You create objects with new, but you never free them. The garbage collector reclaims objects that nothing refers to any more. This removes whole categories of bugs such as double frees and dangling pointers.
A huge standard library. Collections, file and network I/O, dates and times, concurrency, regular expressions and much more come with every JDK, so you rarely need third-party code for everyday tasks.
Syntax
- A public class must be in a file with the same name:
Hello.java. - Execution starts in
public static void main(String[] args). - Statements end with a semicolon; blocks use braces.
Code examples
Hello, Java
Hello, Java! Java runs on the JVM.
Java checks array bounds for you
Caught: Index 3 out of bounds for length 3
In C, reading marks[3] would silently read garbage memory. Java throws an exception you can handle.
More examples
Objects, a method and the standard library
Languages: [C, C++, Java, Python] Count: 4 Contains Java? true Java has 4 letters, upper case: JAVA
Step-by-step explanation
import java.util.List;makes theListinterface from the standard library available by its short name.List.of(...)creates an unmodifiable list of four strings;<String>says what the list holds.- Printing a list calls its
toString()method, which formats it as[C, C++, Java, Python]. size()andcontains()are methods called on the list object with the dot operator.name.length()andname.toUpperCase()are methods of theStringclass;+joins strings and numbers.
Expected output
Running “Objects, a method and the standard library” prints exactly:
Practical applications
- Server applications and REST APIs built with Spring Boot
- Android apps (alongside Kotlin)
- Big-data platforms such as Kafka, Hadoop and Elasticsearch
- Desktop tools such as IntelliJ IDEA, which is itself written in Java
Best practices
- Install a Long-Term Support JDK (17 or 21) for learning and real projects.
- Name classes in PascalCase and methods and variables in camelCase from the very first program.
- Read compiler errors from the first one down — later errors are often caused by the first.
Common mistakes
File name doesn't match the public class
Avoid
Prefer
A public class must be stored in a file with exactly the same name, including capital letters; otherwise javac reports an error.
Thinking Java and JavaScript are related
Avoid
Prefer
The similar name was a marketing decision in 1995. JavaScript runs mainly in browsers; Java runs on the JVM.
Important notes
- This course uses Java 21. Features added after Java 8, such as
var(Java 10), switch expressions (Java 14), text blocks (Java 15) and records (Java 16), are labelled when they appear. - Garbage collection means you don't free memory, but you can still 'leak' it by keeping references to objects you no longer need.
Key takeaways
- Java compiles to bytecode that the JVM runs, so the same program works on any operating system.
- Java is object-oriented, statically typed and garbage collected.
- Every program starts in a
mainmethod inside a class whose name matches the file name.
Try it yourself
- 1Print your name, your college and the year on three separate lines.
- 2Write down three differences between C and Java that you noticed in this lesson.
Show hint
Think about memory, arrays and classes.
Finished reading? Mark it complete to update your dashboard.
Suggested practice
3 questions test this exact topic. Answers and explanations are revealed after you submit.
- BeginnerWhat does the javac compiler produce from a .java file?
- BeginnerWhat makes Java programs 'write once, run anywhere'?
- BeginnerWhich statement about memory in Java is true?