0% found this document useful (0 votes)
30 views

JAVA Notes

Uploaded by

sayyedaman530
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

JAVA Notes

Uploaded by

sayyedaman530
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 42

2 Marks Questions

a. Differentiate between Iterator and ListIterator.


b. What are different states in lifecycle of Thread?
c. What is the role of Prepared Statement?
Answer: A,B,C
d. Differentiate between ArrayList and Array.
e. What is Thread?
f. What is accept() method sin networking?
Answer: D,E,F
g. What are common JDBC Exceptions? Bk:32
h. What is the difference between Process and Thread? BK: 29
Answer:G,H

i. Mention the Implicit Objects in a JSP.


Answer:
request
response
out
session
application
config
page
pageContext
j. What is socket ?
k. What is hibernate?
l. What is use of accept ( ) method?
Answer:J,K,L

m. What is the use of forName() method ?


n. What is JSP?
o. What is spring?
Answer: N,O
5 Marks Questions
a. Explain the concept of Socket and Server Socket with suitable syntax.

b. Explain thread life cycle with suitable diagram. Bk:14


c. What are different types of JDBC Drivers? Bk:35
d. What is Thread? How to set Priority to the thread? Bk:15
e. What is difference between execute( ), execute Query( )and execute Update(
)?
f. Explain the SortedSet Interface with example.
g. Explain the difference between TCP/IP and UDP. Bk:56
Answer:F,G

h. Explain difference between Statements and Prepared Statement.


4 Marks Questions
a. What are the benefits of the Spring Framework?
b. Differentiate between List and Set interface.

c. Explain JDBC Architecture in detail.


d. Describe the life cycle of servlet.

e. Short note on Session Tracking.


f. Explain Socket and Server Socket.

g. Explain different ways to create Thread.


h. Short note on Set Interface

i. Explain in detail JSP tags with example.


j. Short note on Networking Terminology.

k. Explain thread synchronization with suitable example.


l. Explain JDBC Drivers with a suitable diagram

m. Explain in detail the following components of JSP.


1. JSP Directives.
2. JSP Tags.
3. Scripting Elements.

m.State purpose of:


i. Statement
ii. Connection
iii. ResultSet
iv. DriverManager
Programs

1. Write a java program to display IP Address and Name of client


machine.
2. Write a java program to display “Hello Java” message n times on the
screen. (Use Runnable Interface)
3. Write a JDBC program to count the number of records in table.
(Without using standard method).
4. Write a java program which will display name and priority of current
thread. Change name of Thread to MyThread and set the priority to 2
and display it on screen.
5. Write a java program to display all the alphabets from ‘A’ to ‘Z’
after every 3 seconds.
6. Write a JSP program to check whether given number is Armstrong or
not.
7. Write a java program to create a Mobile (Model_No,
Company_Name, Price, Color) table.
8. Write a JDBC program to delete the records of employees whose
names are starts with ‘A’ character.
9. Write a JSP program to accept Name and Age of Voter and check
whether he is eligible for voting or not.
MCQ
1. Which of the following is a part of the Java Collections Framework?
a) ArrayList
b) Array
c) int[]
d) String

2. Which is the root interface of the Java Collection framework hierarchy?


a) Collection
b) Root
c) Collections
d) List/Set

3. Which collection does not allow duplicate elements?


a) List
b) Set
c) Map
d) All of the above

4. What is the implementation of the List interface?


a. HashMap
b. HashSet
c. LinkedList
d. LinkedHashSet
5. What are the implementation classes of the List interface?
a. ArrayList
b. HashSet
c. LinkedList
d. Vector

6. Which class is a resizable array implementation?


a) LinkedList
b) ArrayList
c) HashSet
d) ArrayDeque

7. Which collection ensures that elements are processed in first-in-first-out (FIFO)


order?
a) HashSet
b) LinkedHashSet
c) LinkedList
d) PriorityQueue

8. Which of these is not a method in the Collection interface?


a) add()
b) get()
c) remove()
d) size()
9. Which of the following collections is thread-safe?
a) Vector
b) ArrayList
c) LinkedList
d) TreeSet

10. Which method removes all elements from a collection?


a) clear()
b) deleteAll()
c) removeAll()
d) purge()

11. What are the implementation classes of the Set interface?


a. HashSet
b. LinkedHashSet
c. ArrayList
d. TreeSet

12. Which of the following lists can contain the same element multiple times?
a) Set
b) Map
c) List
d) None of the above
13. Which method is used to obtain the size of a collection?
a) length()
b) getLength()
c) count()
d) size()

14. Which of the following is ordered and sorted by its natural ordering or by a
comparator?
a) HashSet
b) LinkedHashSet
c) TreeSet
d) List

15. Which list method replaces the element at a specified position?


a) replace()
b) set()
c) put()
d) insert()

1. What is multithreading in Java?


a) A programming language for concurrent execution.
b) A technique to execute multiple programs simultaneously.
c) A concept of executing multiple threads concurrently within a single program.
d) A method for parallel processing of data.

2. What is a thread in Java?


a) A lightweight process that executes a sequence of instructions.
b) A memory allocation unit in Java.
c) A Java keyword to define a loop construct.
d) A data structure to store multiple values.

3. Which class is used to create a thread in Java?


a) Thread
b) Runnable
c) Process
d) Executor
4. How can synchronization be achieved in Java threads?
a) Using the synchronized keyword.
b) Using the volatile keyword.
c) Using the final keyword.
d) Using the static keyword.

5. What is the purpose of the wait() method in Java threads?


a) To pause the execution of a thread.
b) To terminate a thread.
c) To notify other threads to resume execution.
d) To release the lock held by the thread.

6. Which method is used to start the execution of a thread?


a) start()
b) run()
c) execute()
d) begin()

7. What is the maximum number of threads that can be created in a Java


program?
a) There is no fixed limit.

b) It depends on the amount of available memory.


c) It depends on the number of CPU cores.
d) It is limited to 100 threads.

8. What is the main advantage of multithreading in Java?


a) Improved program performance.
b) Simplified program structure.
c) Reduced memory usage.
d) Elimination of runtime errors.
9. In java multi-threading, a thread can be created by
a) Extending Thread class
b) Implementing Runnable interface
c) Using both
d) None

10. Which method is called internally by Thread start() method?


a) execute()
b) run()
c) launch()
d) main()

11. What is maximum thread priority in Java ?


a) 10
b) 12
c) 5
d) 8

12. Which method must be implemented by a Java thread?


a) run()
b) execute()
c) start()
d) None
13. Number of threads in below java program is
a) 0
b) 1
c) 2
d) 3

14. Execution of a java thread begins on which method call?


a) Start ()
b) Run ()
c) Execute ()
d) Launch ()

15. How many ways a thread can be created in Java multithreading?


a) 1
b) 2
c) 3
d) 4

16. Default value of a java thread is


a) 0
b) 1
c) 5
d) 10
17. If a priority of a java thread is 3 then the default priority of its child thread will
be
a) 0
b) 1
c) 5
d) 3

18. Which method is used to check if a thread is running?


a) isAlive()
b) run ()
c) alive ()
d) keepAlive()

19. Min and Max priority of a thread in Java multithreading are


a) 1, 10
b) 0,10
c) 0,255
d) 1,256

20. Which method we implement from Runnable interface?


a) Run ()
b) Start ()
c) Execute ()
d) call ()
21. Daemon thread runs in
a) Background
b) Foreground
c) Both
d) none

22. Which method is used to create a daemon thread?


a) setDaemon(boolean value)
b) setThread(boolean value)
c) createDaemon(boolean value)
d) makeDeamon(boolean value);

23. The life cycle of a thread in java is controlled by


a) JRE
b) JDK
c) JVM
d) None

24. Which method is used to get current running thread object?


a) runningThread()
b) currentThread()
c) runnableThread()
d) None
25 Thread priority in Java is?
a) Integer
b) Float
c) double
d) long

26. What is the name of the thread in the following Java Program
a) main
b) Thread
c) System
d) None of the mentioned

27. Which of the following will ensure the thread will be in running state?
a) yield()
b) notify()
c) wait()
d) Thread.killThread()

28. What decides thread priority?


a) Process
b) Process scheduler
c) Thread
d) Thread scheduler
1. Connection object can be initialized using the ............................ method of the
Driver Manager class.
A) putConnection()
B) setConnection()
C) Connection()
D) getConnetion()

2. The ......................... method executes an SQL statement that may


returnmultiple results.
A) executeUpdate()
B) executeQuery()
C) execute()
D) noexecute()

3. The ................................ method executes a simple query and returns a


singleResult Set object.
A)executeUpdate()
B) executeQuery()
C) execute()
D) noexecute()
4. How many statement objects can be created using a Connection?
A. 2
B. 1
C. 3
D. Multiple

5. Parameterized queries can be executed by?


A. ParameterizedStatement
B. PreparedStatement
C. CallableStatement and Parameterized Statement
D. All kinds of Statements

6. Which methods are required to load a database driver in JDBC?


A. getConnection()
B. registerDriver()
C. forName()
D. Both b and c

7. Thin driver is also known as?


A. Type 3 Driver
B. Type-2 Driver
C. Type-4 Driver
D. Type-1 Driver
8. What are the major components of the JDBC?
A. DriverManager, Driver, Connection, Statement, and ResultSet
B. DriverManager, Driver, Connection, and Statement
C. DriverManager, Statement, and ResultSet
D. DriverManager, Connection, Statement, and ResultSet

9. Which of the following methods are needed for loading a database driver
inJDBC?
A. registerDriver() method
B. Class.forName()
C. Both A and B
D. getConnection()

10 Which method is used to perform DML statements in JDBC?


A. execute()
B. executeQuery()
C. executeUpdate()
D. executeResult()

11. Which of the following is used to call a stored procedure?


A. Statement
B. PreparedStatement
C. CallableStatment
D. CalledStatement
12. Which of the following is not a valid type of statement in JDBC?
A - Statement
B - PreparedStatement
C - CallableStatement
D - QueryStatement

13. What does JDBC stand for


a) Java Database Connectivity
b) Java Data Binding Connection
c) Java Database Control
d) Java Data Business Connector

1. The Java __________ specification defines an application programming


interface for communication between the Web server and the application
program.
a) Servlet
b) Server
c) Program
d) Randomize
2. The doGet() method in the example extracts values of the parameter’s type
and number by using __________
a) request.getParameter()
b) request.setParameter()
c) responce.getParameter()
d) responce.getAttribute()

3. A JSP is transformed into a(n):


a) Java applet
b) Java servlet
c) Either 1 or 2 above
d) Neither 1 nor 2 above

4. Which of these functions is not a part of the servlet lifecycle


a) Checking if an instance of servlet exists or not
b) Invoking the service method of the servlet
c) Shutting down the servlet
d) Pausing the servlet for a given period of time.

5. What is the full form of JSP?


a) Java servlet program
b) Java server pages
c) Java server pages
d) Java server program
6. Which of the following code is used to get an attribute in a HTTP Session
object in servlets?
a) session.getAttribute(String name)
b) session.alterAttribute(String name)
c) session.updateAttribute(String name)
d) session.setAttribute(String name)

7. Which are the session tracking techniques?


i. URL rewriting
ii. Using session object
iii.Using response object
iv. Using hidden fields
v. Using cookies
vi. Using servlet object
a) i, ii, iii, vi
b) i, ii, iv, v
c) i, vi, iii, v
d) i, ii, iii, v

8. Which page directive should be used in JSP to generate a PDF page?


a) contentType
b) generatePdf
c) typePDF
d) contentPDF
9. Which tag should be used to pass information from JSP to included JSP?
a) Using <%jsp:page> tag
b) Using <%jsp:param> tag
c) Using <%jsp:import> tag
d) Using <%jsp:useBean> tag

10. Which one is the correct order of phases in JSP life cycle?
a) Initialization, Cleanup, Compilation, Execution
b) Initialization, Compilation, Cleanup, Execution
c) Compilation, Initialization, Execution, Cleanup
d) Cleanup, Compilation, Initialization, Execution

11. “request” is instance of which one of the following classes?


a) Request
b) HttpRequest
c) HttpServletRequest
d) ServletRequest

12. Which one of the following is correct for directive in JSP?


a) <%@directive%>
b) <%!directive%>
c) <%directive%>
d) <%=directive%>
13. Which of the following action variable is used to include a file in JSP?
a) jsp:setProperty
b) jsp:getProperty
c) jsp:include
d) jsp:plugin

14. “out” is implicit object of which class?


a) javax.servlet.jsp.PrintWriter
b) javax.servlet.jsp.SessionWriter
c) javax.servlet.jsp.SessionPrinter
d) javax.servlet.jsp.JspWriter

15. Java code is embedded under which tag in JSP?


a) Declaration
b) Scriptlet
c) Expression
d) Comment

16. Which of the following is not a directive in JSP?


a) page directive
b) include directive
c) taglib directive
d) command directive
17. Which interfaces declare a getSession() method?
a) ServletRequest
b) ServletResponse
c) HttpServletRequest
d) HttpServletResponse

18. What is a servlet in Java?


a) A programming language
b) A scripting language
c) A server-side technology for Java web applications
d) A database management system

19. Which interface must a Java class implement to create a servlet?


a) Servlet
b) HttpServlet
c) ServletConfig
d) ServletRequest

20. How many jsp implicit objects are there and these objects are created by
the web container that are available to all the jsp pages?
a) 8
b) 9
c) 10
d) 7
21. Which is not a directive?
a)include
b)page
c)export
d)taglib

1. What is Spring Core?


a) A Java framework for creating user interfaces
b) An IDE for developing Spring based applications
c) A sub-module of Spring framework
d) A scripting language of the Spring Framework

2. In Spring’s XML configuration file, which XML tag is used to define a


bean?
a. <component>
b. <service>
c. <bean>
d. <dependency>
3. Which annotation is used to declare a class as a Spring bean in a Java
based configuration class?
(a) @Service
(b) @Bean
(c) @Component
(d) @Autowired

4. Which scope in Spring ensures that object exists between every request in
an HTTP session?
(a) Singleton
(b) Prototype
(c) Request
(d) Session

5. What is Hibernate?
a) A programming language
b) A database management system
c) An object-relational mapping (ORM) framework
d) A scripting language

You might also like