Q2 Give some similarities b/w Java with C/C++ p#15 (from internet also)
Ans:
1.
2.
3.
4.
5.
Lecture No 2
Q3 what is JVM? P#17
Ans: JVM stands for Java Virtual Machine. Java byte code executes by software
known as virtual machine so JVM executes java byte code or executable code. We
can say that central part of java platform is JVM.
Q5 what is JRE? P# 18
Page |2
Ans: JRE stands for Java Runtime environment. JVM (Java Virtual Machine) is
part of JRE. JRE consists of built in classes and JVM. Without JRE it is impossible
to run java software.
Q6 Write Program Development and Execution steps involved in Java? P#19
Ans: There are following steps involved
1. Edit
2. Compile
3. Load
4. Verify
5. Execute
Q7 why the main method is declared as static in Java program? P#29
Ans: It is made as static so that Java Run time environment (JRE) can call it with
out creating an object. If main method is not static then JRE have to call object of
the class in which main method is present and call the main method on that object.
So making main method static allows JRE to call it without creating object.
Q8 what does Void in main method indicates P#29
Ans: it indicates that main ( ) does not return any thing.
Lecture No 3
Page |3
Ans: Every thing in java is an object as every class in java inherits from class
object by default. Java programming can not be done by classes so we can say
that classes are building blocks for java programming. That is why java is object
oriented because java programming can not be done without classes/ objects.
Q12 how Ans: we can we create object of Wrapper Class? P#35
Ans: we can create object of Wrapper Class using a string or primitive data type
Example:
Integer num = new Integer (4);
Integer num = new Integer (4);
We can also use corresponding value function to get primitive data type from a
wrapper.
Example:
Int primNum = num.intValue ( );
Q13 how can we convert strings to numeric primitive data types? P#35
Ans:
We can convert a string to primitive data type using parse ( ) method.
Example:
String value 552;
Int d = Integer.parseInt (value);
Example:
String value 3.14;
Double d = Double.parseDouble (value);
Lecture No 4
Q14 Define the followings P#40
Class, object, constructor, attribute and methods
Ans:
Class
Definition:
Class is user defined data type. It is prototype for objects.
Classes are basic features of OOP (object oriented programming)
With out classes, it is not possible to program in java.
Page |4
Object
Definition:
Objects are instances of class. These are created from class. Examples are nouns,
things in the world.
Constructor
Definition
It is used for initialization. It is used to create an object and to initialize it.
Constructor has the same name as the name of class.
Attribute
Definition:
Attribute represents characteristics or properties of object
Methods
Definition:
Methods are the actions that an object can perform.
Page |5
Q17 what do you know about static variables and methods? P#47
Ans: static variables and methods are associated with the class itself and not tied
to any particular object. Static variables and methods are generally accessible by
class name
Q18 for what purpose, Finalize method is used? P#47
Ans:
To recycle the object of class we use finalize ( ) method
Provides reusability
No need to create objects again and again
Time saving
Easy to implement and Understand
Q21 what is type casting and its Types? Explain with example?P#5
Ans: Type casting means conversion of one entity type into another. It is of two
types
1. Up Casting
2. Down Casting
Up Casting
Conversion of smaller data type into bigger one
Example
Int a = 10;
Double b = a;
Page |6
Example: Employee e = new Teacher ( );
Down Casting
Conversion of bigger data type into smaller one
Example:
Double a = 7.65
Int b = (int) a;
Lecture No 6
Q22 what is collection what is its advantage and which package we need to
import while using it? P#60
Ans: Collection is group of objects known as its elements
Advantage of collection over array is we dont need to know the eventual size of
collection in order to add objects in to it. We need to import Java.util package to
use collection.
Q23What are basic methods of Collection P#60
Ans: Basic methods are
1. Constructor
2. int size ( )
3. Boolean add (Object)
4. Boolean isEmpty ( )
5. Boolean contains (Object)
6. Boolean removes (Object)
Q24 Difference b/w Array and Array list P#61
Ans:
Array is of fixed size once created can not be modified can not add or delete any
record. Array list is resizable. It can grow or shrink over time.
Q25 Describe Methods of Array list? P#61
Ans: Methods are
1. Int size ( )
2. add (Object)
3. Object get (int index)
4. remove (int index)
Page |7
Q26 what is hash map describe its methods? P#63
Ans: hash map stores elements in the form of key value pair. A key is associated
with each object stored. Keys are unique and allow fast retrieval of object.
Methods are
1. put (Object key, Object value)
2. object get (Object key)
3. int size ( )
Lecture No 7
Q27 what are types of error? P#70
Ans: three types of errors are
1. Syntax error( Language syntax errors)
2. Logic error (error in logic unexpected output results)
3. runtime error (Exceptional errors)
Checked Exceptions
1. Can not be solved by debugging
2. must be caught/declare in throws clause
3. subclass of exceptions
Page |8
4. caused due to external factors
5. compiler error if not handled properly
Lecture No 8
Q31 what do you know about Stream? P#85
Ans: streams are abstraction of data source/sink. We can consider stream as
data path data can flow through this path in one direction. Streams can be
1. Node Stream
2. Filter Stream
Lecture No 9
Q32 what is abstract class? P#96
Ans: instance of an abstract class can not be instantiated because it is used to
define part of implementation only
Q33 what is interface class? P#98
Ans: these are special java types contain only set of method prototype. These do
not provide implementation. So interface is pure abstract class.
Q34 what is Graphical user interface? P#102
Ans: A GUI component is an object with which user interact via mouse or
keyboard.
Q35 what is meant by look and feel in Java? P#102
Ans: The appearance and how user interacts with program is known as look and
feel.
Q36 what package is needed to import for making GUI? P#102
Ans: javax.swing or Java.awt package
Page |9
Q37 what are container and its types? P#104
Ans: A container is a collection of related components which allows other
components to be nested inside it
Types of container are
Top Level Container: (can exist independently/alone JFrame, Applet)
General Purpose Container: (can not exist independently/alone like JPanel, Tool
bar)
Q38 Write steps for creating GUI in Java? P#104
1. Import required package
Import javax.swing.*; /import Java.awt.*;
2. setup top level container
3. get component area for top level container
4. Apply layout to component area
5. create and add components
6. set size of frame and make it visible
Lecture No 12
Q41 how can we handle mouse events in java? P#130
Ans:
Two types of listener interfaces are available for handling mouse events
1. Mouse Listener (Clicked, Exit, Pressed, Released, Enter)
P a g e | 10
2. Mouse Motion Listener (Dragged, Moved)
Q42 how window events are handled in Java? P#133
Ans: these are handled through window listener interface there are 7 methods
available
1. Window activated
2. Window Closed
3. Window Closing
4. Window Deactivated
5. Window Deiconified
6. Window Iconified
7. Window Open
Lecture No 13
Q43 what are adapter classes? P#136
Ans: Adapter classes provide definition for all the methods (empty bodies)
corresponding to listener interface
Lecture No 14
Q47 Write steps involved in JDBC? P#151
Ans:
1. Import required package java.sql.*;
2. Load Database driver
P a g e | 11
3.
4.
5.
6.
7.
Lecture No 15
Q48 name statement methods? P#156
Ans: 1. execute Update ( )
3. getMaxRows ( )/setMaxRows ( )
4. getQueryTimeOut ( )/setQueryTimeOut ( )
P a g e | 12
Lecture No 17
Q53 what is Meta data? P#174
Ans: data about data is known as Meta data.
Q54 How to create result set Meta data object? P#174
Ans: ResultSetMetaData rsmd = rs.getMetaData ( );
Q55 Name methods of ResultSetMetaData P#174
Ans: getColumnCount ( )
GetColumnType ( )
GetColumnName ( )
GetColumnLable (int)
GetColumnDisplaySize ( )
Q56 Name JDBC driver Types P#179
Ans: JDBC-ODBC Bridge
Native-API /Partly java driver
Net-Protocol Driver/All Java Driver
Native-Protocol Driver/All Java Driver
Lecture No 18
Q57 Write methods used for painting swing components? P#186
Ans:
PaintComponent ( )
PaintBorder ( )
PaintChildern ( )
Q58 Write steps that we need to follow in order to perform painting? P#187
Ans:
1. Subclass JPanel
2. Override paintComponent (Graphics g) method
3. install that JPanel inside the JFrame
Lecture No 20
Q59 what is applet and is it a JPanel? P#199
Ans: It is a small program written in java and included in HTML page. It is
independent of the OS on which it runs that is why an applet is a panel because it
allows interaction with java program.
P a g e | 13
An applet can initialize itself init ( )
It can start itself start ( )
It can stop itself stop ( )
It can destroy itself (it can perform final cleanup) destroy ( )
Lecture No 21
Q62 What is socket and describe its advantages? P#211
Ans: socket is bidirectional communication link b/w two programs running on a
network.
Advantages:
1. Provides more control
2. Used for client server communication
3. Efficient performance
4. We can read/write a network through sockets
Q63 what is Port? P#211
Ans: port is transparent address to which processes can listen communication
request
Lecture No 22
P a g e | 14
Q66 why we need serialization? P#219
Ans: We need serialization to send an object to stream
Q67 how can we prevent serialization? P#225
Ans: there is no need to serialize sockets, streams, DB connections because they
dont represent state of object. For serialization prevention we use transient
keyword with the object which we dont want to serialize
Like transient Sockets s; transient Connection con; etc