Java was designed to be simple, safe and able to run on any machine. These aims shaped every feature of the language.
Evolution of Java
Java was developed at Sun Microsystems by a team led by James Gosling, starting in 1991. It was first called Oak and was intended for consumer electronic devices such as set-top boxes. In 1995 it was renamed Java and released publicly, just as the World Wide Web was growing, and its ability to run small programs (applets) in web browsers made it famous. JDK 1.0 appeared in 1996. Sun was acquired by Oracle in 2010, and Java is now released every six months, with long-term support versions such as Java 8, 11, 17 and 21. Java editions include Java SE (standard), Java EE (enterprise, now Jakarta EE) and Java ME (micro, for small devices).
Definition: Platform independence. The ability of a program to run on any hardware and operating system without change, achieved in Java by compiling to bytecode that runs on any Java Virtual Machine.
Features of Java
Simple: Java has a familiar C-like syntax but removes difficult features such as pointers and operator overloading. Object-oriented: almost everything is an object. Platform independent and portable: "write once, run anywhere", since bytecode runs on any JVM, and data type sizes are fixed on every platform. Compiled and interpreted: the compiler produces bytecode, which the JVM interprets or compiles just in time. Robust: strong type checking, exception handling and automatic garbage collection prevent many errors and memory leaks. Secure: no pointers, a bytecode verifier and a security manager protect the machine. Distributed: built-in support for networking and remote objects. Multithreaded: programs can do several tasks at once. High performance: the JIT (Just-In-Time) compiler converts bytecode to machine code at run time. Dynamic: classes are loaded as needed.
Java, C and C++
Java removes several features of C and C++: pointers, goto, structures and unions, #define and preprocessor directives, global variables, operator overloading and multiple inheritance of classes, which Java replaces by interfaces. Java has automatic garbage collection instead of manual free() or delete. All Java code lives inside classes.
Java and the Internet
Java was the first language designed with the internet in mind. Java applets could be downloaded and run safely in a browser, and Java's networking classes make internet programs easy. Today Java runs web servers (servlets, Spring), Android apps and big-data systems such as Hadoop.
Table 1.2: Java compared with C and C++
| Feature | C | C++ | Java |
|---|---|---|---|
| Paradigm | Procedural | Procedural and OOP | Pure OOP style |
| Pointers | Yes | Yes | No |
| Multiple inheritance | — | Yes | Through interfaces |
| Memory release | free() | delete | Garbage collection |
| Platform | Dependent | Dependent | Independent (bytecode) |
Example 1.2: Which feature?
Problem: Name the Java feature behind each fact: (a) a .class file compiled on Windows runs on Linux, (b) memory is freed automatically, (c) a program can download files while playing music, (d) there are no pointers to misuse.
Solution:
- Running unchanged on another system is platform independence.
- Automatic freeing is garbage collection, part of robustness.
- Doing two tasks at once is multithreading.
- No pointers makes Java simple and secure.
Result: (a) platform independent, (b) robust, (c) multithreaded, (d) secure and simple.
public class Features {
public static void main(String[] args) {
String v = System.getProperty("java.specification.version");
System.out.println("Java version: " + v);
System.out.println("int is always " + Integer.SIZE + " bits");
System.out.println("long is always " + Long.SIZE + " bits");
System.out.println("char is " + Character.SIZE + " bits");
}
}
Output
Java version: 11
int is always 32 bits
long is always 64 bits
char is 16 bits
Common mistakes
- Saying that Java has no inheritance of multiple types. It allows multiple interfaces.
- Thinking that Java is only interpreted. The JIT compiler makes it fast.
- Believing that platform independence means the JVM itself is the same everywhere. Each platform has its own JVM.
Key takeaways
- Java was created by James Gosling at Sun in 1991 and released in 1995.
- Write once, run anywhere: bytecode runs on any JVM.
- Java removes pointers, goto, structures, operator overloading and multiple class inheritance.
- Features include robust, secure, multithreaded and distributed.
Practice questions
- Who developed Java?
- Why is Java platform independent?
- Name two C++ features removed from Java.
Answers to the practice questions
- James Gosling and his team at Sun Microsystems.
- Because it compiles to bytecode, which runs on a JVM available for every platform.
- Pointers and operator overloading (also goto, multiple class inheritance).
Sources
- Official BCA syllabus Object Oriented Programming using Java, course code 25BCA402SEC01, Unit I
