💻 Programming

Java

Java Programming Language

Write Once, Run Anywhere. A platform-independent object-oriented language running on the JVM. The enterprise development standard with Spring.

📖 Detailed Explanation

Java is an object-oriented programming language developed in 1995 by James Gosling at Sun Microsystems. It was originally designed for embedded systems in consumer electronics, but with the explosive growth of the web it became a core language for enterprise application development. Oracle acquired Sun in 2010, and Oracle now manages Java.

Java's core philosophy is "Write Once, Run Anywhere (WORA)." Java code is compiled to bytecode and runs on the JVM (Java Virtual Machine), so it behaves identically regardless of the operating system. Thanks to this platform independence, the same application can run on Windows, Linux, or macOS.

Java provides a strong type system, automatic memory management (Garbage Collection), and multithreading support. It catches type errors at compile time to improve runtime stability, and the GC handles memory leak problems automatically. These traits enable stable operation in large-scale systems.

In practice, Java is most widely used for backend server development together with the Spring Framework. It is recognized for its proven stability in mission-critical systems such as finance, telecommunications, and public institutions, and it is also an official language for Android app development. As of 2024, it remains near the top of the TIOBE Index alongside Python and C, and is used by more than 9 million developers worldwide.

💻 Code Example

// 1. 기본 클래스와 객체지향 프로그래밍
public class User {
    private String name;
    private String email;

    public User(String name, String email) {
        this.name = name;
        this.email = email;
    }

    public String getName() { return name; }
    public String getEmail() { return email; }

    @Override
    public String toString() {
        return String.format("User{name='%s', email='%s'}", name, email);
    }
}

// 2. Stream API와 람다 표현식 (Java 8+)
import java.util.List;
import java.util.stream.Collectors;

public class StreamExample {
    public static void main(String[] args) {
        List<Integer> numbers = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

        int sumOfEvenSquares = numbers.stream()
            .filter(n -> n % 2 == 0)        // 짝수만: [2, 4, 6, 8, 10]
            .map(n -> n * n)                // 제곱: [4, 16, 36, 64, 100]
            .reduce(0, Integer::sum);       // 합계: 220

        System.out.println("짝수 제곱의 합: " + sumOfEvenSquares);
    }
}

// 3. 비동기 처리 (CompletableFuture)
import java.util.concurrent.CompletableFuture;

public class AsyncExample {
    public static CompletableFuture<User> fetchUserAsync(String userId) {
        return CompletableFuture.supplyAsync(() -> {
            // API 호출 시뮬레이션
            return new User("홍길동", "hong@example.com");
        }).thenApply(user -> {
            System.out.println("사용자 조회 완료: " + user.getName());
            return user;
        }).exceptionally(ex -> {
            System.err.println("오류 발생: " + ex.getMessage());
            return null;
        });
    }
}

🗣️ Say It Like This in Practice

💬 In a Meeting
"This service has heavy traffic and stability matters, so I think we should build it with Java Spring Boot. Connect the DB with JPA and add a Redis cache, and performance should be more than sufficient."
💬 In an Interview
"Java's GC manages the heap by dividing it into the Young Generation and the Old Generation. Minor GC happens frequently in the Eden space, and Full GC runs when the Old space is full. With G1GC, you can reduce Stop-the-World time in a predictable way."
💬 In a code review
"Using Optional here can prevent a NullPointerException. Don't call user.getName() directly; please change it to Optional.ofNullable(user).map(User::getName).orElse('Unknown')."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

❌
Use equals() instead of ==

When comparing objects, `==` compares references (memory addresses). When comparing the values of strings or objects, always use the `equals()` method. `"hello" == new String("hello")` is false.

❌
Preventing NullPointerException

This is the most common runtime error in Java. Do thorough null checks or use the Optional class. It is also good to make active use of the @NonNull annotation and IDE warnings.

✅
Using immutable objects

For safe code in multithreaded environments, make active use of immutable objects. Using the final keyword, record (Java 16+), and immutable collection factory methods such as List.of() can prevent unexpected state changes.

🔗 Related Terms

📚 Learn More