Java Notes
Java is a high-level, class-based, object-oriented programming language used to create web applications, backend services, banking systems, Android applications, desktop tools, and large enterprise systems. Java was designed so that a program written on one operating system can run on another without rewriting its source code; this is called platform independence.
Java is a high-level, class-based, object-oriented programming language. It is used to create software such as web applications, backend services, banking systems, Android applications, desktop tools, and large enterprise systems.
Java was designed so that a program written on one operating system can run on another operating system without rewriting the source code. This is why Java is known for platform independence.
Definition of Java
Java is both:
- a programming language used to write instructions for a computer, and
- a platform that provides the runtime environment required to run those instructions.
When a developer writes a Java program, the code is saved in a file ending in .java. The Java compiler converts that source code into a .class file containing bytecode. The Java Virtual Machine (JVM) runs that bytecode on the current computer.
This process is the basis of Java's well-known idea: Write Once, Run Anywhere.
Nature of Java
| Property | Meaning |
|---|---|
| High-level language | Developers write readable statements instead of machine instructions. |
| Object-oriented | Programs are organised using classes and objects. |
| Class-based | A class defines the data and behaviour used to create objects. |
| Statically typed | Every variable has a type that Java checks before running the program. |
| Platform-independent | The same bytecode can run on a compatible JVM on different operating systems. |
| Secure and robust | Java has type checking, exception handling, access control, and automatic memory management. |
| Multithreaded | A Java application can perform more than one task at the same time. |
Why Java is platform-independent
Languages such as C or C++ normally compile source code into machine code for one particular operating system and processor. Java takes a different route: it compiles source code into bytecode.
Bytecode is not directly tied to Windows, Linux, or macOS. Each system uses a JVM implementation that understands the same bytecode.
| Stage | What happens |
|---|---|
| Write | A developer writes Student.java. |
| Compile | javac Student.java creates Student.class. |
| Run | java Student starts the JVM and executes the bytecode. |
Platform-independent does not mean that every Java project works everywhere automatically. File paths, databases, operating-system commands, native libraries, and installed Java versions can still differ.
Where Java is used
Java is common in the following areas:
| Area | Examples |
|---|---|
| Backend development | REST APIs, authentication services, payment systems |
| Enterprise software | Banking, insurance, ERP, inventory, and hospital systems |
| Android ecosystem | Android applications and libraries use Java/JVM concepts |
| Desktop applications | Tools built with JavaFX or Swing |
| Data and distributed systems | Apache Kafka, Hadoop, Elasticsearch, and many server-side systems |
| Developer tools | IDEs, build tools, testing frameworks, and automation software |
Java is not JavaScript
Despite their similar names, Java and JavaScript are different languages.
| Java | JavaScript |
|---|---|
| Runs on the JVM. | Usually runs in browsers or Node.js. |
| Statically typed. | Dynamically typed. |
| Class-based language. | Prototype-based language. |
| Common for backend and enterprise systems. | Common for browser interaction and web frontends. |
Advantages of Java
- Its type system and compiler catch many mistakes before a program runs.
- The JVM makes the language portable across supported operating systems.
- It has a large standard library and a mature ecosystem.
- Automatic garbage collection reduces manual memory-management errors.
- It is widely used in large, long-lived codebases.
Limitations of Java
- A Java application may take more memory and have slower startup than a small native program.
- The JVM must be installed and compatible with the application version.
- Java syntax can be more verbose than some newer languages.
- Garbage collection helps memory management but does not prevent poor program design or memory leaks caused by unnecessary references.
Important terms
| Term | Meaning |
|---|---|
| JDK | Java Development Kit; tools used to write, compile, and run Java programs. |
| JVM | Java Virtual Machine; the runtime that executes Java bytecode. |
| Bytecode | Platform-neutral instructions stored in .class files. |
| Class | A blueprint that defines data and behaviour. |
| Object | A usable instance created from a class. |
Java, therefore, is not only a language for printing a first program. It is a mature software platform used to create maintainable applications that can run across different systems.
Continue the lesson path