Java / 3 of 6 / 24 dilihat
Java Core Features
What Makes Java Different? Understanding Its Core Features
Java is often described as simple, portable, robust, secure, and high-performance. But what do those words actually mean for someone learning Java?
In the previous tutorials, we learned what Java is and how it evolved from a language called Oak into a modern software platform.
Now we will focus on the features that make Java useful for real-world development.
Java did not survive for more than three decades because of one special feature. Its strength comes from a combination of design choices that make applications easier to build, run, and maintain.
Series Navigation
Previous: History and Evolution of Java
Current: Core Features of Java
Next: Java vs C and C++
Learning Goals
After completing this article, you should be able to:
- explain why Java is considered simple and familiar;
- understand how classes and objects organize Java programs;
- explain platform independence and portability;
- understand why Java is called robust;
- describe the role of garbage collection;
- explain Java's security approach;
- understand multithreading at a basic level;
- explain how JIT compilation improves performance.
1. Java Is Simple and Familiar
The word simple does not mean that every Java project is easy.
Large applications can still become complex. Java is considered simple because it removes or restricts several low-level features that often make programming harder.
Java does not normally require developers to work with:
- pointer arithmetic;
- manual memory release;
- header files;
- preprocessor macros;
- multiple inheritance between classes;
- user-defined operator overloading.
Java also uses syntax that looks familiar to C and C++ developers.
if (score >= 75) {
System.out.println("Passed");
} else {
System.out.println("Try again");
}The braces, semicolons, operators, and control structures make the language easier to recognize.
Why This Matters
Developers can focus more on application logic and less on low-level memory operations.
For example, in ordinary Java code, an object can be created like this:
Course course = new Course();The developer does not manually release the object's memory later. The JVM manages that process.
Important Limitation
Java simplifies several language features, but the ecosystem can still be large.
Professional Java projects may involve:
- build tools;
- frameworks;
- databases;
- cloud services;
- testing tools;
- deployment configuration.
A better description is:
Java provides safer and more predictable foundations, but good software still requires careful design.
2. Java Is Object-Oriented
Java organizes most application code using classes and objects.
A class is a blueprint.
An object is an instance created from that class.
For example, a Course class may contain:
- a title;
- the number of completed lessons;
- a method for completing a lesson;
- a method for showing progress.
public class Course {private String title;
private int completedLessons;
public Course(String title) {
this.title = title;
this.completedLessons = 0;
}
public void completeLesson() {
completedLessons++;
}
public void showProgress() {
System.out.println(
title + ": " + completedLessons + " lesson(s)"
);
}
}
```
We can create an object from that class:
Course javaCourse = new Course("Java Fundamentals");javaCourse.completeLesson();
javaCourse.showProgress();
```
Why This Matters
Object-oriented programming helps developers:
- group related data and behavior;
- divide large systems into smaller parts;
- reuse code;
- hide internal implementation details;
- replace one implementation with another;
- test components separately.
Common Object-Oriented Ideas
Encapsulation
Encapsulation protects an object's internal state.
private int balance;Other code cannot modify balance directly when it is private.
The class can provide a safe method instead:
public void deposit(int amount) {
if (amount > 0) {
balance += amount;
}
}Inheritance
Inheritance allows one class to reuse and extend another class.
class User {
void login() {
System.out.println("User logged in");
}
}class Administrator extends User {
void openAdminPanel() {
System.out.println("Admin panel opened");
}
}
```
Polymorphism
Polymorphism allows different objects to be used through the same type.
interface Notification {
void send(String message);
}Different classes can implement the interface in different ways.
Important Limitation
Object-oriented programming is not automatically good architecture.
Poor design can create:
- very large classes;
- deep inheritance chains;
- tightly coupled components;
- code that is difficult to test.
Java also supports procedural and functional styles. Developers should use the style that best fits the problem.
3. Java Is Platform-Independent
Platform independence is one of Java's best-known features.
Java source code is normally compiled into bytecode.
That bytecode is then executed by the Java Virtual Machine, or JVM.
Java source code
│
│ compiled by javac
▼
Java bytecode
│
│ executed by the JVM
▼
Windows, Linux, or macOSThe JVM is different for each operating system, but the bytecode format is designed to remain the same.
This is the idea behind:
Write Once, Run Anywhere
Example
Suppose we compile this source file:
public class PlatformMessage {public static void main(String[] args) {
System.out.println("Running with Java");
}
}
```
The compiler produces:
PlatformMessage.classThat .class file can often run on another supported operating system without being compiled again.
Why This Matters
A development team can maintain one main codebase instead of building completely separate versions for every platform.
Important Limitation
A Java application can still become platform-specific.
For example:
Path path = Path.of("C:\\data\\tutorial.txt");This path is specific to Windows.
Applications can also depend on:
- native libraries;
- operating-system commands;
- fonts;
- file permissions;
- hardware;
- screen size.
Java improves portability, but developers must still avoid platform-specific assumptions.
4. Java Is Portable and Architecture-Neutral
Platform independence and portability are related, but they are not exactly the same.
Platform independence means bytecode can run through compatible JVMs.
Portability means the program behaves consistently across systems.
Java improves portability through:
- standardized bytecode;
- predictable primitive data types;
- a large standard library;
- Unicode support;
- consistent exception rules;
- defined language behavior.
For example, a Java int is always a signed 32-bit integer.
int total = 1_000_000;Its size does not change because the application moves to another common processor architecture.
Architecture-Neutral
Java bytecode is not designed for one physical processor.
A JVM can translate it for different architectures.
Java bytecode
│
├── x86-64
├── ARM64
└── another supported architectureImportant Limitation
When Java uses native code, separate builds may still be required.
Examples include:
.dllfiles on Windows;.sofiles on Linux;.dylibfiles on macOS.
Portable Java code should avoid unnecessary native dependencies.
5. Java Is Strongly and Statically Typed
Java checks types before and during execution.
int lessonCount = 12;
String courseName = "Java Fundamentals";
boolean published = true;This code is invalid:
int lessonCount = "twelve";The compiler rejects it because a string cannot be assigned to an integer variable.
Why This Matters
The compiler can detect many mistakes early:
- incompatible assignments;
- invalid method arguments;
- incorrect return values;
- missing methods;
- invalid collection elements.
Example:
List<String> topics = new ArrayList<>();topics.add("Classes");
topics.add(100); // Compile-time error
```
Only strings can be added to topics.
Type Inference
Java can infer some local variable types:
var title = "Java Core Features";The compiler still knows that title is a String.
The variable does not become dynamically typed.
Important Limitation
Type checking cannot detect every logical mistake.
This code compiles:
int totalPrice = quantity - unitPrice;The types are valid, but the formula may be wrong.
Static typing helps prevent certain errors, but testing and code review are still necessary.
6. Java Is Robust
Java is often described as robust because it includes features that reduce common software failures.
These features include:
- compile-time type checking;
- array bounds checking;
- exception handling;
- automatic memory management;
- runtime type checking;
- bytecode verification;
- no ordinary pointer arithmetic.
Array Bounds Checking
Consider this array:
String[] topics = {
"Variables",
"Methods",
"Classes"
};The valid indexes are:
0, 1, and 2This code is invalid:
System.out.println(topics[5]);Java throws an ArrayIndexOutOfBoundsException.
It does not silently read unrelated memory.
Exception Handling
Java uses exceptions to represent errors and unusual conditions.
try {
int value = Integer.parseInt("abc");
System.out.println(value);
} catch (NumberFormatException exception) {
System.out.println("The value is not a valid integer.");
}The normal program flow and the error flow are separated.
Operation starts
│
├── success → continue
└── failure → throw an exceptionImportant Limitation
Robust does not mean bug-free.
Java applications can still have:
- null reference errors;
- incorrect business logic;
- unhandled exceptions;
- resource leaks;
- concurrency problems.
The language provides safer mechanisms, but developers must still use them correctly.
7. Java Uses Automatic Memory Management
Java uses automatic memory management through the JVM.
When an object is created, the JVM manages the memory used by that object.
Course course = new Course("Java Fundamentals");When the object can no longer be reached by the application, it becomes eligible for garbage collection.
Object is created
│
▼
Application uses it
│
▼
No reachable reference remains
│
▼
Memory may be reclaimedWhy This Matters
Developers do not normally need to manually release object memory.
This reduces errors such as:
- forgetting to release memory;
- releasing the same memory twice;
- accessing memory after it has been released.
Garbage Collection Does Not Manage Everything
The garbage collector manages Java object memory.
It does not guarantee that external resources are closed at the correct time.
Developers must still close resources such as:
- files;
- database connections;
- network sockets;
- input streams;
- output streams.
A common solution is try-with-resources:
try (BufferedReader reader = Files.newBufferedReader(path)) {
System.out.println(reader.readLine());
}Java Can Still Have Memory Leaks
A program can keep references to objects it no longer needs.
List<byte[]> cache = new ArrayList<>();while (true) {
cache.add(new byte[1_000_000]);
}
```
The objects remain reachable through cache, so the garbage collector cannot remove them.
A better statement is:
Garbage collection automates memory cleanup, but developers must still manage references and resources responsibly.
8. Java Was Designed with Security in Mind
Java was created for networked environments, so security became an important design goal.
Java provides features such as:
- access modifiers;
- type checking;
- array bounds checking;
- bytecode verification;
- class-loader isolation;
- cryptographic APIs;
- controlled native-code access.
Access Modifiers
Java provides:
public
protected
package-private
privateThese modifiers control which code can access a class, field, constructor, or method.
public class Account {private int balance;
public int getBalance() {
return balance;
}
}
```
Other classes cannot directly modify balance.
Standard Security APIs
Java provides APIs for:
- encryption;
- digital signatures;
- secure random numbers;
- certificates;
- TLS connections;
- key management.
Important Limitation
Java does not automatically make an application secure.
Developers can still create vulnerabilities such as:
- SQL injection;
- weak authentication;
- exposed passwords;
- path traversal;
- incorrect authorization;
- insecure configuration.
For example:
String sql =
"SELECT * FROM users WHERE name = '" + userInput + "'";This is unsafe because user input is inserted directly into the query.
Security depends on language features, application design, configuration, testing, and maintenance.
9. Java Supports Multithreading
Applications often need to perform several activities during the same period.
For example, an application may:
- receive user input;
- download data;
- write logs;
- save files;
- process background jobs.
Java includes support for threads and concurrency.
Thread worker = new Thread(() -> {
System.out.println("Background task started");
});worker.start();
```
The code inside the lambda runs in another thread.
Why This Matters
Multithreading can help applications:
- remain responsive;
- process several requests;
- perform background work;
- use processor resources more effectively.
Modern Java also provides higher-level concurrency tools such as:
- executors;
- thread pools;
- futures;
- concurrent collections;
- virtual threads.
Important Limitation
Multithreading does not always make a program faster.
It can introduce:
- race conditions;
- deadlocks;
- inconsistent data;
- scheduling overhead;
- difficult debugging.
Developers must coordinate shared data carefully.
Concurrency is powerful, but it is also one of the more advanced areas of Java.
10. Java Can Deliver Strong Performance
Java is sometimes described as slow because it uses bytecode.
That description is incomplete.
Modern JVMs can use Just-In-Time compilation, or JIT compilation.
The JVM observes the running application and identifies frequently executed code.
That code can then be compiled into optimized native machine instructions.
Bytecode starts running
│
▼
JVM observes application behavior
│
▼
Frequently executed code is identified
│
▼
JIT compiler creates native code
│
▼
Optimized code runs on the processorWhy This Matters
The JVM can optimize code using information collected while the application is running.
This is especially useful for long-running applications such as:
- backend services;
- enterprise systems;
- application servers;
- data-processing systems.
Warm-Up
At startup, the JVM has limited information.
As the application runs, more code may be optimized.
This is why some Java applications perform better after a warm-up period.
Important Limitation
Java performance still depends on:
- algorithms;
- data structures;
- memory use;
- database access;
- network latency;
- JVM configuration;
- hardware;
- application architecture.
JIT compilation also introduces trade-offs such as startup time and memory usage.
A better statement is:
Java combines portable bytecode with a runtime that can optimize frequently executed code.
11. Why These Features Matter Together
Java's features are most useful when combined.
Imagine a tutorial platform.
Object-Oriented Design
Classes represent concepts such as:
Course
Lesson
Student
ProgressStatic Typing
The compiler checks that methods receive valid types.
void enroll(Student student, Course course) {
// ...
}Platform Independence
The compiled application can run on different supported JVM platforms.
Robustness
Exceptions and runtime checks help detect problems.
Garbage Collection
The JVM manages memory for temporary objects.
Multithreading
Several users can access the application during the same period.
JIT Compilation
Frequently executed code can be optimized at runtime.
The Java platform is therefore more than just syntax.
Java language
+
Standard library
+
JVM
+
Development tools
+
Ecosystem
=
Java platform12. Common Misconceptions
“Java Is Completely Object-Oriented”
Java is strongly object-oriented, but primitive types such as int, boolean, and double are not objects.
“Write Once, Run Anywhere Means No Testing”
Applications should still be tested on every supported environment.
Operating systems can differ in file paths, permissions, fonts, and native dependencies.
“Garbage Collection Prevents All Memory Leaks”
A Java application can still retain objects it no longer needs.
If an object remains reachable, the garbage collector cannot remove it.
“Java Is Always Slow”
Modern JVMs use JIT compilation and runtime optimization.
Actual performance depends on the workload and application design.
“Java Is Automatically Secure”
Java provides security mechanisms, but developers can still create insecure applications.
“Multithreading Always Improves Performance”
Threads add overhead and coordination complexity.
They help only when the workload benefits from concurrency.
13. Feature Summary
- Simple and familiar: removes several low-level complexities while retaining familiar syntax.
- Object-oriented: organizes data and behavior using classes and objects.
- Platform-independent: compiles into bytecode that runs through compatible JVMs.
- Portable: provides predictable types, libraries, and runtime behavior.
- Strongly typed: detects many invalid operations during compilation.
- Robust: uses exceptions, runtime checks, and automatic memory management.
- Secure foundations: provides access control, verification, and cryptographic APIs.
- Multithreaded: supports concurrent tasks and responsive applications.
- High-performance: uses JIT compilation and adaptive runtime optimization.
Every feature has limitations.
Understanding those limitations is more useful than memorizing marketing terms.
14. Mini Exercise
Create a class called TutorialProgress with:
- a private student name;
- a private completed lesson count;
- a constructor;
- a method to complete one lesson;
- a method to display progress.
Expected usage:
TutorialProgress progress =
new TutorialProgress("Alya");progress.completeLesson();
progress.completeLesson();
progress.showProgress();
```
Expected output:
Alya has completed 2 lesson(s).Suggested Solution
public class TutorialProgress {private final String studentName;
private int completedLessons;
public TutorialProgress(String studentName) {
this.studentName = studentName;
this.completedLessons = 0;
}
public void completeLesson() {
completedLessons++;
}
public void showProgress() {
System.out.println(
studentName
+ " has completed "
+ completedLessons
+ " lesson(s)."
);
}
public static void main(String[] args) {
TutorialProgress progress =
new TutorialProgress("Alya");
progress.completeLesson();
progress.completeLesson();
progress.showProgress();
}
}
```
15. Knowledge Check
- In what sense is Java considered simple?
- What is the difference between a class and an object?
- Why is Java platform-independent?
- What does static typing help detect?
- What does the garbage collector do?
- Does Java automatically make an application secure?
- What is JIT compilation?
Suggested Answers
- Java removes or restricts several low-level and complicated features.
- A class is a blueprint; an object is an instance created from that class.
- Java is compiled into bytecode that can run through compatible JVMs.
- It detects many incompatible assignments, method calls, and return values.
- It reclaims memory from objects that are no longer reachable.
- No. Java provides security mechanisms, but developers must still build applications securely.
- JIT compilation converts frequently executed bytecode into optimized native machine code while the application runs.
Key Takeaways
Java source code
│
▼
Compile-time type checking
│
▼
Portable bytecode
│
▼
JVM execution and runtime checks
│
▼
Garbage collection and JIT optimizationThe most important points are:
- Java simplifies several low-level programming tasks.
- Classes and objects help organize growing applications.
- Java bytecode can run through compatible JVMs on different platforms.
- Static typing detects many mistakes before execution.
- Runtime checks, exceptions, and garbage collection improve robustness.
- Java provides security foundations but does not guarantee secure applications.
- Java supports concurrent programming.
- Modern JVMs can optimize frequently executed code through JIT compilation.
- Every feature has benefits and trade-offs.
What's Next?
Java borrowed familiar syntax from C and C++, but it made different decisions about memory, portability, safety, and low-level control.
In the next article, we will compare:
Java vs C and C++: Different Languages for Different Problems
Official Sources and Further Reading
- Java Language Specification — Introduction
- Java Virtual Machine Specification — Introduction
- The Java Language Environment
- Java Exceptions Tutorial
- Java Concurrency Tutorial
- JDK Garbage Collection Tuning Guide