0% found this document useful (0 votes)
7 views13 pages

Java Viva Question Answers

The document outlines a practical exam guide for Java programming, detailing essential concepts and questions that students must prepare for. It includes definitions of key Java terms such as JVM, JRE, inheritance, polymorphism, and exception handling, along with practical questions for students to practice. Students are required to bring a printed copy of the document to their practical exams.

Uploaded by

Disha Chouthwani
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views13 pages

Java Viva Question Answers

The document outlines a practical exam guide for Java programming, detailing essential concepts and questions that students must prepare for. It includes definitions of key Java terms such as JVM, JRE, inheritance, polymorphism, and exception handling, along with practical questions for students to practice. Students are required to bring a printed copy of the document to their practical exams.

Uploaded by

Disha Chouthwani
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Lab 6: Programming in Java Java Practical Viva Questions

Note:
1. All the students are required to first prepare answer & concept of
the selected questions which have allotted to the students in the day
of practical exam.
2. Students read and bring printout of this file on the day of pre-
practical and Main practical examination compulsory.

James Gosling is known as the Father of Java because he created Java at Sun Microsystems in
1995.
Java simply supports command line arguments to pass values to the main() method during
program execution. Java receives all command line inputs through the main(String[] args)
method, where the JVM stores each argument as a String element in the array.

1. What is Java?

Java is a high-level, object-oriented, platform-independent programming language.

2. Why is Java platform independent?

Because Java programs run on JVM, not directly on OS.

3. What is JVM?

JVM (Java Virtual Machine) executes Java bytecode.

4. What is JRE?

JRE provides JVM and libraries required to run Java programs.

5. What is JDK?

JDK is a development kit containing JRE plus tools like compiler.

6. What is bytecode?

Bytecode is the intermediate code generated by the Java compiler.

7. What is a class?

A class is a blueprint/template for creating objects.

8. What is an object?

Object is an instance of a class.

9. What is a constructor?

Constructor initializes objects when they are created.


Lab 6: Programming in Java Java Practical Viva Questions

10. What is method overloading?

Same method name with different parameters.

11. What is method overriding?

Child class provides a specific implementation of a parent class method.

12. What is inheritance?

Inheritance allows one class to acquire properties of another.

13. What is polymorphism?

Polymorphism allows the same action to behave differently.

14. What is encapsulation?

Wrapping data and methods into a single unit (class).

15. What is abstraction?

Hiding implementation details and showing only functionality.

16. What is an interface?

Interface is a fully abstract class with only abstract methods (Java 7).

17. What is a package?

Package is a group of related classes and interfaces.

18. What is main() method?

Entry point of a Java program.

19. What is [Link]()?

Method to print output on console.

20. What are data types?

Data types specify the type and size of data.

21. What are primitive data types?

byte, short, int, long, float, double, char, boolean.

22. What is a variable?


Lab 6: Programming in Java Java Practical Viva Questions

A variable stores data values in memory.

23. What is an array?

Array is a collection of similar data types.

24. What is string in Java?

String is an immutable sequence of characters.

25. What is exception?

Exception is an abnormal event that disrupts program flow.

26. What is try-catch?

Used to handle exceptions safely.

27. What is final keyword?

Final makes variable constant, method non-overridable, class non-inheritable.

28. What is static keyword?

Static belongs to the class, not object.

29. What is this keyword?

this refers to the current object.

30. What is super keyword?

super refers to parent class members.

31. What is a nested class?

A class declared inside another class.

32. What is an inner class?

A non-static nested class.

33. What is a static nested class?

A nested class declared with static keyword.

34. Why use inner classes?

To logically group classes and improve encapsulation.


Lab 6: Programming in Java Java Practical Viva Questions

35. Can inner classes access outer class members?

Yes, inner classes can access outer class fields even if privat

36. What is a literal?

A literal is a fixed constant value in a program.

37. What are integer literals?

Whole number values like 10, -5, 100.

38. What is a wrapper class?

A wrapper class converts primitive types into objects.

39. Name any wrapper classes.

Integer, Float, Double, Character, Boolean.

40. What is autoboxing?

Automatic conversion of primitive to wrapper object.

41. What is unboxing?

Automatic conversion of wrapper object to primitive.

42. C++ Vs Java-

A. Platform Dependency

C++ is platform dependent, while Java is platform independent because of JVM.

B. Memory Management

C++ uses manual memory management (pointers, delete), whereas Java uses automatic
garbage collection.

C. Multiple Inheritance

C++ supports multiple inheritance using classes, but Java does NOT support multiple
inheritance through classes (only via interfaces).

___________________________________________________________________________

1. What is a constructor?

A constructor is a special method that initializes an object when it is created.


Lab 6: Programming in Java Java Practical Viva Questions

2. Can a constructor have a return type?

No, constructors do not have a return type.

3. What is a default constructor?

A constructor created automatically when no constructor is defined.

4. What is a parameterized constructor?

Constructor that accepts parameters.

5. Can a constructor call another constructor?

Yes, using this().

6. Can constructors be inherited?

No, constructors are not inherited.

7. Can we use super() in constructor?

Yes, to call parent class constructor.

_____________________________________________________________________________

1. What is inheritance?

It is a feature of OOP to create new class from existing class. Inheritance allows one class to
acquire properties of another class.

2. What is the parent class called?

Parent class is called superclass.

3. What is the child class called?

Child class is called subclass.

4. What is single inheritance?

Inheritance with one parent and one child class.

5. What is multilevel inheritance?

Inheritance where a class inherits from a derived class.

6. Does Java support multiple inheritance?

No, Java does not support multiple inheritance via classes but supported by interface.
Lab 6: Programming in Java Java Practical Viva Questions

7. How do we achieve multiple inheritance in Java?

Using interfaces.

8. What is the use of super?

To access parent class members.

9. What gets inherited in Java?

Non-private variables and methods.

_________________________________________________________________________________

1. What is a package?

Package is a group of related classes and interfaces.

2. What is the main purpose of a package?

To organize classes and avoid name conflicts.

3. What are the types of packages?

Built-in packages and user-defined packages.

4. How do you create a package?

Using package packagename; at the top of the file.

5. How do you access a package?

Using import packagename.*;.

6. Where are compiled package classes stored?

Inside folder structure matching package name.

__________________________________________________________________________________

1. What is an interface?

Interface is a blueprint containing abstract methods.

2. Can an interface have variables?

Yes, but they are public static final by default.

3. Can we instantiate an interface?


Lab 6: Programming in Java Java Practical Viva Questions

No, interfaces cannot be instantiated.

4. How do we implement an interface?

Using implements keyword.

5. Can an interface extend another interface?

Yes, interfaces can extend other interfaces.

6. Can a class implement multiple interfaces?

Yes, a class can implement many interfaces.

7. What type of methods can an interface contain in Java 8+?

Abstract, default, and static methods.

8. Can interfaces support multiple inheritance?

Yes, interfaces allow multiple inheritance.

__________________________________________________________________________________

1. What is an exception?

An exception is an unwanted event that disrupts program flow.

2. What is exception handling?

Exception handling manages runtime errors using try–catch blocks.

3. What is try block?

A try block contains code that may cause an exception.

4. What is catch block?

It handles the exception thrown in the try block.

5. What is finally block?

Finally block always executes, whether exception occurs or not.

6. What is throw keyword?

throw is used to manually throw an exception.

7. What is throws keyword?


Lab 6: Programming in Java Java Practical Viva Questions

throws declares exceptions that a method may throw.

8. What are checked exceptions?

Exceptions checked at compile time.

9. What are unchecked exceptions?

Exceptions checked at runtime.

10. What is Exception class?

It is the superclass of all exception types.

11. Can we have multiple catch blocks?

Yes, multiple catch blocks can be used.

12. Can we handle multiple exceptions in one catch?

Yes, using | (multi-catch).

__________________________________________________________________________________

1. What is a thread?

A thread is the smallest unit of execution in a program.

2. How do you create a thread in Java?

By extending Thread class or implementing Runnable.

3. What is run() method?

The method containing the thread's executing code.

4. What is start() method?

start() creates a new thread and calls run() automatically.

5. Difference between start() and run()?

start() creates a new thread; run() executes in the same thread.

6. What is thread lifecycle?

New → Runnable → Running → Blocked → Terminated.

7. What is thread priority?


Lab 6: Programming in Java Java Practical Viva Questions

It determines the scheduling preference of a thread.

8. What is sleep()?

sleep() pauses the thread for a given time.

9. What is join()?

join() waits for a thread to finish execution.

10. What is yield()?

yield() gives other threads a chance to run.

__________________________________________________________________________________

1. What is multithreading?

Multithreading is running multiple threads simultaneously.

2. Why use multithreading?

To achieve faster execution and better CPU utilization.

3. What is thread synchronization?

Synchronization prevents multiple threads from accessing shared data simultaneously.

4. What is a synchronized method?

A method locked so only one thread can execute it at a time.

5. What is a synchronized block?

A block of code locked using an object monitor.

6. What is a deadlock?

Deadlock occurs when two threads wait for each other forever.

7. What is inter-thread communication?

Threads communicate using wait(), notify(), and notifyAll().

8. What is wait()?

wait() makes a thread release lock and go to waiting state.

9. What is notify()?
Lab 6: Programming in Java Java Practical Viva Questions

notify() wakes up one waiting thread.

10. What is notifyAll()?

notifyAll() wakes up all waiting threads.

__________________________________________________________________________________

1. What is [Link] package?

It provides classes for input and output operations.

2. What is FileInputStream?

It reads data from a file as bytes.

3. What is FileOutputStream?

It writes data to a file as bytes.

4. What is FileReader?

It reads data from a file as characters.

5. What is FileWriter?

It writes character data to a file.

6. What is BufferedReader?

BufferedReader reads text efficiently using a buffer.

7. What is BufferedWriter?

BufferedWriter writes text efficiently with buffering.

8. What is InputStreamReader?

It converts byte streams into character streams.

9. What is OutputStreamWriter?

It converts character streams into byte streams.

10. What is Serialization?

Serialization converts an object into a byte stream.

____________________________________________________________________
Lab 6: Programming in Java Java Practical Viva Questions

1. What is [Link] package?

It contains fundamental classes required by every Java program.

2. What is Object class?

Object is the root class of all Java classes.

3. What is String class?

String represents immutable character sequences.

4. What is Math class?

Math provides methods for mathematical operations.

5. What is System class?

System contains system-related functionality like input/output.

6. What is Wrapper class?

Wrapper classes convert primitives into objects.

7. What is StringBuilder?

A mutable sequence of characters, not synchronized.

8. What is StringBuffer?

A mutable, thread-safe sequence of characters.

9. What is Exception class in lang?

Superclass for all exception types.

10. Is [Link] automatically imported?

Yes, it is imported by default.

______________________________________________________________________________

1. What is an applet?

Applet is a small Java program that runs inside a browser.

2. What class do applets extend?

Applets extend the Applet class.


Lab 6: Programming in Java Java Practical Viva Questions

3. What is init() method?

init() is used to initialize the applet.

4. What is start() method?

start() executes when the applet becomes visible.

5. What is stop() method?

stop() executes when the user leaves the applet page.

6. What is destroy() method?

destroy() is called before the applet is removed from memory.

7. What is paint() method?

paint() is used to draw graphics on the applet window.

8. What tag is used to run applet?

<applet> tag (deprecated in modern browsers).

9. Can applets access local files?

No, for security applets have restricted access.

10. What is appletviewer?

A tool to run and test applets.

____________________________________________________________________________

1. What is AWT?

AWT (Abstract Window Toolkit) is used for building GUI applications.

2. What package does AWT belong to?

It belongs to [Link] package.

3. What is Frame?

A Frame is a top-level AWT window.

4. What is Button?

Button is a clickable UI component.


Lab 6: Programming in Java Java Practical Viva Questions

5. What is Label?

A Label displays non-editable text.

6. What is TextField?

A TextField allows single-line input.

7. What is TextArea?

A TextArea allows multi-line input.

8. What is Layout Manager?

It controls the arrangement of GUI components.

9. What is Event Handling?

Event handling deals with user actions like clicks and keypresses.

10. What is ActionListener?

ActionListener handles button click events.

Practical Questions that all the students have to practice before Pre-Practical Exam
Q. - A-1, 16, 22. B-11, 13. C-2, 20. D-3, 8. E-4, 9.

----Best of Luck---

You might also like