0% found this document useful (0 votes)
6 views

Java-viva and questionaire

The document provides a comprehensive overview of various Java concepts, including JVM, bytecode, OOP principles, and data types. It explains key differences between JRE and JDK, access modifiers, and the use of constructors and interfaces. Additionally, it covers exception handling, multithreading, and the distinctions between different Java constructs such as arrays and vectors.

Uploaded by

akashjyothi0
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Java-viva and questionaire

The document provides a comprehensive overview of various Java concepts, including JVM, bytecode, OOP principles, and data types. It explains key differences between JRE and JDK, access modifiers, and the use of constructors and interfaces. Additionally, it covers exception handling, multithreading, and the distinctions between different Java constructs such as arrays and vectors.

Uploaded by

akashjyothi0
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

# 1. What is JVM?

(5 marks)
JVM (Java Virtual Machine) is a software that runs Java bytecode on a
computer. It provides a platform-independent environment for running Java
programs. The JVM interprets the bytecode and executes the instructions,
providing memory management, security, and other features. The JVM also
provides a sandboxed environment for running Java programs, which ensures
that the programs cannot access sensitive data or cause harm to the system.

# 2. What is bytecode? (5 marks)


Bytecode is the intermediate code generated by the Java compiler. It is
platform-independent and can be executed by the JVM on any machine.
Bytecode is stored in .class files and is executed by the JVM at runtime. The
bytecode contains instructions that are specific to the JVM, rather than the
underlying hardware. This allows Java programs to be portable across different
platforms.

# 3. What do you mean by literals in Java? (5 marks)


Literals in Java are constant values that can be assigned to variables. Examples
include integer literals (e.g., 10), floating-point literals (e.g., 3.14), character
literals (e.g., 'a'), string literals (e.g., "hello"), and boolean literals (e.g., true).
Literals are used to represent fixed values in a Java program. They are used to
initialize variables, pass arguments to methods, and return values from
methods.

# 4. Difference between JRE and JDK? (5 marks)


JRE (Java Runtime Environment) is a subset of JDK (Java Development Kit) that
includes only the JVM and libraries. JDK includes development tools like the
compiler, debugger, and profiler, in addition to the JRE. Developers need JDK
to develop Java programs, while users only need JRE to run Java programs. The
JRE provides the necessary libraries and runtime environment for running Java
programs, while the JDK provides the necessary tools for developing and
debugging Java programs.

# 5. What are the OOPS concepts? (5 marks)


OOPS (Object-Oriented Programming) concepts include Encapsulation,
Abstraction, Inheritance, Polymorphism, and Composition. Encapsulation
refers to the hiding of data and behavior within an object. Abstraction refers to
the showing of only essential features of an object. Inheritance refers to the
creation of a new class based on an existing class. Polymorphism refers to the
ability of an object to take on multiple forms. Composition refers to the
creation of objects from other objects.

# 6. What do you mean by garbage collection? (5 marks)


Garbage collection is the process by which the JVM automatically reclaims
memory occupied by objects that are no longer in use. This eliminates memory
leaks and reduces the risk of memory-related errors. The JVM's garbage
collector periodically identifies unreachable objects and frees up their
memory. Garbage collection is an important feature of the JVM, as it allows
developers to focus on writing code without worrying about memory
management.

# 7. Explain different primitive data types? (5 marks)


Primitive data types in Java include byte, short, int, long, float, double, char,
and boolean. The byte data type is an 8-bit signed integer, while the short data
type is a 16-bit signed integer. The int data type is a 32-bit signed integer, while
the long data type is a 64-bit signed integer. The float data type is a 32-bit
floating-point number, while the double data type is a 64-bit floating-point
number. The char data type is a 16-bit unsigned character, while the boolean
data type is a true or false value.

# 8. What are the different access modifiers in Java? (5 marks)


Access modifiers in Java include public, private, protected, and default (no
modifier). The public access modifier allows access from anywhere, while the
private access modifier allows access only within the same class. The protected
access modifier allows access within the same class and subclasses, while the
default access modifier allows access within the same package.

# 9. What do you mean by polymorphism? (5 marks)


Polymorphism is the ability of an object to take on multiple forms, depending
on the context in which it is used. This can be achieved through method
overloading (multiple methods with the same name but different parameters)
or method overriding (a subclass providing a different implementation of a
method already defined in its superclass). Polymorphism allows for more
flexibility and generic code, as objects of different classes can be treated as
objects of a common superclass.

# 10. What is inheritance? (5 marks)


Inheritance is the mechanism by which one class can inherit the properties and
behavior of another class. The subclass (or derived class) inherits all the fields
and methods of the superclass (or base class) and can also add new fields and
methods or override the ones inherited from the superclass. Inheritance allows
for code reuse and facilitates the creation of a hierarchy of related classes.
# 11. What are the different types of inheritance? (5 marks)
Types of inheritance include single inheritance, multiple inheritance,
multilevel inheritance, hierarchical inheritance, and hybrid inheritance. Single
inheritance refers to a subclass inheriting from a single superclass. Multiple
inheritance refers to a subclass inheriting from multiple superclasses.
Multilevel inheritance refers to a subclass inheriting from a superclass that
itself inherits from another superclass.

# 12. Difference between subclass and superclass? (5 marks)


A subclass (or derived class) inherits properties and behavior from a superclass
(or base class). The subclass inherits all the fields and methods of the
superclass and can also add new fields and methods or override the ones
inherited from the superclass. The superclass provides a common base for
multiple subclasses, allowing for code reuse and facilitating the creation of a
hierarchy of related classes.

# 13. What is an abstract class? (5 marks)


An abstract class is a class that cannot be instantiated and is intended to be
inherited by other classes. An abstract class can have both abstract methods
(methods declared without an implementation) and concrete methods
(methods with an implementation). Abstract classes are used to provide a
partial implementation of a class, which can then be completed by subclasses.

# 14. What is the difference between this keyword and super keyword? (5
marks)
The this keyword refers to the current object, while the super keyword refers to
the parent class. The this keyword is used to access the fields and methods of
the current object, while the super keyword is used to access the fields and
methods of the parent class. The super keyword is often used in subclasses to
override the methods of the parent class.

# 15. What is a class and an object? (5 marks)


A class is a blueprint for creating objects, which are instances of the class. A
class defines the properties and behavior of an object, including its fields and
methods. An object is an instance of a class, and has its own set of attributes
(data) and methods (functions). Objects are created from classes using the new
keyword.

# 16. What is a constructor? (5 marks)


A constructor is a special method that is called when an object is created, used
to initialize the object's state. A constructor has the same name as the class and
no return type, not even void. Constructors are used to set the initial state of an
object, such as setting the values of its fields.

# 17. Different types of constructors? (5 marks)


Types of constructors include default constructors, parameterized
constructors, and copy constructors. A default constructor is a constructor with
no parameters, used to create an object with default values. A parameterized
constructor is a constructor with parameters, used to create an object with
specific values. A copy constructor is a constructor that creates a copy of an
existing object.

# 18. What is an interface? (5 marks)


An interface is an abstract class that defines a contract for other classes to
follow. An interface defines a set of methods that must be implemented by any
class that implements it. Interfaces are used to define a common set of methods
that can be called by other classes, without specifying how those methods are
implemented.

# 19. Difference between array and vector? (5 marks)


An array is a fixed-size collection of elements, while a Vector is a dynamic-size
collection of elements. An array has a fixed size that is specified when it is
created, while a Vector can grow or shrink as elements are added or removed.
Arrays are more efficient than Vectors, but Vectors provide more flexibility and
functionality. Vectors also provide methods for inserting, deleting, and
manipulating elements, which are not available in arrays.

# 20. What is overloading and overriding? (5 marks)


Overloading is when multiple methods with the same name can be defined with
different parameters, allowing for more flexibility and generic code. Overriding
is when a subclass provides a different implementation of a method already
defined in its superclass, allowing for more specific and customized behavior.
Overloading is resolved at compile-time, while overriding is resolved at
runtime. Both overloading and overriding are important concepts in object-
oriented programming.

# 21. What is a file? (5 marks)


A file is a collection of data stored on a computer's disk. Files can contain text,
images, audio, video, or other types of data. Files are used to store and retrieve
data, and are an essential part of computer programming. Files can be created,
read, written, and deleted using various programming languages and operating
systems. Understanding how to work with files is an important skill for
programmers.
# 22. Different methods to read data from the keyboard? (5 marks)
Methods to read data from the keyboard include using the Scanner class,
BufferedReader class, and DataInputStream class. The Scanner class provides a
simple and convenient way to read data from the keyboard, while the
BufferedReader class provides a more efficient and flexible way to read data.
The DataInputStream class provides a way to read binary data from the
keyboard. Each method has its own strengths and weaknesses, and the choice
of method depends on the specific requirements of the program.

# 23. What is multithreading? (5 marks)


Multithreading is the ability of a program to execute multiple threads or flows
of execution concurrently. Multithreading allows a program to perform
multiple tasks simultaneously, improving responsiveness and throughput.
Multithreading is particularly useful in programs that require concurrent
execution of multiple tasks, such as web servers, database servers, and
graphical user interfaces. Understanding multithreading is an important skill
for programmers who want to create efficient and responsive programs.

# 24. What is a package? (5 marks)


A package is a collection of related classes and interfaces. Packages provide a
way to organize and structure code, making it easier to find and use related
classes and interfaces. Packages also provide a way to control access to classes
and interfaces, allowing developers to hide implementation details and expose
only the necessary interfaces. Understanding packages is an important skill for
programmers who want to create well-organized and maintainable code.

# 25. What is an exception? (5 marks)


An exception is an event that occurs during the execution of a program that
disrupts the normal flow of instructions. Exceptions can be caused by a variety
of factors, including errors in the code, unexpected user input, or system
failures. Exceptions are used to signal that something has gone wrong, and
provide a way to handle and recover from errors. Understanding exceptions is
an important skill for programmers who want to create robust and reliable
programs.

# 26. Difference between exception and error? (5 marks)


An exception is a condition that can be anticipated and handled, while an error
is a condition that cannot be anticipated or handled. Exceptions are typically
caused by errors in the code or unexpected user input, while errors are
typically caused by system failures or other external factors. Exceptions can be
caught and handled using try-catch blocks, while errors typically require more
drastic measures, such as restarting the program or system.

# 27. Difference between throw and throws? (5 marks)


The throw keyword is used to explicitly throw an exception, while the throws
keyword is used to declare that a method may throw an exception. The throw
keyword is used to signal that an exception has occurred, while the throws
keyword is used to warn other developers that a method may throw an
exception. The throw keyword is typically used in the body of a method, while
the throws keyword is typically used in the method signature.

# 28. Difference between final and finally? (5 marks)


The final keyword is used to declare a variable, method, or class that cannot be
modified. Once a variable is declared as final, its value cannot be changed. A
final method cannot be overridden in a subclass, and a final class cannot be
subclassed. The finally keyword, on the other hand, is used to declare a block
of code that will be executed regardless of whether an exception is thrown. The
finally block is typically used to release resources, such as closing files or
database connections.

# 29. Is multiple inheritance possible in Java? Justify (5 marks)


No, multiple inheritance is not possible in Java. A class can only extend one
superclass. This is because Java's designers wanted to avoid the complexity and
ambiguity that can arise from multiple inheritance. Instead, Java provides
interfaces, which allow a class to implement multiple interfaces while still only
extending one superclass. This approach provides many of the benefits of
multiple inheritance while avoiding its drawbacks.

# 30. What is an Applet? (5 marks)


An applet is a small Java program that runs in a web browser. Applets are
typically used to provide interactive content, such as games, animations, or
other multimedia experiences. Applets are downloaded from a web server and
run on the client's machine, using the Java Virtual Machine (JVM) that is built
into the web browser. Applets are subject to certain security restrictions, such
as being unable to access the local file system or network.

# 31. Difference between string and stringbuffer? (5 marks)


A String is an immutable sequence of characters, meaning that once a String is
created, its contents cannot be changed. This makes Strings thread-safe and
efficient, but it also means that certain operations, such as concatenation,
require the creation of a new String object. A StringBuffer, on the other hand, is
a mutable sequence of characters, meaning that its contents can be changed
after it is created. This makes StringBuffers more flexible than Strings, but also
more complex and potentially less efficient.
# 32. Difference between break and continue? (5 marks)
The break statement is used to exit a loop or switch statement prematurely.
When a break statement is encountered, the loop or switch statement is
terminated, and execution continues with the next statement after the loop or
switch. The continue statement, on the other hand, is used to skip the
remainder of the current iteration of a loop and move on to the next iteration.
When a continue statement is encountered, the current iteration is terminated,
but the loop continues with the next iteration.

You might also like