JAVA_QB

advertisement
PESIT SOUTHCAMPUS
QUESTION BANK
Faculty:Deepa A
No. Of Hours:52
PART-A
UNIT-1 INTRODUCTION TO JAVA
1) What led to the creation of Java?
2) What are the steps to be followed for executing a Java program?
3) What are the characteristics of Object-Oriented-Programming language?
4) Explain the data types available in Java
5) What are the different types of operators in Java?
6) Briefly discuss the features of JAVA.
7) What is JVM? Explain how JAVA works on a typical computer?
8) List out at least 10 difference between JAVA & C++
9) Explain why Java is the language of choice among network programmers?
10) Explain JVM.
11) Explain Bytecode.
12) Explain the three principles of Java.
13) Explain the features of OOP.
14) Explain the steps involved in implementation of a Java program.
15) Explain the use of JVM.
16) What is Java Development Kit (JDK)?
17) Explain the features of Java.
UNIT-2 CLASSES, INHERITANCE, EXCEPTIONS, APPLETS
1) Why do you need to use “final” with inheritance?
2) What is “Garbage Collector”?
3) What is the use of finalize( ) method?
4) Differentiate between the classes and objects?
5) What is dynamic method dispatch?
6) Explain the importance of super and this.
7) What are the class members? How do you access the class members?
8) Write a short note on String Class.
9) What are final variables and methods?
10) Elaborate the object class.
11) How does string class differ from string buffer class?
12) Write a java program to accept two strings and check whether string1 is a sub string of string2 or not.
13) Explain the relevance of static variable and static methods in JAVA programing with an example.
14) Describe the syntax of single inheritance in Java.
15) Explain the differences between the following with suitable examples
a. Constructor and a method
b. Class method and an instance method
16) Write a program to implement multiple inheritance.
17) What is a vector? How does it differ from an array? Explain with an example.
18) What do you understand by private, protected and public?
19) What is an instance variable and instance method?
20) What is the difference between string and stringbuffer ?
21) Does importing a package imports the subpackages as well?
22) What is class and instance of a class?
23) What are objects? How to create objects?
PESIT-BSC Education For The Real World
24) Explain how the concept of polymorphism is implemented in Java?
25) Explain encapsulation in the object oriented programming.
26) What is encapsulation? How does Java achieve encapsulation?
27) How does Java incorporates the concept of polymorphism? Give one example.
28) What do you understand by encapsulation in Java?
29) Explain the term polymorphism with an example.
30) Explain the finalize method.
31) What do you understand by an abstract class?
32) What is method overriding and how does it differ from methos overloading in Java?
33) When can a method in super class be prevented from being overridden by a method in
subclass?Explain by an example.
34) Explain in brief the overriding methods in Java.
35) Explain the use of the keyword final in Java programming.
36) Explain the use of finalize method.
37) State the different access specifiers available in Java.
38) What is method overriding and how does one prevent a method from being overridden?
39) State any two differences between method overloading and method overriding.
40) What do you understand by inheritance in Java?
41) How does a subclass constructor call a super class constructor?
42) Write a note on finalizer method.
43) Explain the keyword super in Java.
44) What is a class and a subclass? Give examples.
45) What is inheritance? Is multiple inheritance supported by Java?
46) What is data abstraction?
47) Explain the terms subclass and super class.
48) What are different access specifiers in Java?
49) What do you mean by final variable and final method?
50) Explain an abstract class.
UNIT-3 MULTI THREADED PROGRAMMING, EVENT HANDLING
1) What are the two methods to create a thread?
2) What is the importance of Alive() and join() methods?
3) Differentiate between extending a class and implementing interface.
4) What are the Java APIs used for package?
5) Describe the life-cycle of a thread.
6) With a suitable example program, explain how synchronization problem can be Overcome
7) Describe different forms of interface implementation with their syntax Declaration.
8) Explain the state transition diagram of a thread.
9) Name at least 10 Java API class you have used while programming.
10) Significance of interface in java?
UNIT-4 SWINGS
1) Why do you need swings in java?
2) What are the components of java swings?
3) Write a program to create a check box.
4) How do you create a table using swings.
5) What are applet classes?
6) How initialization and termination is done in applets?
7) How passing parameters is done in applets, give an example.
8) Which are the methods defined by AppletContext interface?
9) Write a method to fill a rectangle with red color.
10) What is an applet? How do applets differ from an application programs?
11) Explain life cycle of an applet.
12) Write a method in Java applet to display a circle.
13) How do we pass parameters to an applet? Give one example.
PESIT Bangalore South Campus
JAVA Course Information VII sem Information Science & Engineering
14) What does your method do when start() (life cycle of an applet) is called?
15) Explain destroy() method, a stage in the life cycle of an applet.
16) Write a method to display a message “Computer Programming” at position (50, 20) inside a square.
11)Explain drawRect () method in Graphics class with suitable example.
12) How getParameter () method is used in applet?
13) Explain Font class and Color class.
14) Explain the steps involved to execute and run an applet.
17) What is AWT? What are the various components in AWT?
PART B
UNIT-5 ENTERPRISE EDITION OVERVIEW, DATABASE ACCESS
1) What are the components of J2EE application?
2) What does application client module contain?
3) Differentiate between JDBC driver types with neat diagram.
4) How you will create jdbc /odbc connection.
5) What is container explain?
6) What is the thin client?
7) What are types of J2EE clients?
UNIT-6 SERVLETS
1) What APIs are available for developing a J2EE application?
2) How do I ensure that my servlet is thread-safe
3) Why there are no constructors in servlets?
4) What is the difference between GenericServlet and HttpServlet?
5) What is the Difference between doGet() and doPost()?
6) Can I send multiple responses for a single request? Give reason.
7) Can there be more than one instance of a servlet at one time ?
8) What are the different cases for using sendRedirect() vs. getRequestDispatcher()?
9) What is the difference between request attributes, session attributes, and ServletContext attributes?
10) Are singleton/static objects shared between servlet contexts?
11) What is the difference between ServletContext and ServletConfig?
12) What is the servlet?
13) What is the need of super.init(config) in servlets?
14) How to know whether we have to use jsp or servlet in our project?
15) Can we call destroy() method on servlets from service method?
16) What is the Servlet Interface?
17) What is the difference between GenericServlet and HttpServlet?
18) How we can check in particular page the session will be alive or not?
19) What is the importance of deployment descriptor in servlet?
20) When we increase the buffer size in our project using page directive attribute ‘buffer’ what changes
we observe?
21) What is the difference between ServetConfig and ServletContext..?
22) When a servlet accepts a call from a client, it receives two objects. What are they?
23) What are the differences between GET and POST service methods?
24) In which conditions we have to use the ServletContext?
25) What methods will be called in which order?((i.e)service(),doget(),dopost())
26) Servlet is Java class. Then why there is no constructor in Servlet? Can we write the constructor in
Servlet
27) What is the use of ServletConfig and ServletContext..?
28) What information that the ServletRequest interface allows the servlet access to?
29) What is the difference between ServletContext and ServletConfig?
PESIT Bangalore South Campus
JAVA Course Information VII sem Information Science & Engineering
30) When do you have action=get?
31) What is a Singleton class. How do you write it?
32) What is difference between sendRedirect() and forward()..? Which one is faster then other and
which works on server?
33) What information that the ServletResponse interface gives the servlet methods for replying to the
client?
34)Can a init(ServletConfig config) method be overrided in servlets?
35) How many ServletConfig and servlet context objects are present in one application?
36) Do we have a constructor in servlet? can we explictly provide a constructor in servlet programme as
in java program?
37) What are the uses of Servlets?
38) Is servlet is used to create a dynamic webpage or Static webpage or both?
39) If you want a servlet to take the same action for both GET and POST request, what should you do?
40) What is the difference between JSP and SERVLETS?
41) What are the advantages using servlets than using CGI?
42) What is a better approach for enabling thread-safe servlets and JSPs? SingleThreadModel Interface
or synchronization?
43) We have two applications in that we have two servlets each.How they(servlets) communicate with
each other?
44) How the server will know (i.e) when it can invoke init, service,destroy methods of servlet life cycle?
45) How to communicate between two servlets?
46) What is the difference between servlets and applets?
47) How will u pass the argument from one servlet to another servlet?
48) What method used to add a jsp to the servlet?
49) How HTTP Servlet handles client requests?
50) How to get one Servlet’s Context Information in another Servlet?
51) Difference between single thread and multi thread model servlet
52) What is the super class of All servlets?
53) How are Servlet Applet communication achieved?
54) What is servlet context and what it takes actually as parameters?
55) What is the servlet life cycle?
56) Types of Servlets?
57) Why is that we deploy servlets in a webserver.What exactly is a webserver?
58) Which code line must be set before any of the lines that use the PrintWriter?
UNIT-7 JSP, RMI
1) How does a servlet communicate with a JSP page?
2) What's a better approach for enabling thread-safe servlets and JSPs?
3) Why use JSP when we can do the same thing with servlets?
4) How does JSP handle run-time exceptions?
5) How do I use a scriptlet to initialize a newly instantiated bean?
6) What is RMI, explain in brief?
7) What is the difference between static variables and instance variables in a servlet?
8) What are the JSP atrributes?
UNIT-8 ENTERPRISE JAVA BEANS
1) What is the difference between Message Driven Beans and Stateless Session beans?
2) What is an EJB and EJB Context?
3) Why do we have a remove method in both EJBHome and EJBObject?
4) What is the difference between a Server, a Container, and a Connector?
5) Why are ejbActivate() and ejbPassivate() included for stateless session bean?
6) When should I adopt BMP and when I should use CMP?
7) What is session Facade?
8) What is the difference between EJB and Java beans?
PESIT Bangalore South Campus
JAVA Course Information VII sem Information Science & Engineering
9) What are the key features of the EJB technology?
10)What are the key benefits of the EJB technology?
11)What is message-driven bean?
12)What are Entity Bean and Session Bean?
Multiple Choice Questions
1.To override a method in Java, we need to define a method in sub class with the
A.
B.
C.
D.
same name, same number of arguments having the same data types as a method in the super class
different name, same number of arguments having the same data type as a method in the super class
same name but different number of arguments as a method in the super class
same name, same number of arguments but different data types as a method in the super class
2.A constructor that is automatically generated in the absence of explicit constructors called?
A.
B.
C.
D.
Default Constructor
Nullary Constructor
Empty Constructor
All the above
3.Choose best option that describes Constructor.
A.
B.
C.
D.
Have no return type
Use name of the class and have no return type
Use name of the class
None of the above
4.Overloaded methods are differentiated by
A.
B.
C.
D.
Number of arguments
Data type of arguments
Number and the Data type of the arguments
None of the above
5.Which keyword is used to inherit class?
A.
B.
C.
D.
inherit
extends
inheritance
extend
6.Which method of System class is used to copy array?
A.
B.
C.
D.
copyArray
arrayCopy
arraycopy
arrCopy
7.Which is right way to creating an array of integer?
A. javaArray = new int[10];
B. javaArray new = myArray[10];
C. int[] javaArray = new int[10];
PESIT Bangalore South Campus
JAVA Course Information VII sem Information Science & Engineering
D. A and C Both
8.Which is right way to declare Array?
A.
B.
C.
D.
int[] myArray;
int myArray[];
int []myArray;
A and B Both
9.How integer literal can expressed binary data?
A.
B.
C.
D.
int binaryData = b11010;
int binaryData = bx11010;
int binaryData = 0b11010;
int binaryData = xb11010;
10.If you access an uninitialized local variable will result?
A.
B.
C.
D.
Syntax Error
Compile Time Error
Run Time Error
No Error
11.How many type of Primitive Data Types exist in Java?
A.
B.
C.
D.
5
7
8
10
12.A collection of methods with no implementation is called an ________.
A.
B.
C.
D.
Polymorphism
Inheritance
Interface
Data Binding
13.What is the correct signature of the main method?
A.
B.
C.
D.
public static void main(String[] args)
static public void main(String[] args)
public void main(String[] args)
A and B Both
14.Which is not a valid comment style in Java
A.
B.
C.
D.
/* comment */
/* comment
/** comment */
// comment
15.The Java programming language is a ________?
A. Machine Level Language
PESIT Bangalore South Campus
JAVA Course Information VII sem Information Science & Engineering
B. High Level Language
C. Assembly Level Language
D. None of the above
16.Which is not a valid keyword in java?
A.
B.
C.
D.
null
transient
synchronized
native
17. What is the range of data type short in Java?
a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
d) None of the mentioned
18. What is the range of data type byte in Java?
a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
d) None of the mentioned
19.Explanation:Byte occupies 8 bits in memory. Its range is from -128 to 127.
Which of the following are legal lines of Java code?
a). int w = (int)888.8;
b) byte x = (byte)100L;
c). long y = (byte)100;
d). byte z = (byte)100L;
a) 1 and 2
b) 2 and 3
c) 3 and 4
d) All statements are correct.
20. An expression involving byte, int, and literal numbers is promoted to which of these?
a) int
b) long
c) byte
d) float
21. Which of these literals can be contained in a data type float variable?
a) 1.7e-308
b) 3.4e-038
c) 1.7e+308
d) 3.4e-050
22.Which data type value is returned by all transcendental math functions?
a) int
PESIT Bangalore South Campus
JAVA Course Information VII sem Information Science & Engineering
b) float
c) double
d) long
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
23. What is the output of this program?
class average {
public static void main(String args[])
{
double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5};
double result;
result = 0;
for (int i = 0; i < 6; ++i)
result = result + num[i];
System.out.print(result/6);
}
}
a) 16.34
b) 16.566666644
c) 16.46666666666667
d) 16.46666666666666
View Answer
24. What is the output of this program?
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
class conversion {
public static void main(String args[])
{
double a = 295.04;
int b = 300;
byte c = (byte) a;
byte d = (byte) b;
System.out.println(c + " " + d);
}
}
a) 38 43
b) 39 44
c) 295 300
d) 295.04 300
25. What is the output of this program?
1.
2.
3.
4.
5.
6.
7.
class increment {
public static void main(String args[])
{
int g = 3;
System.out.print(++g * 8);
}
}
a) 25
b) 24
c) 32
d) 33
PESIT Bangalore South Campus
JAVA Course Information VII sem Information Science & Engineering
26. What is the output of this program?
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
class area {
public static void main(String args[])
{
double r, pi, a;
r = 9.8;
p1 = 3.14;
a = pi * r * r;
System.out.println(a);
}
}
a)
b)
c)
d)
301.5656
301
301.56
301.56560000
27. Which of these access specifiers must be used for main() method?
a) private
b) public
c) protected
d) None of the mentioned
28. Which of these is used to access member of class before object of that class is created?
a) public
b) private
c) static
d) protected
29. Which of these is used as default for a member of a class if no access specifier is used for it?
a) private
b) public
c) public, within its own package
d) protected
30. What is the process by which we can control what parts of a program can access the members of a
class?
a) Polymorphism
b) Abstraction
c) Encapsulation
d) Recursion
PESIT Bangalore South Campus
JAVA Course Information VII sem Information Science & Engineering
31. Which of the following statements are incorrect?
a) public members of class can be accessed by any code in the program.
b) private members of class can only be accessed by other members of the class.
c) private members of class can be inherited by a sub class, and become protected members in sub class.
d) protected members of a class can be inherited by a sub class, and become private members of the sub class.
32. What is the output of this program?
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
class access{
public int x;
private int y;
void cal(int a, int b){
x = a + 1;
y = b;
}
}
class access_specifier {
public static void main(String args[])
{
access obj = new access();
obj.cal(2, 3);
System.out.println(obj.x + " " + obj.y);
}
}
a) 3 3
b) 2 3
c) Runtime Error
d) Compilation Error
33. What is the output of this program?
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
class access{
public int x;
private int y;
void cal(int a, int b){
x = a + 1;
y = b;
}
void print() {
system.out.println(" " + y);
}
}
PESIT Bangalore South Campus
JAVA Course Information VII sem Information Science & Engineering
12.
13.
14.
15.
16.
17.
18.
19.
20.
class access_specifier {
public static void main(String args[])
{
access obj = new access();
obj.cal(2, 3);
System.out.println(obj.x);
obj.print();
}
}
a) 2 3
b) 3 3
c) Runtime Error
d) Compilation Error
34. What is the output of this program?
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
class static_out {
static int x;
static int y;
int add(int a, int b){
x = a + b;
y = x + b;
}
}
class static_use {
public static void main(String args[])
{
static_out obj1 = new static_out();
static_out obj2 = new static_out();
int a = 2;
obj1.add(a, a + 1);
obj2.add(5, a);
System.out.println(obj1.x + " " + obj2.y);
}
}
a) 7 7
b) 6 6
c) 7 9
d) 9 7
35. Which of these access specifier must be used for class so that it can be inherited by another sub class?
a) public
b) private
PESIT Bangalore South Campus
JAVA Course Information VII sem Information Science & Engineering
c) both a & b
d) None of the mentioned
36. What is the output of this program?
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
class test {
int a;
int b;
test(int i, int j) {
a = i;
b = j;
}
void meth(test o) {
o.a *= 2;
O.B /= 2;
}
}
class Output {
public static void main(String args[])
{
test obj = new test(10 , 20);
obj.meth(obj);
System.out.println(obj.a + " " + obj.b);
}
}
a) 10 20
b) 20 10
c) 20 40
d) 40 20
PESIT Bangalore South Campus
JAVA Course Information VII sem Information Science & Engineering
Download