1.
Explain the main features of Java
Introduction
Java is a high-level, general-purpose programming language developed to be simple, secure, and
platform independent. It is widely used for developing standalone, web, and enterprise applications.
Simple
Java is simple to learn and use because complex features such as pointers and operator overloading
are removed.
It follows C and C++ syntax, making it familiar to programmers.
Object-Oriented
Java is a purely object-oriented language.
All programs are written using classes and objects.
Objects represent real-world entities and contain data and methods.
Distributed
Java supports distributed applications through network protocols such as TCP/IP and UDP.
It also supports Remote Method Invocation (RMI) which allows methods to run on different
systems.
Robust
Java is robust because of:
• Exception handling mechanism
• Automatic memory management
• Compile-time and run-time error checking
These features prevent system crashes and data loss.
Secure
Java provides strong security features for internet-based applications.
Security threats such as viruses, hacking, and unauthorized access are reduced.
Platform Independent
Java programs are compiled into bytecode which can run on any system with JVM.
Hence Java follows “Write Once, Run Anywhere”.
Multithreaded
Java supports multithreading which allows multiple tasks to run simultaneously, improving
performance.
Dynamic
Java supports dynamic loading of classes and creation of interactive applications like applets.
Conclusion
Due to these features, Java is reliable, secure, and widely used in software development.
2. Explain object-oriented programming
concepts supported by Java
Introduction
Object-Oriented Programming (OOP) is a programming approach based on objects and classes.
Java strictly follows OOP principles to improve code quality and reusability.
Object
An object is a real-world entity.
It has state (data) and behavior (methods).
Example: A Car object has color, speed, and methods like start().
Class
A class is a blueprint for creating objects.
It de nes variables and methods common to all objects of that class.
Encapsulation
Encapsulation means binding data and methods into a single unit.
Data is hidden using private variables and accessed through public methods.
This improves security and data protection.
Inheritance
Inheritance allows one class to acquire properties and methods of another class.
It promotes code reuse and reduces duplication.
Polymorphism
Polymorphism allows one method to have many forms.
It is achieved using:
• Method overloading
fi
• Method overriding
This improves exibility in programs.
Abstraction
Abstraction hides implementation details and shows only essential features.
It is implemented using abstract classes and interfaces.
Conclusion
These OOP concepts make Java programs modular, reusable, secure, and easy to maintain.
3. What is Java bytecode? Explain the role of
JVM and platform independence
Java Bytecode
Java bytecode is an intermediate code generated after compilation of a Java program.
It is not speci c to any machine or operating system.
Role of Compiler
The Java compiler converts source code into bytecode.
This bytecode is stored in a .class le.
Role of JVM
Java Virtual Machine (JVM) acts as an interpreter.
It converts bytecode into machine code according to the operating system.
JVM also manages memory, security, and execution.
Platform Independence
Different JVMs exist for different platforms.
The same bytecode runs on all systems having JVM.
No changes are required in the source code.
Conclusion
Thus, bytecode and JVM together make Java a platform-independent language.
4. Explain various data types in Java
Introduction
fi
fl
fi
Data types specify the type of value a variable can store.
They help in memory allocation and ef cient program execution.
Primitive Data Types
Primitive data types store simple values:
• int – stores integers
• oat and double – store decimal values
• char – stores characters
• boolean – stores true or false
• byte, short, long – store integer values of different sizes
Non-Primitive Data Types
Non-primitive data types store complex data:
• String – stores text
• Arrays – store multiple values of same type
• Classes – user-de ned data types
• Interfaces – de ne abstract behavior
Conclusion
Proper use of data types improves performance and reduces memory wastage.
5. Write Once Run Anywhere – Justify
Meaning
Write Once Run Anywhere means writing a Java program once and running it on any platform.
Explanation
Java compiler converts source code into bytecode.
Bytecode is architecture-neutral.
JVM executes bytecode according to the system.
The same program runs on Windows, Linux, and macOS.
Advantages
• No need to rewrite code for different systems
fl
fi
fi
fi
• Easy portability
• Saves time and cost
Conclusion
Thus Java successfully supports the principle of Write Once, Run Anywhere.