Java Viva
Java Viva
1. What is Java?
o Answer:
JDK (Java Development Kit): A full software development kit that includes
the JRE and development tools such as the compiler (javac), debugger, and
documentation generator.
JVM (Java Virtual Machine): A virtual machine that runs Java bytecode and
allows Java programs to be platform-independent by abstracting the
underlying OS.
4. What are primitive data types in Java? Can you name them?
o Answer: Primitive data types are basic types that are built into Java. They include:
5. What are control structures in Java? Can you give examples of loops and conditionals?
o Answer: The static keyword is used to declare class-level variables and methods that
are shared by all instances of a class. It means that the member belongs to the class
rather than an instance of the class. For example, static int count; means count is
shared across all objects of the class.
o Answer: A method is a block of code that performs a specific task. It is defined with a
return type, name, and parameters.
System.out.println("Hello!");
}
Method call:
o Answer: The main method is the entry point for any Java application. It is where the
program starts execution. It must be defined as public static void main(String[] args).
9. Explain the concept of type casting in Java. What is the difference between implicit and
explicit type casting?
o Answer: Type casting is the process of converting one data type to another.
o Answer:
== compares the references of two objects (i.e., whether they point to the
same memory location).
Example:
public Car() {
System.out.println("Car created!");
}
}
14. What are arrays in Java? How do you declare and initialize an array?
Or initialized directly:
o Answer: void indicates that the method does not return any value. If a method is
defined with void, it performs an action but does not return anything to the caller.
Object-Oriented Programming (OOP) Concepts in Java:
1. What is Object-Oriented Programming (OOP)? Can you list and explain its main principles?
o Answer: Inheritance allows a new class to acquire properties and methods from an
existing class. It is implemented using the extends keyword.
o class Animal {
o }
o }
3. Can you explain the difference between extends and implements in Java?
o Answer:
Example:
class Animal {
}
5. What is method overloading and method overriding in Java? How do they differ?
o Answer:
Method Overloading: Defining multiple methods with the same name but
different parameters.
o class Employee {
o return salary;
o }
o this.salary = salary;
o }
o }
o }
8. Can you explain the concept of "super" keyword in Java and give an example of its use?
o Answer: The super keyword refers to the superclass (parent class). It is used to call
the parent class's constructor or methods.
o class Animal {
o Animal() {
o System.out.println("Animal Constructor");
o }
o }
o Dog() {
o System.out.println("Dog Constructor");
o }
o }