[go: up one dir, main page]

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

JAVA FAQ Viva Questions With Answers

Uploaded by

shravanipt30
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 views8 pages

JAVA FAQ Viva Questions With Answers

Uploaded by

shravanipt30
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/ 8

Course Name: OOPJ Lab Course Code: CSL304 FAQ

Q) What are the principle concepts of OOPS?


A) There are four principle concepts upon which object oriented design and programming rest.
They are:
•Abstraction
•Polymorphism
•Inheritance
•Encapsulation

Q) What is meant by Object Oriented Programming?


A)OOP is a method of programming in which programs are organized as cooperative
collections of objects. Each object is an instance of a class and each class belong to a
hierarchy.

Q) What is an Object?
A)Object is an instance of a class. It has state,behavior and identity. It is also
called as an instance of a class.

Q) What is meant by abstraction?


A) Abstraction defines the essential characteristics of an object that distinguish it
from all other kinds of objects. Abstraction provides crisply-defined conceptual
boundaries relative to the perspective of the viewer. Its the process of focussing on
the essential characteristics of an object. Abstraction is one of the fundamental
elements of the object model.

Q) What is meant by Encapsulation?


A) Encapsulation is the process of compartmentalising the elements of an abtraction
that defines the structure and behaviour. Encapsulation helps to separate the
contractual interface of an abstraction and implementation

Q) What is Java?
Java is a high-level programming language originally developed by Sun Microsystems and
released in 1995. Java runs on a variety of platforms, such as Windows, Mac OS, and the
various versions of UNIX.

Q) What is the most important feature of Java?


A) Java is a platform independent language.

Q) What do you mean by platform independence?


A) Platform independence means that we can write and compile the java code in one platform

Prepared by PSC 1
Course Name: OOPJ Lab Course Code: CSL304 FAQ

(eg Windows) and can execute the class in any other supported platform eg
(Linux,Solaris,etc).

Q) What are the supported platforms by Java Programming Language?


A) Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of
UNIX/Linux like HP-Unix, Sun Solaris, Redhat Linux, Ubuntu, CentOS, etc.

Q) What is the difference between a JDK and a JVM?


A) JDK is Java Development Kit which is for development purpose and it includes execution
environment also. But JVM is purely a run time environment and hence you will not be able
to compile your source files using a JVM.

Q) What are the access modifiers in Java?


A) There are 3 access modifiers. Public, protected and private, and the default one if no identifier
is specified is called friendly, but programmer cannot specify the friendly identifier explicitly.

Q) What are packages?


A) Package is a collection of related classes and interfaces providing access protection and
namespace management.

Q) What is meant by Inheritance and what are its advantages?


A) Inheritance is the process of inheriting all the features from a class. The advantages of
inheritance are reusability of
code and accessibility of variables and methods of the super class by sub classes.

Q) What is the difference between superclass and subclass?


A) super class is a class that is inherited whereas sub class is a class that does the inheriting.

Q) What is an abstract class?


A) An abstract class is a class designed with implementation gaps for sub classes to fill in and is
deliberately incomplete.

Q) What are the states associated in the thread?


A) Thread contains ready, running, waiting and dead states.

Q) What is synchronization?
A) Synchronization is the mechanism that ensures that only one thread is accessing the resources
at a time.

Q) What is deadlock?

Prepared by PSC 2
Course Name: OOPJ Lab Course Code: CSL304 FAQ

A) When two threads are waiting each other and can’t precede the program is said to be deadlock

Q) What is an applet?
A) Applet is a dynamic and interactive program that runs inside a web page displayed by a java
capable browser

Q) What is the lifecycle of an applet?


A) init() method – Can be called when an applet is first loaded start() method – Can be called
each time an applet is started.
paint() method – Can be called when the applet is minimized or maximized. stop() method – Can
be used
when the browser moves off the applet’s page. destroy() method – Can be called when the
browser is finished
with the applet.

Q) How do you set security in applets?


A) using setSecurity Manager() method

Q) What is a layout manager and what are different types of layout managers available in java
AWT?
A) layout manager is an object that is used to organize components in a container. The different
layouts are available are FlowLayout, BorderLayout, CardLayout, GridLayout and
GridBagLayout

Q) What is JDBC?
A) JDBC is a set of Java API for executing SQL statements. This API consists of a set of classes
and interfaces to enable programs to write pure Java Database applications.

Q) What are drivers available?


A) a) JDBC-ODBC Bridge driver b) Native API Partly-Java driver
c) JDBC-Net Pure Java driver d) Native-Protocol Pure Java driver

Q) What is the Java API?


A) The Java API is a large collection of ready-made software components that provide many
useful capabilities, such as graphical user interface (GUI) widgets.

Q) Why there are no global variables in Java?


A) Global variables are globally accessible. Java does not support globally accessible variables
due to following reasons:
1. The global variables breaks the referential transparency

Prepared by PSC 3
Course Name: OOPJ Lab Course Code: CSL304 FAQ

2. Global variables creates collisions in namespace.

Q) What are Encapsulation, Inheritance and Polymorphism?


A) Encapsulation is the mechanism that binds together code and data it manipulates and keeps
both safe from outside interference and misuse. Inheritance is the process by which one object
acquires the properties of another object. Polymorphism is the feature that allows one interface to
be used actions.

Q) What is the use of bin and lib in JDK?


A) Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and
all packages.

Q) What is method overloading and method overriding?


A) Method overloading: When a method in a class having the same method name with different
arguments is said to be method overloading.
Method overriding : When a method in a class having the same method name with the same
arguments is said to be method overriding.
Q) What is the difference between this() and super()?
A) this() can be used to invoke a constructor of the same class whereas super() can be used to
invoke a super class constructor

Q) Why Java?
A) The programs that we are writing are very similar to their counterparts in several other
languages, so our choice of language is not crucial. We use Java because it is widely available,
embraces a full set of modern abstractions, and has a variety of automatic checks for mistakes in
programs, so it is suitable for learning to program. There is no perfect language, and you
certainly will be programming in other languages in the future

Q) What is the meaning of the words public, static and void?


A) These keywords specify certain properties of main() that you will learn about later in the
book. For the moment, we just include these keywords in the code (because they are required)
but do not refer to them in the text.

Q) What happens when you omit a brace or misspell one of the words, like public or static or
main?
A) It depends upon precisely what you do. Such errors are called syntax errors. Try it out and
see.

Q) Can a program use more than one command-line argument?

Prepared by PSC 4
Course Name: OOPJ Lab Course Code: CSL304 FAQ

A) Yes, you can put several, though we normally use only a few. You refer to the second one as
args[1], the third one as args[2], and so forth. Note that we start counting from 0 in Java.

Q) What Java systems libraries and methods are available for me to use?
A) There are thousands of them, but we introduce them to you in a deliberate fashion in this
book to avoid overwhelming you with choices

Q) What exactly is a .class file?


A) It’s a binary file (sequence of 0s and 1s). If you are using Unix or OS X, you can examine its
contents by typing od -x HelloWorld.class at the command prompt.This displays the results in
hexadecimal (base16). In deference to Java’s name, the first word of every .class file is cafe.

Q) What is the base class of all classes?


A) java.lang.Object

Q) Difference between throw and throws?


A) It includes: Throw is used to trigger an exception where as throws is used in declaration of
exception. Without throws,
Checked exception cannot be handled where as checked exception can be propagated with
throws.

Q) Define JIT compiler?


A) It improves the runtime performance of computer programs based on bytecode.

Q) What is the difference between object oriented programming language and object based
programming language?
A) Object based programming languages follow all the features of OOPs except Inheritance.
JavaScript is an example of object based programming languages

Q) What is the purpose of the default constructor?


A) The java compiler creates a default constructor only if there is no constructor in the class.

Q) Can a constructor be made final?


A) No, this is not possible.

Q) What is a static block?


A) It is used to initialize the static data member, It is executed before the main method at the
time of classloading.

Prepared by PSC 5
Course Name: OOPJ Lab Course Code: CSL304 FAQ

Q) Difference between Overloading and Overriding?


A) Method overloading increases the readability of the program. Method overriding provides the
specific implementation of the method that is already provided by its super class parameter must
be different in case of overloading, parameter must be the same in case of overriding.

Q) What is the final class?


A) Final classes are created so the methods implemented by that class cannot be overridden. It
can’t be inherited.

Q) What is NullPointerException?
A) NullPointerException is thrown when calling the instance method of a null object, accessing
or modifying the field of a null object etc.

Q) Does it matter in what order catch statements for FileNotFoundException and IOException
are
written?
A) Yes, it does. The FileNoFoundException is inherited from the IOException. Exception’s
subclasses have to be caught first.

Q) Why is the Vector class used?


A) The Vector class provides the capability to implement a growable array of objects. Vector
proves to be very useful if you don’t know the size of the array in advance, or you just need one
that can change sizes over the lifetime of a program.

Q) What is the difference between a break statement and a continue statement?


A) A break statement results in the termination of the statement to which it applies (switch, for,
do, or while). A continue statement is used to end the current loop iteration and return control to
the loop statement.

Q) If a variable is declared as private, where may the variable be accessed?


A) A private variable may only be accessed within the class in which it is declared

Q) What is the primary benefit of Encapsulation?


A) The main benefit of encapsulation is the ability to modify our implemented code without
breaking the code of others who use our code. With this Encapsulation gives maintainability,
flexibility and extensibility to our code.

Q) What is an Interface?
A) An interface is a collection of abstract methods. A class implements an interface, thereby
inheriting the abstract methods of the interface.

Prepared by PSC 6
Course Name: OOPJ Lab Course Code: CSL304 FAQ

Q) Give some features of Interface?


A) It includes: Interface cannot be instantiated An interface does not contain any constructors.
All of the methods in an interface are abstract.

Q) Define Packages in Java?


A) Package can be defined as a grouping of related types(classes, interfaces, enumerations
and annotations ) providing access protection and name space management.

Q) Why Packages are used?


A) Packages are used in Java in-order to prevent naming conflicts, to control access, to make
searching/locating and usage of classes, interfaces, enumerations and annotations, etc.,
easier.

Q) What do you mean by Multithreaded program?


A) A multithreaded program contains two or more parts that can run concurrently. Each part of
such a program is called a thread, and each thread defines a separate path of execution.

Q) What are the two ways in which Thread can be created?


A) Thread can be created by: implementing Runnable interface, extending the Thread class.

Q) What is an applet?
A) An applet is a Java program that runs in a Web browser. An applet can be a fully functional
Java application because it has the entire Java API at its disposal.

Q) An applet extend which class?


A) An applet extends java.applet.Applet class.

Q) Explain garbage collection in Java?


A) It uses garbage collection to free the memory. By cleaning those objects that is no longer
reference by any of the program.

Q) What does Java's inheritance mean?

A) Inheritance is the term used in Java to describe the process of building a new class utilizing
the features of an existing class. In other words, inheritance is how a child class acquires each
parent class's traits.

Q) What are superclass and subclass, respectively?

Prepared by PSC 7
Course Name: OOPJ Lab Course Code: CSL304 FAQ

A) Superclasses are classes from which features are inherited by subclasses. It is also known as
the parent class or foundation class.
Subclasses are classes that contain all the properties, methods, and nested classes of another
class. A derived class, kid class, or extended class are other names.

Q) How does Java implement or achieve inheritance?

A)Two keywords can be used to implement or accomplish inheritance:

● extends: The keyword extends is used to create an inheritance relationship between


two classes and two interfaces.
● implements: The term "implements" establishes the line of descent between a class
and an interface.

Q) Why do Java programmers use inheritance??

A) An inheritance is utilized to leverage polymorphism and reuse code by establishing a type


hierarchy. For type declaration, inheritance is preferable, but because the composition is more
versatile, it's a better choice for code reuse.

Q) What kinds of inheritance are there in Java?

A) The different inheritance kinds are as follows:


a. Multi-level Inheritance
b. Single Inheritance
c. Multiple Inheritance
d. Hybrid Inheritance and,
e. Hierarchical Inheritance

Prepared by PSC 8

You might also like