Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Java Programming Language: JVM, JDK, JRE, Features, Inheritance, Interfaces, and more, Exams of Java Programming

Answers to various questions related to the Java programming language. It explains the concept of JVM, the difference between JDK and JRE, the features of Java, the differences between C++ and Java, and more. It also covers topics such as inheritance, interfaces, method overloading and overriding, command line arguments, arrays, abstract classes, and bytecode. useful for students who are learning Java programming language or preparing for exams related to it.

Typology: Exams

2022/2023

Available from 11/23/2023

rutvi-darji
rutvi-darji 🇮🇳

3 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1. What is JVM? Why is Java called the "Platform Independent Programming
Language”?
ANS:- Java is platform-independent because it uses a virtual machine.
The Java programming language and all APIs are compiled into bytecodes.
Bytecodes are effectively platform-independent. The virtual machine takes
care of the differences between the bytecodes for the different platforms.
2. What is the Difference between JDK and JRE?
ANS:- JDK is for development purpose whereas JRE is for running the
java programs. JDK and JRE both contains JVM so that we can run our java
program. JVM is the heart of java programming language and provides platform
independence.
3. What is Java?
ANS:- Java is an object-oriented programming language. Everything in Java
is associated with classes and objects, along with its attributes and methods.
For example: in real life, a car is an object. The car has attributes, such as
weight and color, and methods, such as drive and brake.
4. What are the differences between C++ and Java?
ANS:- C++ supports features like operator overloading, Goto statements,
structures, pointers, unions, etc. Java does not support features like operator
overloading, Goto statements, structures, pointers, unions, etc. C ++ is only
compiled and cannot be interpreted. Java can be both compiled and interpreted.
5. List the features of Java Programming language.
ANS:- Major Features of Java Programming Language
Simple.
Object-Oriented.
Platform Independent.
Portable.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Java Programming Language: JVM, JDK, JRE, Features, Inheritance, Interfaces, and more and more Exams Java Programming in PDF only on Docsity!

  1. What is JVM? Why is Java called the "Platform Independent Programming Language”? ANS:- Java is platform-independent because it uses a virtual machine. The Java programming language and all APIs are compiled into bytecodes. Bytecodes are effectively platform-independent. The virtual machine takes care of the differences between the bytecodes for the different platforms.
  2. What is the Difference between JDK and JRE? ANS:- JDK is for development purpose whereas JRE is for running the java programs. JDK and JRE both contains JVM so that we can run our java program. JVM is the heart of java programming language and provides platform independence.
  3. What is Java? ANS:- Java is an object-oriented programming language. Everything in Java is associated with classes and objects, along with its attributes and methods. For example: in real life, a car is an object. The car has attributes, such as weight and color, and methods, such as drive and brake.
  4. What are the differences between C++ and Java? ANS:- C++ supports features like operator overloading, Goto statements, structures, pointers, unions, etc. Java does not support features like operator overloading, Goto statements, structures, pointers, unions, etc. C ++ is only compiled and cannot be interpreted. Java can be both compiled and interpreted.
  5. List the features of Java Programming language. ANS:- Major Features of Java Programming Language
    • Simple.
    • Object-Oriented.
    • Platform Independent.
    • Portable.
  • Robust.
  • Secure.
  • Interpreted.
  • Multi-Threaded.
  1. What do you understand by Java virtual machine? ANS:- A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The Java Virtual Machine, or JVM, is an abstract computer that runs compiled Java programs. The JVM is "virtual" because it is generally implemented in software on top of a "real" hardware platform and operating system. All Java programs are compiled for the JVM.
  2. What is the difference between JDK, JRE, and JVM? ANS:- JDK vs JRE vs JVM JDK is for development purpose whereas JRE is for running the java programs. JDK and JRE both contains JVM so that we can run our java program. JVM is the heart of java programming language and provides platform independence.
  3. What is JIT compiler? ANS:- The Just-In-Time (JIT) compiler is a component of the runtime environment that improves the performance of Java™ applications by compiling bytecodes to native machine code at run time.
  4. What gives Java its 'write once and run anywhere' nature? ANS:- What gives Java its 'write once and run anywhere' nature? The Bytecode. Java compiler converts the Java programs into the class file (Byte Code) which is the intermediate language between source code and machine code. This bytecode is not platform-specific and can be executed on any computer.

ANS:- In the Java programming language, an object is an instance of a Java class, meaning it is a copy of a specific class. Java objects have three primary characteristics: identity, state, and behavior. These characteristics are the building blocks of any class object and set the scene for how they are used.

  1. Why is the main method static? ANS:- The main() method is declared static so that JVM can call it without creating an instance of the class containing the main() method. We must declare the main() function static as no class object is present when the java runtime starts. JVM can then load the class into the main memory and invoke the main() method.
  2. What is the static block? ANS:- n a Java class, a static block is a set of instructions that is run only once when a class is loaded into memory. A static block is also called a static initialization block. This is because it is an option for initializing or setting up the class at run-time.
  3. Can we execute a program without main() method? ANS:- Yes, we can execute a java program without a main method by using a static block. Static block in Java is a group of statements that gets executed only once when the class is loaded into the memory by Java ClassLoader, It is also known as a static initialization block
  4. Can we make the abstract methods static in Java? ANS:- Declaring abstract method static If you declare a method in a class abstract to use it, you must override this method in the subclass. But, overriding is not possible with static methods. Therefore, an abstract method cannot be static.
  5. What is this keyword in java? ANS:- The this keyword refers to the current object in a method or constructor. The most common use of the this keyword is to eliminate the confusion

between class attributes and parameters with the same name (because a class attribute is shadowed by a method or constructor parameter).

  1. What is the Inheritance? ANS:- Inheritance in Java is the method to create a hierarchy between classes by inheriting from other classes. Java Inheritance is transitive - so if Sedan extends Car and Car extends Vehicle, then Sedan is also inherited from the Vehicle class. The Vehicle becomes the superclass of both Car and Sedan.
  2. Why is Inheritance used in Java? ANS:- The most important use of inheritance in Java is code reusability. The code that is present in the parent class can be directly used by the child class. Method overriding is also known as runtime polymorphism. Hence, we can achieve Polymorphism in Java with the help of inheritance.
  3. Why is multiple inheritance not supported in java? ANS:- The reason behind this is to prevent ambiguity. Consider a case where class B extends class A and Class C and both class A and C have the same method display(). Now java compiler cannot decide, which display method it should inherit. To prevent such situation, multiple inheritances is not allowed in java.
  4. What is super in java? ANS :- The super keyword in Java is a reference variable that is used to refer parent class objects. The super() in Java is a reference variable that is used to refer parent class constructors. super can be used to call parent class' variables and methods. super() can be used to call parent class' constructors only.
  5. What are the main uses of the super keyword? ANS:- The super keyword refers to superclass (parent) objects. It is used to call superclass methods, and to access the superclass constructor. The most common use of the super keyword is to eliminate the confusion between superclasses and subclasses that have methods with the same name.
  6. What are the differences between this and super keyword?

ANS:- Interfaces are used in Java to achieve abstraction. By using the implements keyword, a java class can implement an interface. In general terms, an interface can be defined as a container that stores the signatures of the methods to be implemented in the code segment. It improves the levels of Abstraction.

  1. What is abstract class. ANS:- An abstract class is a class that is declared abstract —it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed.
  2. Why java is called high level language ANS:- Java is a computer programming language. It enables programmers to write computer instructions using English-based commands instead of having to write in numeric codes. It's known as a high-level language because it can be read and written easily by humans.
  3. Explain main method of java ANS:- The Java main method is usually the first method you learn about when you start programming in Java because its the entry point for executing a Java program. The main method can contain code to execute or call other methods, and it can be placed in any class that's part of a program.
  4. What is byte code ANS:- Bytecode in Java is a set of instructions for the Java Virtual Machine. Bytecode is a platform-independent code. Bytecode is a code that lies between low-level language and high-level language. After the Java code is compiled, the bytecode gets generated, which can be executed on any machine using JVM.
  5. What javac and java ANS:- Technically, javac is the program that translates Java code into bytecode (. class file) - an intermediate format which is understandable by the Java Virtual Machine (JVM). And java is the program that starts the JVM, which in turn, loads the. class file, verifies the bytecode and executes it.
  6. What is garbage collection

ANS:- Garbage collection in Java is the automated process of deleting code that's no longer needed or used. This automatically frees up memory space and ideally makes coding Java apps easier for developers. Java applications are compiled into bytecode that may be executed by a JVM.

  1. What are data types ANS:- Data types are divided into two groups:
    • Primitive data types - includes byte , short , int , long , float , double , boolean and char.
    • Non-primitive data types - such as String , Arrays and Classes (you will learn more about these in a later chapter)
  2. Is java pure object oriented language? ANS :- Java is not a fully object-oriented language as it supports primitive data types like int, byte, long, short, etc., which are not objects. Hence these data types like int, float, double, etc., are not object-oriented. That's why Java is not 100% object-oriented.
  3. What is String? ANS:- In Java, a string is an object that represents a number of character values. Each letter in the string is a separate character value that makes up the Java string object. Characters in Java are represented by the char class. Users can write an array of char values that will mean the same thing as a string.
  4. What is polymorphism ANS :- Polymorphism means " many forms ", and it occurs when we have many classes that are related to each other by inheritance. Like we specified in the previous chapter; Inheritance lets us inherit attributes and methods from another class. Polymorphism uses those methods to perform different tasks.
  5. What is dynamic method dispatch ANS:- Dynamic Method Dispatch in Java is the process by which a call to an overridden method is resolved at runtime (during the code execution). The concept of method overriding is the way to attain runtime polymorphism in

as special methods to initialize an object.

  1. Types of exceptions in java. ANS:- There are two kinds of exceptions in Java:
    • Checked exceptions: These are the exceptions that are checked by the compiler at compile time. ...
    • Unchecked exceptions: These are the exceptions that are not checked by the compiler at compile time.
  2. Where is finally block used? ANS:- The finally block in java is used to put important codes such as clean up code e.g. closing the file or closing the connection. The finally block executes whether exception rise or not and whether exception handled or not. A finally contains all the crucial statements regardless of the exception occurs or not.
  3. List types of inheritance ANS:- Java supports only Single, Multilevel, and Hierarchical types of inheritance. Java does not support Multiple and Hybrid inheritance. We have discussed the Multiple inheritance ambiguity and Diamond problem in Java.
  4. Java installation steps. ANS:- Follow these five steps to setup and install Java on Windows:
    1. Download Java for Windows.
    2. Run the Java installer.
    3. Validate the JAVA_HOME setting.
    4. Confirm the Java PATH variable was set properly.
    5. Run a JDK command to verify Java install was a success.