Anda di halaman 1dari 14

Page |1

CS506 Web Programming and Development Solved Subjective Questions With


Reference For Final Term
Lecture No 1
Q1 Describe some Characteristics/Advantages of Java Language? (P#12, 13, 14)
Ans:
1.
2.
3.
4.
5.
6.
7.
8.
9.

Java is WORA (Write once run anywhere)


Java is Object oriented or network friendly language
Java is network based
Multi Threaded,
High Performance dynamic language
Java is programmer efficient
Java is very Robust language
Simple and Secure
port able

Q2 Give some similarities b/w Java with C/C++ p#15 (from internet also)
Ans:
1.
2.
3.
4.
5.

Both are object oriented based languages


Both languages allow to write comments for code understanding
Inheritance (single inheritance in case of Java)
Classes are used in both C/C++ and Java
in both languages semicolon is placed at the end of statement except at the
end of class (semicolon is not placed at end of class in java)

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.

Q4 what is meant by byte code in Java? P# 17


Ans: Java programs are compiles in the form of byte code. Java compiler reads
program (source code) and translate it in to byte code (understandable or
executable) and places it into class files

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

Q9 what is String? P#30


Ans: String is sequence of characters stored in the memory and accessible as a unit.
Java strings are represented as objects

Q10 Differentiate b/w == and equals method? P#30


Ans: == allows shallow comparison while equals operator allows deep comparison
so in java we use equals operator for comparison instead of == operator.
Example: string1.equals (string2) // (comparison of two strings using equals
operator in java)

Q11Why java is object oriented? P#34

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.

Q15 Write some differences b/w Java and C/C++? P#41


Ans:
1. Unlike C/C++ every thing resides inside the class in Java where as in C/C++
there are also present global functions and variables.
2. All methods are written inline in Java
3. There is no semicolon at the end of class in Java
4. Constructors and Destructors both are used in C/C++ but in Java only
constructors are used and destructors are not required in Java as memory
management is responsibility of JVM in java.

Q16 Name the access modifiers used in Java? P#41


Ans: there are three access modifiers used in java
Public: accessible by anyone at anywhere
Private: only accessible within the class
Protected: accessible to the class itself, to its subclass, or other classes within the
same package.

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

Q19 Describe advantages of inheritance and what type of inheritance java


supports? P#52
Ans: Java allows single inheritance and keyword extends is used in java for
inheritance. All classes are inherited from object class.
Advantages of Inheritance
1.
2.
3.
4.

Provides reusability
No need to create objects again and again
Time saving
Easy to implement and Understand

Q20 what is polymorphism in Java? P#57


Ans: Poly means many and Morphic means shapes means many shapes so
polymorphism in java means having multiple behaviors

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)

Q28 what is exception how program can handle it? P#70


Ans: an exception is an event that usually signals an erroneous situation at run
time. A program handles exception as
1. ignore it
2. handle it where it occurs
3. handle it another place in the program

Q29 what are types of exception? P#72


Ans: Checked and Unchecked Exceptions
UN Checked Exception
Subclass of run time exception/error
Can be solved by debugging
Does not require explicit handling
Cause due to internal factors
Examples: Null pointer exception, Division by zero exception

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

Q30 How java handles exceptions? P#72


Ans: java handles exception through 5 keywords
Try, Catch, throw, throws and finally
Finally block always executes
Catch block is used for exception handling
To avoid a code which could generate errors enclose it in try block
To normally throw an exception, through keyword is used.
If not interested in handling exception then use throws block

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

Q39 Name the Layouts supported in java P#109


Ans:
1. Border Layout
2. Flow Layout
3. Box Layout
4. Grid Layout
5. Card Layout
6. Grid Bag Layout
Lecture No 11
Q40 How Java handle events write steps? P#120
Ans:
1. Create components which can generate events (Event Generation)
2. Guild components that can handle events ( Event Handlers)
3. Register handler with generators

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

Q45 what is meant by inner classes? P#139


Ans: A class defined within another class is inner class
Q46 Differentiate b/w named and anonymous objects
Anonymous objects:
1. Difficult to understand
2. Shorter
3. Has no name
4. same as inner class in capabilities
5. used when there is only one time use of particular object
Named Objects:
1. Easy to understand
2. Have name
3. used when repeated use of an object is required

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.

Define connection URL


establish connection with DB
Create statement
Execute query
Close the connection

Lecture No 15
Q48 name statement methods? P#156
Ans: 1. execute Update ( )
3. getMaxRows ( )/setMaxRows ( )
4. getQueryTimeOut ( )/setQueryTimeOut ( )

Q49 Describe different types of statements? P#159


Ans:
Statement
Prepared Statement
Callable Statement
Q50 Write syntax of update query P#153
Ans: String sql = INSERT INTO table name + (columns name) Values (values)
Int count = stmt.executeUpdate (sql);
Lecture No 16
Q51 what does result set contains? P#162
Ans: it contains result of SQL query
Q52 Name useful result set methods? P#162
Ans: next ( )
2. Getters
3. Close ( )
4. Absolute (int)
5. Updaters
6. Update Row ( )
7. MoveToInsertRow (int)
8. InsertRow ( )
9. DeleteRow ( )
10 Last ( ) Fist ( )
11. GetRow ( )

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.

Q60 what can an applet do? (Methods) P#201

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

Q64 Write steps to make Client connection? P#212


Ans:
1. import package java.net and java.io
2. connect socket with server
3. Get I/O streams of socket
4. Send/Receive Message
5. Close Socket

Q65 Write steps to make simple server connection? P#214


Ans:
1. import package java.net and java.io
2. Create server socket
3. Wait for incoming connections
4. Get I/O streams of socket
5. Send/Receive Message
6. Close Socket

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

Anda mungkin juga menyukai