0% found this document useful (0 votes)
16 views16 pages

Viva Questions

Data structure
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)
16 views16 pages

Viva Questions

Data structure
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
You are on page 1/ 16

Object Oriented Concepts using Java (One Mark Questions)

UNIT ~ 1
01. Who and when was Java developed?
Ans. James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language
project in June 1991. The small team of sun engineers called Green Team. It released its
first version in the year 1995.
02. What was the first name of java?
Ans. Oak
03. What do you mean by data abstraction and encapsulation in java?
Ans. Encapsulation means hiding the internal details or mechanics of how an object does
something. Abstraction is outer layout in terms of design.
Data abstraction is the process of hiding certain details and showing only essential
information to the user.
04. What is binding mention different types of binding in java?
Ans. Connecting a method call to the method body is known as binding.
There are two types of binding
1. Static Binding (also known as Early Binding).
2. Dynamic Binding (also known as Late Binding).
05. Expand JDK, JVM and JRE
Ans. JDK – Java Development Kit
JVM – Java Virtual Machine
JRE – Java Runtime Environment
06. Which is the latest version of java?
Ans. Java SE 18.0. 2.1 is the latest release of Java SE Platform.
07. When & which company owns java?
Ans. Oracle Corporation is the current owner of the official implementation of the Java
SE platform, following their acquisition of Sun Microsystems on January 27, 2010. This
implementation is based on the original implementation of Java by Sun.

08. Why java is called compiled and interpreted language?


Ans. Java can be considered both a compiled and an interpreted language because its
source code is first compiled into a binary byte-code. This byte-code runs on the Java
Virtual Machine (JVM), which is usually a software-based interpreter.
09. What do you mean platform independent?
Ans. Software that can run on a variety of hardware platforms or software architectures.

Compiled by Mr. Manjunath Balluli, Dept. of Computer Science Page 1 of 16


Object Oriented Concepts using Java (One Mark Questions)
10. What do you mean by garbage collection in java?
Ans. Java garbage collection is the process by which Java programs perform automatic
memory management. Java programs compile to bytecode that can be run on a Java
Virtual Machine or JVM for short.
11. Why is java is called secured?
Ans. Java is secure due to the following reasons:
o Java programs run inside a virtual machine which is known as a sandbox.
o Java does not support explicit pointer.
o Byte-code verifier checks the code fragments for illegal code that can violate access
right to object.
o It provides java.security package implements explicit security.
o It provides library level safety.
o Run-time security check takes place when we load new code.

12. Mention types of programs in java?


1. Stand-alone / CUI – based programs
2. Web Applications / GUI – based programs.

13. What is import statement? Give example


Ans. An import statement tells the compiler the path of a class or the entire package
Eg: import java.util.*;
14. What is javac and java?
Ans. The javac command is used to compile Java programs; it takes .java file as input
and produces bytecode. Following is the syntax of this command.
Eg: javac Sample.java
The java command is used to execute the bytecode of java. It takes byte code as input,
runs it, and produces the output. Following is the syntax of this command.
Eg: java Sample
15. What are tokens? Mention types of java tokens?
Ans. Tokens in Java are the small units of code which a Java compiler uses for
constructing those statements and expressions.
Java supports 5 types of tokens which are:
• Keywords.
• Identifiers.
• Literals.
• Operators.
• Special Symbols.

Compiled by Mr. Manjunath Balluli, Dept. of Computer Science Page 2 of 16


Object Oriented Concepts using Java (One Mark Questions)
16. What is identifier? Give Example
Ans. In Java, an identifier can be a class name, method name, variable name, or label.
For example:
public class Test
{
public static void main(String[] args)
{
int a = 20;
}
}
17. Mention any two valid and invalid identifiers
Ans. Examples of valid identifier names are i , __my_name , name_23 and a1b2_c3 .
18. What is literal? Give example
Ans. A literal can be a number, a character, or a string. For example, in the expression, x
= 3. x is a variable, and 3 is a literal.
19. What is variable? Mention types of variable
Ans. A variable is a container which holds the value while the Java program is executed.
A variable is assigned with a data type. Variable is a name of memory location. There are
three types of variables in java: local, instance and static.
20. What is byte code in java?
Ans. Java bytecode is the instruction set for the Java Virtual Machine. It acts similar to
an assembler which is an alias representation of a C++ code.
21. Write any 5 keywords in java?
Ans. int, char, try, catch, throw, class
22. What is static and final modifiers in java?
Ans. The static modifier for creating class methods and variables. The final modifier
for finalizing the implementations of classes, methods, and variables.
23. What is reference data types in java?
Ans. Reference datatypes in java are those which contains reference/address of
dynamically created objects.
For example: String, class.
24. What is instanceof and new operator in java?
Ans. The instanceof operator in Java is used to check whether an object is an instance
of a particular class or not.

Compiled by Mr. Manjunath Balluli, Dept. of Computer Science Page 3 of 16


Object Oriented Concepts using Java (One Mark Questions)
25. What is one way branching?
Ans. One way Branching statements allow the flow of execution to jump to a different
part of the program.
26. What is two-way branching?
Ans. Two way Branching statements allow the flow of execution to jump to a different
part of the program.
27. What is method? Mention different types of user defined methods in java?
Ans. A method is a block of code which only runs when it is called.
Java Static and Non-static methods, Java method with return a value, and java method
without return a value are the user-defined methods.
28. What is method overloading? Give example
Ans. In Java, two or more methods may have the same name if they differ in parameters
(different number of parameters, different types of parameters, or both). These methods
are called overloaded methods and this feature is called method overloading.
For example
class MethodOverloading {
private static void display(int a){
System.out.println("Arguments: " + a);
}
private static void display(int a, int b){
System.out.println("Arguments: " + a + " and " + b);
}
public static void main(String[] args) {
display(1);
display(1, 4);
}
}
29. Mention different types to implement method overloading in java?
Ans. Different Ways of Method Overloading in Java
• Changing the Number of Parameters.
• Changing Data Types of the Arguments.
• Changing the Order of the Parameters of Methods.
30. Why Math class is used in java?
Ans. The class Math contains methods for performing basic numeric operations such
as the elementary exponential, logarithm, square root, and trigonometric functions.
31. Math.floor() and Math.random() mention their use in java?
Ans.The Math.floor() method rounds the specified double value downward and
returns it. The rounded value will be equal to a mathematical integer.

Compiled by Mr. Manjunath Balluli, Dept. of Computer Science Page 4 of 16


Object Oriented Concepts using Java (One Mark Questions)
Math. Random() generates a number between 0 and 1, that isn't a whole number, and
also isn't 1.
32. What is array? Mention types of array
Ans. An array type is a user-defined data type consisting of an ordered set of elements
of a single data type.
Types: 1-D array, 2-D Array, Multi-Dimensional Array.
33. Write syntax to create array in java?
Ans. <Datatype> array_name[];

Compiled by Mr. Manjunath Balluli, Dept. of Computer Science Page 5 of 16


Object Oriented Concepts using Java (One Mark Questions)
Unit ~ 2
1. What is a class?
Ans. A class is a user defined blueprint or template for which objects are created.
2. What is an object?
Ans. An object is a real-world entity which has both properties and methods. It is an
instance of class.
3. How do you define a class?
Ans. Java provides a reserved keyword class to define a class. The keyword must be
followed by the class name. Inside the class, we declare methods and variables.
4. Syntax for declaring a class?
Ans. class Classname [extends superclassname] //optional
{
[Fields declaration:] //optional
[Methods declaration:] //optional
}
5. What is a method?
Ans. A method is a block of code which only runs when it is called.
6. How do you declare methods?
Ans. return_type methodname(parameter-list)
{
Method–body;
}
7. How do you create objects?
Ans. Objects in java are created using the new operation or operator or keyword.
8. Syntax for declaring an object?
Ans. <class_name> <obj_name> = new <class_name>();
9. What is a Constructor?
Ans. Constructor in java is a special type of method that is used to initialize the object.
Java constructor is invoked at the time of object creation.
10. What are the types of Constructor?
Ans. Java Default Constructor
No argument/Parameter Constructor
Java parameterized constructor
11. What is a Finalizer?
Ans. Finalize method in Java is an Object Class method that is used to perform cleanup
activity before destroying any object.
12. What are the different Visibility modes or Access Modifiers in Java?
Ans. 1. Default 2. Private
3. Protected 4. Public

Compiled by Mr. Manjunath Balluli, Dept. of Computer Science Page 6 of 16


Object Oriented Concepts using Java (One Mark Questions)
13. What is the difference between String and StringBuffer?
Ans. String objects are immutable whereas StringBuffer objects are not. StringBuffer
unlike Strings support growable and modifiable strings.
14. What is the difference between instance, object and a reference?
Ans. Object: An Object is an instance of a class
Reference: A reference is just like a pointer pointing to an object
Instance: This represents the values of data members of a class at a particular time
15. What is method overloading and method overriding?
Ans. Method Overloading:
• In Method Overloading, Methods of the same class shares the same name but each
method must have a different number of parameters or parameters having different types
and order.
Method Overriding:
• In Method Overriding, the subclass has the same method with the same name and
exactly the same number and type of parameters and same return type as a superclass.
16. What is this Keyword?
Ans. The this keyword refers to the current object in a method or constructor.
17. What is the difference between String and StringBuffer?

No. String StringBuffer

1) The String class is immutable. The StringBuffer class is


mutable.

2) String is slow and consumes more memory StringBuffer is fast and


when we concatenate too many strings consumes less memory when
because every time it creates new instance. we concatenate t strings.

3) String class overrides the equals() method of StringBuffer class doesn't


Object class. So you can compare the contents override the equals() method of
of two strings by equals() method. Object class.

4) String class is slower while performing StringBuffer class is faster while


concatenation operation. performing concatenation
operation.

5) String class uses String constant pool. StringBuffer uses Heap memory

Compiled by Mr. Manjunath Balluli, Dept. of Computer Science Page 7 of 16


Object Oriented Concepts using Java (One Mark Questions)
Unit ~ 3
1. What is Inheritance?
Ans. Inheritance is a mechanism wherein a new class is derived from an existing class.
2. Mention the types of inheritance in java?
Ans. a. Single
b. Multilevel
c. Hierarchical
3. What is Base Class?
Ans. The class from which the subclass is derived is called a superclass (also a base class
or a parent class).
4. What is Derived Class?
Ans. A class that is derived from another class is called a subclass (also a derived class,
extended class, or child class).
5. What is Polymorphism?
Ans. Polymorphism means an object having many forms.
6. What are the 2 types of polymorphism in Java?
Ans. There are two types of polymorphism in Java: compile time polymorphism and run
time polymorphism in java.
7. What is Late Binding?
Ans. When the compiler resolves the method call binding during the execution of the
program, such a process is known as Dynamic or Late Binding in Java.
8. What is an abstract class and abstract method?
Ans. The abstract keyword is a non-access modifier, used for classes and methods:
Abstract class: is a restricted class that cannot be used to create objects (to access it, it
must be inherited from another class).
Abstract method: can only be used in an abstract class, and it does not have a body. The
body is provided by the subclass (inherited from).
9. What is interface in java?
Ans. The interface in Java is a mechanism to achieve abstraction. There can be only abstract
methods in the Java interface, not method body. It is used to achieve abstraction and
multiple inheritance in Java.
10. What is a Package in java?
Ans. A java package is a group of similar types of classes, interfaces and sub-packages.
Package in java can be categorized in two form, built-in package and user-defined
package.

Compiled by Mr. Manjunath Balluli, Dept. of Computer Science Page 8 of 16


Object Oriented Concepts using Java (One Mark Questions)
11. What is java UTIL Package?
Ans. Package java. util. Contains the collections framework, some internationalization
support classes, a service loader, properties, random number generation, string parsing
and scanning classes, base64 encoding and decoding, a bit array, and several
miscellaneous utility classes.

Compiled by Mr. Manjunath Balluli, Dept. of Computer Science Page 9 of 16


Object Oriented Concepts using Java (One Mark Questions)
Unit ~ 4
1. What's Java Swing?
Answer: Swing is a GUI toolkit for Java. It is one part of the Java Foundation Classes
(JFC).
Swing includes graphical user interface (GUI) widgets such as text boxes, buttons, split-
panes, and tables.
2. What is awt?
Answer: AWT stands for Abstract Window Toolkit. AWT enables programmers to
develop Java applications with GUI components, such as windows, and buttons.
The Java Virtual Machine (JVM) is responsible for translating the AWT calls into the
appropriate calls to the host operating system.
3. What is an Applet?
Answer: Applet is a java program that runs inside a web browser
4. What is the Lifecycle of an Applet?
Answer:
a. init( ) method - called when an applet is first loaded
b. start( ) method - called each time an applet is started
c. paint( ) method - called when the applet is minimized or maximized
d. stop( ) method - called when the browser moves off the applet's page
e. destroy( ) method - called when the browser is finished with the applet
5. What are the Differences Between Swing and Awt?
Answer: AWT is heavy-weight components, but Swing is light-weight components. AWT
is OS dependent because it uses native components, But Swing components are OS
independent. We can change the look and feel in Swing which is not possible in AWT.
Swing takes less memory compared to AWT. For drawing AWT uses screen rendering
where Swing uses double buffering.
6. What is an Event in Swing?
Answer: Changing the state of an object is called an event.
7. What is an Event Handler in Swing?
Answer: An event handler is a part of a computer program created to tell the program
how to act in response to a specific even
8. Give us the name of the list Layout managers in Java?
Answer: List is here:
1. Flow Layout Manager
2. Grid Layout Manager

Compiled by Mr. Manjunath Balluli, Dept. of Computer Science Page 10 of 16


Object Oriented Concepts using Java (One Mark Questions)
3. Box Layout Manager
4. Border Layout Manager
5. Card Layout Manager
6. GridBag Layout Manager
9. How are the Elements of a Gridbaglayout Organized?
Answer: The Elements of a GridBagLayout are organized according to a grid.
However, the elements are of different sizes and may occupy more than row or column
of the grid. In addition, the rows and columns may have diff sizes.
10. How are the elements of a borderlayout organized?
Answer: The Elements of a BorderLayout are organized at the borders (North, South, East
and West) and the centre of a container
11. What is the Diff Between Choice and The List?
Answer: A Choice is displayed in a compact from that requires we to pull ot down tosee
the list of available choice, Oly one item may be selected from a Choice.
A List may be displayed in such a way that several List items are visible. A List supports
the selection of the one or more List items.
12. Which Containers Use a Border Layout as Their Default Layout in Swing?
Answer: The window, Frame and Dialog classes use a border layout as their default
layout
13. What is Panel?
Answer: Panel is the simplest container class.
A panel provides space in which an application can attach any other component,
including other panels.
14. Expand CUI and GUI.
Answer: CUI – Character User Interface.
GUI – Graphical User Interface.

Compiled by Mr. Manjunath Balluli, Dept. of Computer Science Page 11 of 16


Object Oriented Concepts using Java (One Mark Questions)
Unit ~ 5
1. What are the types of I / O streams?
Answer: There are two types of I / O streams: byte and character.
2. What are the main ancestors of I / O streams?
Answer: Byte: java.io.InputStream, java.io.OutputStream;
Symbolic: java.io.Reader, java.io.Writer;
3. What is common and how do the following streams differ: InputStream,
OutputStream, Reader, Writer?
Answer: The base class InputStream represents classes that receive data from various
sources:
– an array of bytes
– a string (String)
– a file
– a pipe (pipe): data is placed from one end and extracted from the other
– a sequence of different streams that can be combined into one stream
– other sources (e.g., internet connection)
The class OutputStream is an abstract class that defines stream byte output. In this
category are classes that determine where your data goes: to an array of bytes (but not
directly to String; it is assumed that you can create them from an array of bytes), to a file
or channel.
Character streams have two main abstract classes, Reader and Writer , which control the
flow of Unicode characters. The Reader class is an abstract class that defines character
streaming input. The Writer class is an abstract class that defines character stream output.
In case of errors, all class methods throw an IOException.
4. What do you know about Random Access File?
Answer: The RandomAccessFile class inherits directly from Object and is not inherited
from the above basic input / output classes. Designed to work with files, supporting
random access to their contents.
5. What are the file access modes?
Answer: RandomAccessFile can open in read (r) or read / write (rw) mode. There is also
a “rws” mode, when a file is opened for read-write operations and each change of file
data is immediately recorded on a physical device.
6. What packages are stream classes in?
Answer: Classes of input / output streams are in java.io; With JDK 7, a more modern way
of working with threads has been added – Java NIO. Classes are in java.nio. To work with
archives, classes from the java.util package are used.

Compiled by Mr. Manjunath Balluli, Dept. of Computer Science Page 12 of 16


Object Oriented Concepts using Java (One Mark Questions)
7. What do you know about add-on classes?
Answer: Add-on classes endow the existing thread with additional properties. Examples
of classes: BufferedOutputStream, BufferedInputStream, BufferedWriter – buffers the
stream and improves performance.
8. What is serialization?
Answer: Serialization is the process of maintaining the state of an object in a sequence of
bytes.
9. What is deserialization
Answer: Deserialization is the process of restoring an object from these bytes. The Java
Serialization API provides a standard mechanism for creating serializable objects.
10. What classes allow you to archive objects?
Answer:
1. DeflaterOutputStream,
2. InflaterInputStream,
3. ZipInputStream,
4. ZipOutputStream,
5. GZIPInputStream,
6. GZIPOutputStream.

Compiled by Mr. Manjunath Balluli, Dept. of Computer Science Page 13 of 16


Object Oriented Concepts using Java (One Mark Questions)
Unit ~ 6
1. What is multitasking?
Answer: A multitasking operating system is an operating system that gives you the
perception of 2 or more tasks/jobs/processes running at the same time.
2. How can you identify the process?
Answer: Any program which is in a working state is referred to as a process.
These processes do have threads that are single dispatchable units.
3. How do you see a thread?
Answer: In order to see threads status, let us take windows as an operating system,
it illustrates then we’d have Process Explorer where you can see GUI shown below
for windows operating systems.
4. What is Multithreading and How it is Different from Multitasking?
Answer: Multithreading is a specialized form of multitasking.
Process-based multitasking refers to executing several tasks simultaneously where
each task is a separate independent process is Process-based multitasking.
5. What is a thread?
Answer: Threads are lightweight processes within processes as seen.
In java, there are two ways of creating threads namely via Thread class and via
Runnable interface.
6. What are the different states of a thread, or what is thread lifecycle?
Answer: A thread in Java at any point of time exists in any one of the following states.
A thread lies only in one of the shown states at any instant:
New
Runnable
Blocked
Waiting
Timed Waiting
Terminated
7. What are Different Types of threads in Java?
Answer: There are two types of threads in java as follows:
• User thread
• Daemon thread
8. How to set the name of the thread?
Answer: We can name a thread by using a method been already up there known as
setName() replacing default naming which was ‘Thread-0’, ‘Thread-1’, and so on.

Compiled by Mr. Manjunath Balluli, Dept. of Computer Science Page 14 of 16


Object Oriented Concepts using Java (One Mark Questions)
9. What is Exception.
Answer: A Runtime error is called an Exceptions error.
10. What is Exception Handling?
Answer: Java Exception Handling is a mechanism to handle runtime errors such as
NullPointerException, NegativeArraySizeException.
11. Types of Errors.
Answer: Errors may broadly be classified into two categories:
1. Compile-time errors.
2. Run-time errors.
12. What is Compile-time error?
Answer: All syntax errors will be detected and displayed by the Java compiler and
therefore these errors are known as compile-time errors.

15. What is Run-time error?


Answer: Sometimes, a program may compile successfully creating the .class file
but may not run properly these errors are known as Run time error.
16. Types of Exception?
Answer: There are mainly two types of exceptions: checked and unchecked where
error is considered as unchecked exception. The sun microsystem says there are three
types of exceptions: 1. Checked Exception
2. Unchecked Exception
3. Error
15. Write a syntax for Exception Handling Mechanism?
Answer: try
{
statement; // generates an exception
}
catch (Exception - type e)
{
statement; // process the exception
}

Compiled by Mr. Manjunath Balluli, Dept. of Computer Science Page 15 of 16


Object Oriented Concepts using Java (One Mark Questions)
16. What is Try – Block?
Answer: “try” block contains the code in which runtime error may occur.
17. What is Catch – Block?
Answer: “catch” block contains the handling code for runtime errors i.e., when run time
error occurs, instead of terminating the program, control comes to “catch” block.
18. Define Multiple catch – Block?
Answer: Several types of exceptions may arise when executing the program. They can be
handled by using multiple catch blocks for the same try block.
19. Define finally?
Answer: The finally block is always executed, regardless of whether or not an exception
is thrown.
20. Write one difference between final, finally, finalize?
Answer:
i. final is a Keyword.
ii. finally is a Block.
iii. finalize is a method.
21. What is Collection in Java?
Answer: A Collection represents a single unit of objects, i.e., a group.
22. What is framework in Java?
Answer:
o It provides readymade architecture.
o It represents a set of classes and interfaces.
23. What is collection frame framework?
Answer: The Collection framework represents a unified architecture for storing and
manipulating a group of objects.
24. What is JavaBeans?
Answer: JavaBeans is a portable, platform-independent model written in Java
Programming Language. Its components are referred to as beans.
25. Define Java Networking?
Answer: Java Networking is a concept of connecting two or more computing devices
together so that we can share resources.

Compiled by Mr. Manjunath Balluli, Dept. of Computer Science Page 16 of 16

You might also like