←Back to Subject
Notes
Notes
Study material and explanations
Diagrams
Diagrams
Visualize concepts easily
Mnemonics
Mnemonics
Tricks to remember faster
One Night Prep
One Night Prep
Short and focused revision
Revision
Revision
Quick summary and key points
Important Questions
Important Questions
Practice most relevant questions
Notes

History, Features of Java, C++ vs Java & OOPs Concepts

Study material and explanations for Unit 1

History, Features of Java, C++ vs Java & OOPs Concepts

1. Introduction to Java

Java is a high-level, class-based, object-oriented, and platform-independent programming language. It follows the famous principle of WORA (Write Once, Run Anywhere), meaning compiled Java code can run on any operating system (Windows, Linux, macOS, Android) that has a Java Virtual Machine (JVM) installed, without needing to be recompiled.

Simple Real-Life Analogy: Think of C/C++ like regional languages—if you write a letter in Marathi, only someone who knows Marathi can read it. Java is like translating your letter into Universal English (Bytecode), and every state has a local translator (JVM) who reads that English letter to the locals in their native tongue!


2. History of Java

Java was developed by James Gosling (known as the Father of Java) and his team (Mike Sheridan and Patrick Naughton), collectively called the Green Team, at Sun Microsystems in 1991 (later acquired by Oracle Corporation in 2010).

  • Original Goal (1991): The Green Team started the Green Project to create a small, reliable, and portable language for consumer electronic devices like TV set-top boxes, VCRs, and washing machines.
  • Why “Oak”? James Gosling initially named the language Greentalk (with .gt extension) and later renamed it Oak after an oak tree standing outside his office window.
  • Why renamed to “Java” (1995)? “Oak” was already a registered trademark of Oak Technologies. While drinking coffee, the team brainstormed names and chose Java (named after Java coffee from Indonesia, which is why Java’s official logo is a steaming coffee cup).
  • Shift to the Internet (1995): With the rise of the World Wide Web, Sun Microsystems realized that the internet needed a portable and secure language that could run on any computer connected to the web. They launched the HotJava web browser and JDK 1.0 in January 1996.

3. Features of Java (Java Buzzwords)

The creators of Java published a whitepaper listing the core design goals of the language, famously called Java Buzzwords. This is a guaranteed 5- to 8-mark question in DAVV exams!

Figure 1.1: Core Features of Java (The Java Buzzwords)
1. Simple
Clean syntax based on C++, no pointers or operator overloading
2. Object-Oriented
Everything in Java revolves around Classes and Objects
3. Platform Independent
Compiles to Bytecode (.class) that runs on any OS with a JVM
4. Secured
No explicit pointers; runs inside a protected JVM Sandbox
5. Robust
Strong memory management, Automatic Garbage Collection & Exception Handling
6. Multithreaded
Executes multiple tasks simultaneously using built-in Thread support
  1. Simple: Java is easy to learn because its syntax is clean and based on C++. Confusing and error-prone features of C++ like explicit pointers, operator overloading, and multiple inheritance through classes were removed.
  2. Object-Oriented: In Java, everything is modeled as an Object that combines data (fields) and behavior (methods). You cannot write even a single function in Java outside a class.
  3. Platform Independent: Unlike C/C++, which compile into OS-specific machine code (.exe), Java compiles into intermediate Bytecode (.class), which can run on Windows, Linux, or Mac via the JVM.
  4. Secured: Java is ideal for networked environments because:
    • It has no explicit pointers (preventing unauthorized memory access).
    • Programs run inside a virtual JVM Sandbox.
    • A Bytecode Verifier checks code for illegal access before execution.
  5. Robust (Strong & Reliable): Java prevents program crashes using:
    • Strong compile-time and runtime type checking.
    • Automatic Garbage Collection (automatically frees unused memory, preventing memory leaks).
    • Built-in Exception Handling (try-catch) to handle runtime errors gracefully.
  6. Architecture Neutral: In C/C++, an int may take 2 bytes on a 16-bit machine and 4 bytes on a 32-bit machine. In Java, an int is always 4 bytes regardless of hardware architecture.
  7. Portable: Java bytecode can be carried to any platform without making any changes to the source code.
  8. Compiled and Interpreted: Java uses a two-stage system: first, the javac compiler translates source code into bytecode; second, the JVM interprets (and JIT-compiles) the bytecode into machine code.
  9. High Performance: Although interpreted languages are usually slower than C++, Java achieves high speed using the JIT (Just-In-Time) Compiler, which compiles frequently used bytecode blocks into native machine code on the fly.
  10. Multithreaded: Java supports running multiple sub-processes (threads) concurrently within a single program (e.g., downloading a file in the background while keeping the UI responsive).
  11. Distributed: Java provides networking libraries (java.net, RMI) to easily build distributed applications that share data across networks.

4. C++ vs Java (Detailed Comparison)

This is one of the most frequently asked questions in Unit 1 of DAVV BCA exams.

Feature / Basis C++ Java
1. Platform Dependency Platform Dependent (compiles directly into OS-specific machine code). Platform Independent (compiles into portable Bytecode executed by JVM).
2. Programming Paradigm Both Procedural and Object-Oriented (can write main() outside a class). Strictly Object-Oriented (every function, including main(), must be inside a class).
3. Pointers Strongly supports explicit Pointers (*ptr, &x) and pointer arithmetic. No explicit Pointers available to programmers (handled internally for security).
4. Memory Management Manual memory allocation and deallocation using new and delete. Automatic Garbage Collection frees unused objects automatically (no delete keyword).
5. Multiple Inheritance Supports multiple inheritance directly using classes (causes the Diamond Problem). Does not support multiple inheritance through classes; achieved safely via Interfaces.
6. Operator Overloading Allows programmers to overload operators (+, -, <<). No operator overloading allowed (except + which is built-in for string concatenation).
7. Header Files & Preprocessor Uses preprocessor directives (#include <iostream>, #define). No preprocessor or header files; uses package and import statements.
8. Destructors Has explicit Destructors (~ClassName()) to clean up resources. No destructors; relies on the Garbage Collector.
9. goto Statement Supports goto statement for unconditional jumps. goto is a reserved keyword but is not used; uses labeled break and continue instead.
10. Call by Value / Reference Supports both Call by Value and Call by Reference (using &). Everything in Java is strictly Pass by Value (for objects, the reference value is passed).

5. OOPs Concepts in Java (The 4 Pillars + Core Building Blocks)

Object-Oriented Programming (OOP) is a programming methodology that organizes software design around real-world objects and data rather than functions and logic alone.

A. Basic Building Blocks: Class and Object

  1. Object: Any real-world entity that has State (attributes/data) and Behavior (actions/methods).
    • Example: A Student object has State (rollNo = 101, name = "Aarav") and Behavior (attendClass(), giveExam()).
  2. Class: A logical blueprint, template, or prototype from which individual objects are created. A class does not consume memory until an object of that class is instantiated.
    • Example: An architect’s building map is a Class, whereas the actual houses built using that map are Objects.

B. The 4 Pillars of OOPs

Figure 1.2: The 4 Pillars of Object-Oriented Programming (OOP)
1. Encapsulation
Binding data (private variables) and methods together into a single capsule (Class)
2. Abstraction
Hiding complex internal implementation details and showing only essential features
3. Inheritance
Child class acquiring properties and behaviors of a Parent class (Code Reusability)
4. Polymorphism
"One name, many forms" — achieved via Method Overloading and Method Overriding

1. Encapsulation (Data Wrapping & Hiding)

  • Definition: Wrapping up data (variables) and code acting on the data (methods) together into a single unit (a class), while restricting direct external access to the data using private variables and public getter/setter methods.
  • Real-Life Example: A medical capsule wraps several medicines inside one shell. Or your ATM Bank Balance—nobody can directly edit your balance variable; they must go through verified methods like deposit() or withdraw().

2. Abstraction (Hiding Complexity)

  • Definition: Hiding internal implementation details and displaying only the essential functionality to the user. In Java, abstraction is achieved using Abstract Classes (abstract) and Interfaces (interface).
  • Real-Life Example: When you press the brake pedal in a car or send a UPI payment on PhonePe, you only see the button and confirmation screen—you don’t see the complex hydraulic mechanics or banking server handshakes happening underneath.

3. Inheritance (IS-A Relationship / Reusability)

  • Definition: The mechanism by which one class (Child / Subclass) acquires all the properties and behaviors of another class (Parent / Superclass) using the extends keyword.
  • Benefit: Promotes Code Reusability and enables runtime polymorphism.
  • Real-Life Example: SavingsAccount and CurrentAccount inherit common attributes (accountNo, balance, deposit()) from a parent BankAccount class.

4. Polymorphism (“One Name, Many Forms”)

  • Definition: The ability of a single method or action to behave differently depending on the context or the object calling it.
  • Two Types in Java:
    1. Compile-Time Polymorphism (Method Overloading): Multiple methods in the same class having the same name but different parameter lists (e.g., add(int a, int b) and add(double a, double b)).
    2. Runtime Polymorphism (Method Overriding): A child class providing its own specific implementation of a method already defined in its parent class (e.g., Bank.getInterestRate() overridden by SBI to return 6.5% and HDFC to return 7.0%).

💡 Exam Preparation Tips for DAVV BCA

  • 5-Mark Question: “Why is Java called a Platform-Independent and Robust language?” Always draw the compilation flow (.java → javac → .class Bytecode → JVM) and mention Automatic Garbage Collection + Exception Handling for Robustness.
  • 8-Mark Question: “Differentiate between C++ and Java” or “Explain the features (buzzwords) of Java in detail.” Write at least 8–10 points with clear headings.