Java: Introduction to Java

Java is one of the most popular programming languages in the world. This lesson gives you a complete overview and helps you set up your development environment.

1. What is Java

Java is a programming language created by Sun Microsystems in 1995, now maintained by Oracle. Its core design principle is "Write Once, Run Anywhere."

(1) Key Features of Java

Feature Description
Cross-platform Write once, run anywhere (Windows/Mac/Linux)
Object-oriented Supports encapsulation, inheritance, and polymorphism
Easy to learn Syntax similar to C++, but without the complex features
Secure and reliable Built-in memory management, exception handling, and strong type checking
Rich ecosystem Massive collection of open-source libraries and frameworks (Spring, Hibernate, etc.)
Wide job market Web development, Android, big data, enterprise applications

(2) What Can You Build with Java


2. JDK, JRE, and JVM

These three concepts are core to Java. Understanding their relationship is important.

(1) Concept Explanation

Concept Full Name Purpose
JVM Java Virtual Machine The virtual machine that runs Java bytecode
JRE Java Runtime Environment JVM + core libraries (for running Java programs)
JDK Java Development Kit JRE + development tools (compiling, debugging, etc.)

(2) Relationship Diagram

TEXT
JDK (Development Kit)
├── JRE (Runtime Environment)
│   ├── JVM (Virtual Machine)
│   └── Core Libraries
└── Development Tools (javac, java, jshell, etc.)
💡 Simple explanation: Developers need to install the JDK. Regular users only need the JRE. Modern JDK downloads include the JRE automatically.


3. Environment Setup

(1) Download the JDK

JDK 17 or 21 is recommended (LTS - Long Term Support versions).

Download at: https://www.oracle.com/java/technologies/downloads/

(2) Verify Installation

After installation, open a terminal and run these commands to verify:

BASH
# Check Java version
java -version

# Check compiler version
javac -version

Expected output:

TEXT
java version "17.0.9" 2023-10-17 LTS
Java(TM) SE Runtime Environment (build 17.0.9+11-LTS-201)
Java HotSpot(TM) 64-bit Server VM (build 17.0.9+11-LTS-201, mixed mode, sharing)
⚠️ Note: If you see "java is not recognized as an internal or external command," your environment variables are not set up correctly. Add the JDK's bin directory to your PATH.


4. Getting Started with JShell

JShell is an interactive tool introduced in Java 9. It lets you run Java code directly in the terminal, making it perfect for learning and experimentation.

(1) Launch JShell

BASH
jshell

Output:

TEXT
|  Welcome to JShell Version 17.0.9
|  For an introduction type: /help intro
jshell>

(2) Basic Operations

JAVA
// Arithmetic
jshell> 3 + 4
$1 ==> 7

// Define a variable
jshell> int age = 25
age ==> 25

// Print output
jshell> System.out.println("Hello, Java!")
Hello, Java!

// Exit
jshell> /exit
|  Goodbye
💡 Advantage: JShell doesn't require you to write a complete class or main method. You can execute code snippets directly, making it ideal for beginners.


5. Why Learn Java

Reason Description
High demand Java is the go-to language for enterprise development
Competitive salaries Java developers earn above-average salaries
Mature ecosystem Massive collection of open-source frameworks and tools
Abundant learning resources Active community, comprehensive documentation
Cross-platform capability Write once, run anywhere
Long-term stability Continuously updated since 1995

▶ Example

JAVA
public class HelloJava {
    public static void main(String[] args) {
        System.out.println("Hello, Java!");
    }
}
▶ Try it Yourself

❓ FAQ

Q What's the relationship between Java and JavaScript?
A No direct relationship. Java is a compiled OOP language; JavaScript is a scripting language. Similar names are a historical coincidence.
Q What prerequisites do I need?
A None. You can start from zero. Other language experience helps but isn't required.
Q Which JDK version should I choose?
A JDK 17 or 21 (LTS) are recommended for enterprise projects.

📖 Summary

📝 Exercises

  1. Setup: Install the JDK on your computer and verify that the java and javac commands work correctly
  2. JShell practice: Use JShell to calculate: How many seconds are in a day? How many seconds are in a year?
  3. Think about it: List 3 project ideas you'd like to build with Java

6. Next Lesson

In the next lesson, we'll learn about Your First Java Program — writing and running your first Java program.

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏