Why is Java called a platform independent language?
Java is platform independent because of the Bytecode. Unlike other languages that compile code into machine-specific instructions, Java compiles source code into Bytecode (.class files). This Bytecode can run on any system that has a Java Virtual Machine (JVM) installed, following the "Write Once, Run Anywhere" (WORA) principle.
What are the various data types used in Java programming?
Java data types are divided into two categories:
Write a Java program to display 'Hello World'.
(i) Discuss the major features of Java.
(ii) Write a Java program to calculate the factorial of a given number.
(i) Write the differences between C++ and Java.
| Feature | C++ | Java |
|---|---|---|
| Platform | Platform Dependent | Platform Independent |
| Pointers | Supports Pointers | No Pointers |
| Inheritance | Multiple Inheritance | Single Inheritance (Classes) |
(ii) Write a Java program to generate Fibonacci series.
How can a multi-dimensional array be used in Java? Give example.
A multi-dimensional array is an array of arrays. It is commonly used to represent matrices.
Write the importance of Scanner class in Java.
The Scanner class (java.util.Scanner) is used to get user input. It can read various data types like int, double, and strings from the console or files.
How does String class differ from String buffer?
(i) Explain method overloading with the help of an example.
Method overloading allows a class to have more than one method with the same name, provided their parameter lists are different
.(ii) What is garbage collection and why is it important?
Garbage collection is the process by which Java programs perform automatic memory management. It deletes unused objects to free up heap memory, preventing memory leaks.
What is wrapper class?
A wrapper class is a class whose object wraps or contains primitive data types (e.g., Integer for int, Double for double)
.Define method overriding.
Method overriding occurs when a subclass provides a specific implementation for a method already defined in its parent class
.(i) Why does Java not support multiple inheritance? Write code for multilevel inheritance.
Java avoids multiple inheritance to prevent ambiguity (the Diamond Problem). If two parent classes have the same method, the compiler wouldn't know which one to inherit.
(ii) Discuss dynamic method dispatch.
Dynamic method dispatch is the mechanism by which a call to an overridden method is resolved at runtime rather than compile-time
.Define exception. How does exception differ from error?
(i) What is multithreading? Write benefits.
Multithreading is a Java feature that allows concurrent execution of two or more parts of a program for maximum utilization of CPU
.(ii) Explain steps to create your own exception.
Exception.throw to trigger it(i) Differences between AWT and Swing.
| AWT | Swing |
|---|---|
| Heavyweight | Lightweight |
| Platform Dependent | Platform Independent |
(ii) Design a simple calculator using Java Swing.