Mid-level 5 min · March 04, 2026

Java Integer Division — Silent Truncation Cost $2.3M

A $2.

N
Naren · Founder
Plain-English first. Then code. Then the interview question.
About
 ● Production Incident 🔎 Debug Guide
Quick Answer
  • Java is three things bundled as one: a programming language, the JVM (bytecode executor), and the JDK standard library
  • javac compiles source code to platform-neutral bytecode (.class); the JVM JIT translates it to native machine code at runtime
  • 8 primitive types (int, double, boolean, char, long, float, byte, short) store values directly on the stack
  • Static typing forces type declarations at compile time — errors caught before code ever reaches production
  • Integer division (int / int) silently drops decimals — no error, no warning, just wrong data
  • JDK includes the compiler (javac); JRE is runtime-only — always install the JDK for development
Plain-English First

Imagine you write a recipe on a piece of paper. Normally, different kitchens (a French one, a Japanese one, an American one) all need different versions of that recipe because their ovens and tools work differently. Java solves this problem for software — you write your code once, and Java's special 'universal translator' (called the JVM) reads that code and makes it work in any kitchen, on any computer, anywhere in the world. That's why Java's motto is literally 'Write Once, Run Anywhere.'

Every app on your Android phone, every bank transaction processed behind the scenes, every Amazon warehouse robot making decisions in real time — there's a very good chance Java is involved. It's been the backbone of enterprise software, mobile development, and large-scale systems for over 25 years. Learning Java isn't just learning a language; it's gaining a passport into one of the most employable skill sets in software engineering.

Before Java existed, developers had a painful problem: code written for one operating system simply would not run on another. A Windows program couldn't run on a Mac. A program built for a Sun workstation couldn't run on an IBM machine. Every new target required a full rewrite. Java was designed specifically to kill this problem. It introduced a layer of abstraction — a virtual machine — that sits between your code and the hardware, acting as a universal interpreter so your program doesn't care what's underneath it.

By the end of this article, you'll understand exactly what Java is and why it was created, how code travels from something you type to something a computer executes, and you'll have written, run, and fully understood your first real Java program. No hand-waving, no skipping steps — we're building this from the ground up together.

What Java Actually Is — Platform, Language, and Ecosystem

Most people say 'Java' and mean the programming language — the syntax, the keywords, the way you structure code. But Java is actually three things bundled together, and understanding all three changes how you think about it.

First, there's the Java Programming Language itself — a set of rules for writing instructions a computer can eventually understand. It's object-oriented, meaning you organise your code around things (objects) rather than just a list of steps.

Second, there's the JVM (Java Virtual Machine) — the universal translator we mentioned. When you write Java code, it doesn't compile directly into instructions your specific CPU understands. Instead, it compiles into something called bytecode — a middle-ground language that the JVM then translates on the fly for whatever machine it's running on. This is why the same .class file runs on Windows, Mac, and Linux without changing a single line.

Third, there's the Java Standard Library (JDK/JRE) — thousands of pre-built tools that come with Java so you don't have to reinvent the wheel. Need to read a file? There's a class for that. Need to sort a list? There's a method for that. You're standing on the shoulders of giants from day one.

Java was created by James Gosling at Sun Microsystems in 1995. It was originally designed for interactive television, but it quickly found its true home in enterprise software and the web — and later, Android.

WhatIsJava.javaJAVA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// This file demonstrates the most basic Java program possible.
// Every Java program starts with a class. The class name MUST match the filename.
// Here the file is called WhatIsJava.java, so the class is called WhatIsJava.

public class WhatIsJava {

    // main() is the entry point — the first method Java looks for when you run the program.
    // Think of it as the front door of your application.
    // 'public' means anyone can call it.
    // 'static' means Java doesn't need to create an object to use it (we'll cover this later).
    // 'void' means this method doesn't return any value when it's done.
    // 'String[] args' allows command-line arguments to be passed in — ignore this for now.
    public static void main(String[] args) {

        // System.out.println() is Java's way of printing a line of text to the console.
        // 'System' is a built-in class. 'out' is a stream that points to your screen.
        // 'println' means 'print line' — it prints the text AND moves to the next line.
        System.out.println("Java is running on: " + System.getProperty("os.name"));

        // The + operator here joins two strings together — this is called concatenation.
        // System.getProperty("os.name") fetches the name of your operating system at runtime.
        // This proves the JVM abstraction: same code, different output depending on your machine.
        System.out.println("Java version in use: " + System.getProperty("java.version"));

        System.out.println("Hello from Java — Write Once, Run Anywhere!");
    }
}
Output
Java is running on: Mac OS X
Java version in use: 17.0.9
Hello from Java — Write Once, Run Anywhere!
Why the class name must match the filename:
Java's compiler (javac) uses the filename to locate the class at compile time. If your file is WhatIsJava.java but your class is named HelloWorld, you'll get a compile error: 'class HelloWorld is public, should be declared in a file named HelloWorld.java'. Always keep them in sync — it's not optional.
Production Insight
The JVM abstraction adds measurable overhead vs native compilation — roughly 5-10% on CPU-bound work.
For startup-sensitive workloads (serverless, CLI tools), GraalVM native-image compiles ahead-of-time.
Rule: platform independence has a cost — know when it's worth paying and when it isn't.
Key Takeaway
Java is three things: language, JVM, and standard library — not just a syntax.
The JVM translates platform-neutral bytecode to local machine code at runtime.
Same .class file, any OS — the JVM handles the local translation.

The Journey From Code You Type to Code That Runs — The Compile-Execute Cycle

This is the section most beginner tutorials skip, and it's the one that causes the most confusion later. Let's walk through exactly what happens between you typing Java code and your computer actually doing something.

Step 1 — You write source code. This is the human-readable .java file you create in any text editor. It's just text. Your computer has no idea what to do with it yet.

Step 2 — The Java Compiler (javac) transforms it. You run javac WhatIsJava.java in your terminal. The compiler reads your source code, checks it for syntax errors, and converts it into bytecode — a compact, platform-neutral instruction set stored in a .class file. Bytecode is NOT machine code. No CPU in the world natively understands it.

Step 3 — The JVM executes the bytecode. You run java WhatIsJava. The JVM on your specific machine reads the .class file and uses a component called the JIT compiler (Just-In-Time compiler) to translate bytecode into real machine instructions for your CPU — right at the moment they're needed.

This two-step process is Java's superpower. The .class file you created on your Mac will run identically on a Windows server, a Linux container, or an Android device — because every platform has its own JVM that handles the final translation locally.

Think of bytecode as a universal musical score written in a language every orchestra understands. The JVM is the orchestra — different in every city, but all playing the same music.

CompileAndRunDemo.javaJAVA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// STEP 1: This is your source code — the .java file you write
// Save this as: CompileAndRunDemo.java

// STEP 2: Compile it in your terminal with:
//   javac CompileAndRunDemo.java
// This produces: CompileAndRunDemo.class (bytecode)

// STEP 3: Run it with:
//   java CompileAndRunDemo
// The JVM reads the .class file and executes it.

public class CompileAndRunDemo {

    public static void main(String[] args) {

        // Let's demonstrate that the JVM knows exactly what environment it's in.
        // These system properties are resolved at RUNTIME by the JVM on the current machine.
        String operatingSystem = System.getProperty("os.name");      // e.g. "Windows 11"
        String jvmVendor       = System.getProperty("java.vendor");  // e.g. "Oracle Corporation"
        String javaHome        = System.getProperty("java.home");    // path to your JVM install

        System.out.println("=== JVM Environment Report ===");

        // String.format() lets you build a string with placeholders (%s = string slot)
        // It's cleaner than chaining lots of + operators when you have multiple values
        System.out.println(String.format("Operating System : %s", operatingSystem));
        System.out.println(String.format("JVM Vendor       : %s", jvmVendor));
        System.out.println(String.format("Java Home        : %s", javaHome));

        System.out.println("\nSame .class file. Different machine. Same result.");
        // \n is an escape character — it inserts a blank line before printing the next line.
    }
}
Output
=== JVM Environment Report ===
Operating System : Mac OS X
JVM Vendor : Eclipse Adoptium
Java Home : /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home
Same .class file. Different machine. Same result.
JDK vs JRE vs JVM — cleared up in one sentence each:
JVM (Java Virtual Machine) — runs bytecode. JRE (Java Runtime Environment) — the JVM plus the standard libraries your code needs. JDK (Java Development Kit) — the JRE plus the compiler (javac) and dev tools. To write Java, you need the JDK. To just run Java programs, you only need the JRE. Install the JDK — it includes everything.
Production Insight
JIT compilation means Java gets faster the longer a process runs — hot paths are optimised at runtime.
Cold-start latency is the trade-off: serverless functions pay the JIT warmup tax on every invocation.
Rule: for sub-second startup requirements, use GraalVM native-image to pre-compile to machine code.
Key Takeaway
javac compiles .java source to bytecode (.class) — not machine code.
The JVM JIT compiler translates bytecode to native instructions at runtime.
Bytecode is the universal score; the JVM is the local orchestra.

Your First Real Java Program — Variables, Output, and How the Pieces Fit Together

Now let's write something more meaningful than a one-liner, and break down every single piece so nothing is mysterious.

A Java program is built from classes. Think of a class as a blueprint — like an architectural plan for a house. The class defines what data exists and what actions can be taken. For now, we're using the class purely as a container to hold our main method.

Inside main, we write statements — individual instructions that Java executes top to bottom, one at a time, like a recipe. Each statement ends with a semicolon (;). This is Java telling you: 'This instruction is complete.'

Variables are named storage boxes. When you write int studentAge = 16;, you're asking Java to create a box, label it studentAge, declare that it can only hold whole numbers (int), and immediately put the value 16 inside it. Later you can look inside that box by using its name, or swap what's in it.

Java is statically typed — every variable must have a declared type before you use it. This feels strict at first, but it means Java catches type errors at compile time, before your program ever runs. Contrast this with Python or JavaScript, where type errors often only surface at runtime, sometimes in production. Static typing is a safety net.

Let's build a program that's actually doing something: calculating a student's grade average.

StudentGradeCalculator.javaJAVA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// A real-world style program that uses variables, arithmetic, and output.
// Goal: calculate a student's average score and print a summary report.

public class StudentGradeCalculator {

    public static void main(String[] args) {

        // --- VARIABLE DECLARATIONS ---
        // 'String' holds text (always wrapped in double quotes in Java)
        String studentName = "Maria Chen";

        // 'int' holds whole numbers (integers) — no decimal places
        int mathScore    = 88;
        int scienceScore = 92;
        int englishScore = 79;

        // 'double' holds decimal numbers (floating-point values)
        // We use double here because dividing integers can lose the decimal part
        double averageScore = (mathScore + scienceScore + englishScore) / 3.0;
        // Why 3.0 and not 3? If you divide by the integer 3, Java does integer division
        // and throws away the decimal. Using 3.0 forces decimal (floating-point) division.

        // 'boolean' holds only true or false — nothing else
        boolean hasPassed = averageScore >= 75.0;
        // The >= operator means 'greater than or equal to'
        // This expression evaluates to either true or false and stores it in hasPassed

        // --- OUTPUT ---
        System.out.println("==============================");
        System.out.println("  Student Grade Report");
        System.out.println("==============================");

        // Concatenating variables into output strings using the + operator
        System.out.println("Student  : " + studentName);
        System.out.println("Math     : " + mathScore);
        System.out.println("Science  : " + scienceScore);
        System.out.println("English  : " + englishScore);

        // Rounding averageScore to 2 decimal places using String.format()
        // "%.2f" means: format as a floating-point number with 2 decimal places
        System.out.println("Average  : " + String.format("%.2f", averageScore));

        // Printing a boolean — Java prints 'true' or 'false' as text automatically
        System.out.println("Passed   : " + hasPassed);

        // --- CONDITIONAL LOGIC ---
        // An if/else block runs different code depending on whether a condition is true
        if (hasPassed) {
            // This block only runs if hasPassed is true
            System.out.println("\nResult: PASS — Great work, " + studentName + "!");
        } else {
            // This block only runs if hasPassed is false
            System.out.println("\nResult: FAIL — Keep studying, " + studentName + ".");
        }
    }
}
Output
==============================
Student Grade Report
==============================
Student : Maria Chen
Math : 88
Science : 92
English : 79
Average : 86.33
Passed : true
Result: PASS — Great work, Maria Chen!
Watch Out: Integer Division Silently Drops Decimals
If you write (88 + 92 + 79) / 3 (dividing by the integer 3), Java performs integer division and gives you 86, not 86.33. No error, no warning — just silently wrong data. Always use 3.0 or cast one operand to double: (double)(mathScore + scienceScore + englishScore) / 3. This is one of the most common silent bugs in beginner Java code.
Production Insight
Integer division (int / int) silently drops the decimal portion — no exception thrown.
A payments service calculated daily interest as int, losing fractions on every transaction.
Rule: if the result can be fractional, cast to double or use BigDecimal before dividing.
Key Takeaway
Java is statically typed — every variable declares its type before use.
The compiler catches type errors at build time, not in production at 3 AM.
Verbosity is the trade-off; compile-time safety is the payoff.

Java's Core Data Types — The Building Blocks of Every Program

Every piece of data in Java has a type. Types tell the JVM how much memory to allocate and what operations are valid on that data. Java has two categories of types: primitive types and reference types.

Primitive types are the raw building blocks — they hold a single simple value directly. There are 8 of them in Java. The ones you'll use in 90% of your early code are: int (whole numbers), double (decimal numbers), boolean (true/false), and char (a single character like 'A').

Reference types hold a reference (think: address) to an object stored elsewhere in memory. The most important reference type for beginners is String — which is why String starts with a capital S; it's a full class, not a primitive. When you write String name = "Maria", the variable name doesn't hold the letters directly — it holds the address of where those letters live in memory. This distinction matters when you start comparing Strings (never use == to compare them — more on this in the Gotchas section).

Understanding types isn't bureaucracy — it's what allows Java to catch errors before they cause expensive bugs in production. When your bank runs a transaction, you want the language enforcing that an account balance is always a number, never accidentally a piece of text.

JavaDataTypesShowcase.javaJAVA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// A complete tour of Java's most important primitive and reference data types.
// Every variable here has a descriptive name that makes its purpose obvious.

public class JavaDataTypesShowcase {

    public static void main(String[] args) {

        // ===== PRIMITIVE TYPES =====

        // int: whole numbers from -2,147,483,648 to 2,147,483,647
        int numberOfStudentsInClass = 32;

        // long: whole numbers too big for int (use L suffix to tell Java it's a long literal)
        long populationOfEarth = 8_100_000_000L;
        // Note the underscores in the number: Java allows _ as a visual separator in numeric literals.
        // 8_100_000_000 is much easier to read than 8100000000. It has zero effect on the value.

        // double: decimal numbers (64-bit floating point — high precision)
        double priceOfCoffeeInDollars = 4.75;

        // float: decimal numbers (32-bit — less precise, uses F suffix)
        // Use double unless memory is extremely tight. float is rarely needed.
        float gpuTemperatureInCelsius = 72.5F;

        // boolean: can ONLY be true or false — nothing else
        boolean isJavaFunToLearn = true;

        // char: a SINGLE character, wrapped in SINGLE quotes (not double quotes)
        char firstLetterOfAlphabet = 'A';
        // Internally, Java stores 'A' as the number 65 (Unicode value).
        // That's why you can do arithmetic on chars: 'A' + 1 gives 'B'.

        // byte: tiny integer from -128 to 127 — useful for raw binary data
        byte singleByteValue = 100;

        // short: integer from -32,768 to 32,767 — rarely used in modern Java
        short yearOfJavaRelease = 1995;

        // ===== REFERENCE TYPE =====

        // String: a sequence of characters. Starts with capital S — it's a class.
        // Text goes in DOUBLE quotes. Single quotes are for char only.
        String greetingMessage = "Welcome to Java programming!";

        // String has built-in methods you can call with the dot (.) operator
        int lengthOfGreeting = greetingMessage.length(); // counts characters in the string
        String uppercaseGreeting = greetingMessage.toUpperCase(); // returns a new all-caps string

        // ===== PRINTING EVERYTHING =====
        System.out.println("=== Primitive Types ===");
        System.out.println("int    numberOfStudentsInClass : " + numberOfStudentsInClass);
        System.out.println("long   populationOfEarth       : " + populationOfEarth);
        System.out.println("double priceOfCoffeeInDollars  : " + priceOfCoffeeInDollars);
        System.out.println("float  gpuTemperatureInCelsius : " + gpuTemperatureInCelsius);
        System.out.println("boolean isJavaFunToLearn       : " + isJavaFunToLearn);
        System.out.println("char   firstLetterOfAlphabet   : " + firstLetterOfAlphabet);
        System.out.println("byte   singleByteValue         : " + singleByteValue);
        System.out.println("short  yearOfJavaRelease       : " + yearOfJavaRelease);

        System.out.println("\n=== Reference Type: String ===");
        System.out.println("Original : " + greetingMessage);
        System.out.println("Length   : " + lengthOfGreeting + " characters");
        System.out.println("Uppercase: " + uppercaseGreeting);
    }
}
Output
=== Primitive Types ===
int numberOfStudentsInClass : 32
long populationOfEarth : 8100000000
double priceOfCoffeeInDollars : 4.75
float gpuTemperatureInCelsius : 72.5
boolean isJavaFunToLearn : true
char firstLetterOfAlphabet : A
byte singleByteValue : 100
short yearOfJavaRelease : 1995
=== Reference Type: String ===
Original : Welcome to Java programming!
Length : 28 characters
Uppercase: WELCOME TO JAVA PROGRAMMING!
Interview Gold: Why is String not a primitive type in Java?
String is a class in the java.lang package, not a primitive. This means String objects are stored on the heap (not the stack), have methods you can call on them, and can be null. Java does give String special treatment — you can use double-quote literals instead of calling new String() — but under the hood it's still an object. This distinction comes up in interviews constantly.
Production Insight
String is a class, not a primitive — objects live on the heap, not the stack.
Using == to compare Strings checks memory addresses, not text content.
Rule: always use .equals() for String comparison in production code — never ==.
Key Takeaway
8 primitive types store values directly on the stack — fast, no heap allocation.
Reference types store a memory address pointing to a heap object.
This distinction determines comparison behaviour, null-handling, and memory layout.
● Production incidentPOST-MORTEMseverity: high

The $2.3 Million Integer Division Bug: How Silent Truncation Cost a Trading Firm

Symptom
Portfolio allocation reports showed percentages that didn't add up to 100%. Some accounts received slightly more than their target allocation, others received less. The discrepancy was small per account (~0.3%) but accumulated to $2.3M in misallocated funds over 11 days.
Assumption
The developer assumed that dividing two int values (totalShares / numberOfAccounts) would produce a decimal result. They wrote: int allocationPerAccount = totalShares / numberOfAccounts. Java performed integer division and silently dropped the remainder.
Root cause
Java performs integer division when both operands are int types. The expression 100000 / 47 evaluates to 2127, not 2127.66. No error, no warning, no exception — just silently truncated data. The 31 missing shares (100000 - 2127 * 47 = 31) were unallocated, sitting in a limbo account that nobody was watching.
Fix
Changed all financial calculations to use BigDecimal: BigDecimal allocation = BigDecimal.valueOf(totalShares).divide(BigDecimal.valueOf(numberOfAccounts), 2, RoundingMode.HALF_UP). Added a unit test that asserts division results with non-evenly-dividing test data. Implemented a post-calculation reconciliation check that verifies the sum of all allocations equals the original total.
Key lesson
  • Integer division silently drops decimals — no error, no warning, just wrong data
  • Any calculation involving money, percentages, or ratios must use double or BigDecimal, never raw int division
  • Test data that divides evenly hides integer truncation bugs — always include edge cases with remainders
  • Add reconciliation checks: if the sum of parts doesn't equal the whole, something was truncated
Production debug guideQuick diagnosis for the errors every Java developer hits in their first production codebase5 entries
Symptom · 01
Compile error: 'class X is public, should be declared in a file named X.java'
Fix
Rename your .java file to exactly match the public class name, including capitalisation. Java is case-sensitive — MyClass.java and myclass.java are different files.
Symptom · 02
String comparison returns false when the text looks identical
Fix
You are using == instead of .equals(). The == operator compares memory addresses, not text content. Change to str1.equals(str2).
Symptom · 03
Arithmetic result is a whole number when you expected a decimal
Fix
Check if both operands in the division are int. If so, Java performs integer division. Cast one operand to double: (double) a / b.
Symptom · 04
NullPointerException when calling a method on a String variable
Fix
The String variable is null — it was declared but never assigned, or a method returned null. Add a null check before calling methods: if (str != null && str.equals(...)).
Symptom · 05
Program compiles but output shows garbled characters for non-English text
Fix
Check the source file encoding. Java defaults to the platform encoding. Compile with javac -encoding UTF-8 YourFile.java and ensure your editor saves as UTF-8.
Java vs Python — Key Differences for New Developers
AspectJavaPython
Typing systemStatically typed — types declared at compile timeDynamically typed — types resolved at runtime
CompilationCompiles to bytecode, JVM executes itInterpreted line by line (CPython)
PerformanceFaster — JIT compilation optimises at runtimeSlower for CPU-bound tasks generally
VerbosityMore verbose — explicit types and structure requiredConcise — fewer lines for the same logic
Where it shinesEnterprise apps, Android, large-scale backend systemsData science, scripting, rapid prototyping
Error detectionMany errors caught at compile timeErrors often only surface at runtime
Entry pointpublic static void main(String[] args) requiredNo boilerplate — code runs top to bottom
Memory managementAutomatic via Garbage CollectorAutomatic via reference counting + GC

Key takeaways

1
Java's platform independence comes from a two-step process
javac compiles your source code to bytecode (.class file), then the JVM on any machine translates that bytecode to native machine instructions at runtime — same code, any platform.
2
You need the JDK to develop Java (it includes the compiler javac). The JRE is for running Java apps only. The JVM is the engine inside the JRE that actually executes bytecode.
3
Java has 8 primitive types (int, double, boolean, char, long, float, byte, short) that store values directly, and reference types like String that store a memory address pointing to an object
this distinction determines how comparison and assignment behave.
4
Java's static typing means every variable must declare its type upfront. This feels like extra work, but it lets the compiler catch type errors before your code ever runs
a massive advantage in large or safety-critical applications.
5
Integer division (int / int) silently drops the decimal
no exception, no warning. Always cast to double or use BigDecimal when fractional results matter, especially in financial or percentage calculations.
6
String is a class, not a primitive
always use .equals() to compare text content. The == operator compares memory addresses and will give you false negatives in production.

Common mistakes to avoid

3 patterns
×

Using == to compare Strings

Symptom
if (userName == "admin") returns false even when userName contains "admin". The == operator compares memory addresses, not text content. Two String objects with identical text can live at different memory addresses and == returns false.
Fix
Always use .equals() for String comparison: if (userName.equals("admin")). For case-insensitive comparison use .equalsIgnoreCase("admin"). Never use == for String comparison in production code.
×

Integer division silently truncating decimals

Symptom
int result = 7 / 2 gives 3, not 3.5. Java performs integer division when both operands are integers, silently dropping the decimal portion. No error, no warning — just silently wrong data.
Fix
Use double result = 7.0 / 2 or cast one operand: double result = (double) 7 / 2. Always ask: could this division produce a decimal I care about? For financial calculations, use BigDecimal instead of double.
×

Filename and class name mismatch

Symptom
Compile error: 'class HelloWorld is public, should be declared in a file named HelloWorld.java'. Java is case-sensitive and the public class name MUST exactly match the filename including capitalisation.
Fix
Always name your .java file to match your public class name, character for character. If the class is PaymentProcessor, the file must be PaymentProcessor.java — not paymentprocessor.java or Payment_Processor.java.
INTERVIEW PREP · PRACTICE MODE

Interview Questions on This Topic

Q01JUNIOR
What is the difference between the JDK, JRE, and JVM, and which one do y...
Q02SENIOR
Java is called 'platform-independent' — explain exactly how that works. ...
Q03SENIOR
Why is String not a primitive type in Java, and what practical differenc...
Q01 of 03JUNIOR

What is the difference between the JDK, JRE, and JVM, and which one do you need to compile and run a Java program?

ANSWER
The JVM (Java Virtual Machine) is the engine that executes bytecode. The JRE (Java Runtime Environment) bundles the JVM plus the standard libraries your code needs to run. The JDK (Java Development Kit) includes the JRE plus the compiler (javac) and development tools like javadoc and jdb. To compile and run Java, you need the JDK. To only run pre-compiled Java programs, you need the JRE. In practice, always install the JDK — it includes everything. A common follow-up: 'Can you run Java without the JDK?' Yes — the JRE is sufficient to run .class files. But you cannot compile .java source files without the JDK.
FAQ · 4 QUESTIONS

Frequently Asked Questions

01
Is Java hard to learn for a complete beginner?
02
What is Java mainly used for today?
03
What is the difference between Java and JavaScript?
04
What version of Java should I install as a beginner?
🔥

That's Java Basics. Mark it forged?

5 min read · try the examples if you haven't

1 / 13 · Java Basics
Next
JDK vs JRE vs JVM Explained