25 MCQ
25 MCQ
@ParameterizedTe
st
@CsvSource(value={"TechVersant@1","TechVersant@2"} , delimeter='@')
void simpleCsv( final String s1 , final
int n1) { assertNotNull(s1);
assertTrue(n1>0);
}
}
9) A)
Refer the following code Mrs Janet has been asked to code JDBC pstatement.setString(1,bean.getMovieNa
program to insert movie details in the movie table columns 'movieid' , me());
'moviename' , 'genre' and 'language'. Help her to complete the pstatement.setString(2,bean.getGenre());
following code by identifying the right set of pstatement.setString(3,bean.getLanguage
statements to be added. Choose one. Note that Mysql database is ());
locally installed . Default port numner is used. Schema is 'jdbcdemos'. rowsInsertCount=pstatement.executeUpd
'Movie' Bean class has fields int 'movieId', String 'movieName', String ate();
'genre' and String 'language'.
Anyone of these is the answer( Give first preference for .value and then second preference for the
one which is printed answer)mrs.
15) @NamedQueries({
alechmist @NamedQuery(name="latest_book",query="select b.bookName from BookEntity b where b.public
harry year IN(select MAX(b. publishyear)from BookEntity b)"),
potter @NamedQueries({
black @NamedQuery(name="oldest_book",query="select b.bookName from BookEntity b where b.public
beauty year IN(select MIN(b. publishyear)from BookEntity b)"),
the secret
life of Pi
Davinvi
code
@entity
@table(name="book"
) public class
Bookentity{ @Id
@column(name="bo
okId") private integer
bookId;
@column(name="book_
name") private string
bookName; private
Stringauthor
16)
Sheila wants to check if a condition in her code is working correctly . Which Junit assert method is void assertTrue(boolean condition)
appropriate for her?
17) <head>
Which one of the below tag creates boundaries of document header?
18) <boby></body>
which of the below is valid XML tag
19)
consider the below XSl file calle Library Transform.xsl with code
<xsl;stylsheet version ="1.0"xmlns = "https://...
<xsl:template match="/">
<html>
<body> <books>
<h1>Library</h1> <book>
<tr> </book>
<td>ISBN</td> <book>
<td><xsl:value-of select-"isbn"/></td>
<td><xsl:value-of select="title"/></td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Which of the below would generate a well formed xml with above x
20)
<html>
<body>
<h2> form </h2>
<form>
option to create html form, that allow users to enter name,email and gender. must allow to select only Name:<
one of a given choice male,female and other. br>
<input type="text" id="fname"
name="fname"><br> email:<br>
<input type = "text" id="email"name="email></br>
<input type = "radio"
id="male"name="gender>value="male"> male<br>
<input type = "radio"
id="female"name="gender>value="female">
female<br>
<input type = "radio"
id="other"name="gender>value="other"> other</br>
</form></body></html>
21)
.box1{
bob has a requirement to style a div element in his webpage to have background color to be red background-color
and font style to be italic. below is the div element,help bobselect the most appropriate way to red; font-style
apply styling via CSS. italic;
<div class="box"></div> }
22)
jdbc:mysql://localhost:3306/test
In order to establish connection with MYSQL database in JDBC which one of the following
connection urls is correct? note that port number is 3306,schema is test and mysql is locally
instead
23) ge
there are a number of http methods.select valid http methods from given list[choose 2] t
pu
t
24)
Jacqueline wants to create a customer report by fetching customerId, customername and
customerlocation from customer table. Consider CustomerEntity class with the following
structure.
@Entity
class
CustomerEntit
y{ @Id
private int customerId;
private String
customerName; private
String customerContact;
private String
customerLocation;
//Code with getters and setters
}
Help her to select the appropriate code from the given options.sssssssss
25)
Which of the below statements are correct with respect to HTTP and HTTPS:
1. HTTPS stands for Hyper Text Transfer Protocol Server 2nd and 3rd statements are correct
2. HTTPS is Combination of HTTP and Secure Socket Layer (SSL)
3. The https:// web pages indication along with a lock icon in the browser window pane
indicate the presence of a secure web page.
26) One to many unidirectional association
Ani is working with a house construction application. She created two entity classes
House and Window that helps to design the application. What's true about the
following @Entity association
between House and
Window? @Entity
public class Window{
@ld
private int winNo;
private House
aHouse;
}
@Entity
public class House {
@ld
private int houseNo;
@OneToMany(cascade Cascade
Type ALL) private List<Window>
windows;
}
Choose the best option
27)
Punith, a developer wants to synchronize the changes done on the CustomerEntity object on the
customer table.
He is using the below code to update the changes
Which of the following customer data will be stored/updated in the customer table after executing the
above code.
28)
Mr. Gaetano gets following error upon executing the code to retrieve details from the table
"movie" with columns movied, moviename, genre and language. From the following options
which one he has to add in line1 in order to fix it.
Note that Mysql database is locally installed. Default port number is used. Schema is jdbcdemos < add
movie bean structure>. Movie Bean class has fieds int movield, Sting movieName, String genre and
String language.
Refer the following code
Error:
31)
Harry wants to creates a customer report for CRM application. When there are no more rows to iterate the retrieved result the next() method returns nothin
He wants to iterate the records from employee table. He is using
ResultSet for the first time. Help him to identify one wrong
statement about ResultSet from the given option.
32)
Eesha wants to add a new customer record in a
customer table. Consider the CustomerEntity with the
below structure.
class
CustomerEntit public integer addcustomer throw exception { integer customerid =0; entitymanager entitymanager
y{ int =null;
customerid;
String
customerName;
String
customerLocation;
String
customerType;
//Generate getters and setters
}
Help her to select the appropriate code from the below options to achieve this task.
33)
1. Junit
5 supports Java 5 or higher
Which of these statements are incorrect with respect to Junit 5? 2. Junit
Jupiter provides support for running Junit 3 and Junit 4 based
test on the platform. 3.Annotation @BeforeAll is analogous to Junit 4's
@beforeEach
34) select movie,screen from movieEntity movie,ScrrenEntity screen where Movie.movieid =
consider BookMyTicket application.It allows users to book movie tickets. JPA is screen.movieid
used for persistance operations. It has two entities MovieEntity with fields int
'movieId', String 'movieame', String 'genere' and String 'language'. ScreenEntity
with field int 'movieId',int 'screenId', String 'screenName', Date 'showTime.They
share one to one association.You are required to write JPQL to fetch movie
name, genre, language, screen name and show them to give movie id. Which
one of the following JPQL queries is correct?
35)
Consider the following entity classes and sample
records @Entity
@Table(name =
"customer") public class
CustomerEntity{
@Id
private Integer
customerId; private
String customerName;
@ManyToOne(cascade =
CascadeType.PERSIST)
@JoinColumn(name="locationId_fx")
private LocationEntity location;
customer
customer Id customerName
locationId_fk 1001 Jack 1
1002 Jim 1
1003 Jai 2
location
locationId
city
1 Chennai
2 Pune
3 Banglore
36)
BookEntity.java
@Entity
@Table(name =
"book") public
class BookEntity{
@Id
@Column(name="book_i
d") private Integer
bookId;
@Column(name="book_
name") private String
bookName;
persistence.xml
1)Runtime exceptio in
<persistence version="2.1"
line-1 2)101
xmlns="http://xmins.jcp.org/xml/ns/persistence"xmlns:xsi="http://www.w3.org/2001/X
3)complilation error in ine-
MLSchema-instance"
2 4)Runtime exception in
line-3
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
<persistence-unit name='JPA Merge">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.entity.BookEntity</class> Answer: Runtime exception in line-3
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value='jdbc mysql:localhost:8306jpa_de" />
<property name='javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="root">
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
<persistence>
BookMain.java
37) @Embed
dedId
@Embedda
choose from below INVALID annotation in JPA ble
@NamedQu
ery
@Qualifier
Answer: @Qualifier
38)
Ben wants to delete the
customer record 1001 john Employee deleted successfully:1001
1002 jack Employee deleted successfully:1
1003 Employee deleted successfully:2
krish int OOps some thing went wrong!! we are on process..
id=1001;
String customerdata="DELETE" from customer
WHERE customer="+ id+";
DriveManager
getConnection(")dbc.mysql://localhost:3306/jdbcdemos","root","root");
Statement statement =connection.createStatement(); Answer:
int Employee deleted successfully:1
deleteRowsUpdateCount=statement.executeUpdate(d
eletedata); if(deleteRowsUpdateCount>0){
System.out.println("Employee deleted Successfully:"+ deleteRowsUpdateCount);
1- 1st
funcation sum(){
document froms.calc.result.value=
parseInt(document.forms.calc.number2.value)+
parseInt(document.forms.calc.number1.value);
}
2-
public int getSum(int a
int b){ reurn a+b;
}
3-
function int getSum(int a, int
b){ return a+b;
}
41) It is dependent on the database
Choose the disadvantage on thin driver from below options
42)
Suresh a marketing executive wants to create an customer report on PreparedStatement
monthly basis. He wants to iterate the records from customer table more
faster. Help him to select appropriate interface for this situation.
43)
Choose from the following CORRECT statements about Class.forName() method call.
This method is used for dynamically loading the driver's class fle into memory and to I and II only
register it automatically.
I) Since JDBC 4.0 this is redundant since auto discovery was enabled.
II) this method is used for dynamically loading the driver's class file into memory and register it
automatically.
III) It is used only for loading type 4 driver
44)
Assume that book table is created in book db database and record is
inserted as per below schema
Incomplete Question
45) EntityManagerFactory
Which object represents the programmatic connection definition? It also reads
the connection information from persistence.xml by mapping with the PersistenceUnitName
46) @NamedQueries({
Choose from below VALID named queries annotation in JPA @NamedQuery(name="query1",query= "select b from BookEntity b”),
@NamedQuery(name="query2",query = "select b.bookld from
BookEntityb”)Statement
})
47) Unit testing
What type of testing is done using Junit?
48) Failed assumptions result in a test failure
Anil is explaining JUnit 5 assumptions to his team. Which one of the below
statements is false with respect to assumptions and assertions?
49)
Consider the following test case:
@Test
public void testAssertions() {
50)
Thomas is designing home page for a news website. Home page design <link rel="stylesheet"type="text/css" href="containerstyle.css"/>
consist of many container like <div> tag to display the new article details.
Thomas needs to follow certain css design which are standard throughout
the website design. This standard css design are available as extemal
css file called containerstyle.css. Please choose the most approapriate
option to help Thomas to use the standard css in his home page design.
51)
Answer: C
55)
Jack wants to delete a customer(customerld 1001) from a customer table ,
since customer is not active for longer time. He is using the below code to
delete the customer record.Consider persistance unit is "unit1".
@Entity
class
CustomerEnti
ty { @Id
int customerld; Removed
String customerName;
//Generate getters and setters
}
class CustomerDao {
public void
deleteCustomer() { try {
int id=1001;
EntityManagerFactory entityManagerFactory =
Persistence.createEntityManagerFactory('unit1");
EntityManager entityManager =
entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
employeeEntity =
entityManager.find(EmployeeEntity.class.id); if (id
== employeeEntity.getEmployeeld()) {
entityManager.remove(employeeEntity);
entityManager.getTransaction().commit();//line
-1
}
else
{
System.out.printin("employee id doesn't
exist!");
}
}
catch(Exception exception) {
exception.printStack
Trace();
}
}
Observe the above code and find out entity object goes to which state after line - 1
56) Unit Testing
What type of testing is done using Junit?
57) Java Database Connectivity
What JDBC stands for?
58) JDBC allows us to write application to interact with relational database using JDBC API
What is JDBC?
59) ConnectionPool
Which of the following is not a component/class of JDBC API?
60) A - JDBC DriverManager is a class that manages a list of database drivers.
Which of the following is correct about DriverManager class of JDBC? B - It matches connection requests from the java application with the proper
database driver using communication subprotocol.
Ans: Both
61) A - JDBC driver is an interface enabling a Java application to interact with a database.
B - The JDBC driver gives out the connection to the database and implements the protocol
Which of the following is correct about driver interface of JDBC? for transferring the query and result between client and database.
Ans: Both
62) A - Connection interface consists of methods for
Which of the following is correct about Connection interface of JDBC? contacting a database. B - It represents communication
context.
Ans: Both
63) A - Statement encapsulates an SQL statement which is passed to the database to be
Which of the following is correct about Statement class of JDBC? parsed and compiled. B - Statement encapsulates an SQL statement which is passed
to the database to be planned and executed. Ans: Both
64) A) ResultSet holds data retrieved from a database after you execute an SQL query using Statement
Which of the following is correct about ResultSet class of JDBC? objects.
B) It acts as an iterator to allow you to move through its data.
C) The java.sql.ResultSet interface represents the result set of a
database query. Ans : All
65) DriverManager
Which of the following manages a list of database drivers in JDBC?
66)
Which of the following gives out the connection to the database and implements the protocol JDBC driver
for transferring the query and result between client and database?
67) Connection
Which of the following consists of methods for contacting a database?
68)
Which of the following encapsulates an SQL statement which is passed to the database to be Statement
parsed, compiled, planned and executed?
69) ResultSet
Which of the following holds data retrieved from a database after you execute an SQL query using
Statement objects?
70) ResultSet.TYPE_BACKWARD_ONLY
71) ResultSet.TYPE_FORWARD_ONLY
In which of the following type of ResultSet, the cursor can only move forward in the result set?
72)
In which of the following type of ResultSet, the cursor can scroll forwards and backwards, and the ResultSet.TYPE_SCROLL_SENSITIVE
result set is sensitive to changes made by others to the database that occur after the result set
was created?
73) JDBC-ODBC Bridge plus ODBC driver
Which of the following type of JDBC driver, calls native code of the locally available ODBC driver?
74)
Which of the following type of JDBC driver, calls database vendor native Native-API, partly Java driver
library on a client side. This code then talks to database over network?
75) JDBC-Net, pure Java driver
Which of the following type of JDBC driver, talks with the server-side middleware that then talks to
database?
76) Native-protocol, pure Java driver
Which of the following type of JDBC driver, uses database native protocol?
77) JDBC-ODBC Bridge plus ODBC driver
Which of the following type of JDBC driver, is also called Type 1 JDBC driver?
78) Native-API, partly Java driver
Which of the following type of JDBC driver, is also called Type 2 JDBC driver?
79) DriverManager, Driver, Connection, Statement, ResultSet, SQLException
What are the component/class of JDBC API?
80)Which of the below is/are valid javascript function(s)?
81)
import
org.junit.jupiter.api.Assertion;
import org.junit.jupiter.api.Test;
class McqTests
{ @Test
public void testAssertions() { Assertions.assertEquals(sValue1, sValue2);
String sValue1= new
String("TechGenics"); String sValue2=
"TechGenics";
//Line 3
}
}
}
Which one of the below assertions, if placed at Line 3 in above code, will result into sucessful for
execution.
1. Assertions.assertSame(sValue1, sValue2);
2. Assertions.assertEquals(sValue1, sValue2);
82)
Mr.Fred is a curator of the chain of museaums owned by the government. He is unsing a jaba
application names publicomuseo to store,retrive and modify artifect deatils in tnames hose
museaums.
Many to one
Mr. Martin runs an event management company names gastinodevents.Both have joined hands to the
host events
in those museaums to ignite interest among the public.Assuming that application uses JPA for
persistance operartions
which type of association exists between museum entity and Event entity.Choose one.
83)
which of the following is/are valid to register driver class in JDBS?
1)DriverManager.getConnection("driverClassName");
2)DriverManager.registerDriver("driverClassName");
3)DriverClassName obj=new DriverClassName(); Statement 2consider Beckyanithomas,3 & 4
4)Class.forName("driverClassName");
84)
EntityManagerFactory provider name Has connection information,entity names and persistance 1-iii,2-iv,3-ii,4-i
EntityManager data from a A logical collection of data for storing,manipulating and retriving
database Entity connections Represents the programmatic connection templete for creating
persistance.xml Manages entities and performs CRUD operations
85) @test,
please select the correct annotations @desabl
ed@tag
86) create
which of the following options are valid for property " hibernate.hdm2ddi.auto" update
create-
drop
87) org.junit.jupiter.api.test
harish and team is writing is writing a junit5 based test cases.help them to identify,which annotation. .....................................
method ..........................some code below
88)
Yash task is to update the customer record using JPQL so he was writing update statement and passed Answer:- B) Parameter cannot be passes to a named query to do the operation on required data set
to the createQuery() method, then he realised that its not a good practice to pass query string while
creating queries. He would like to use namedQuery for this approach. Help him to identify wrong
statement about NamedQuery.
89)
Predict the output of following program:
import
org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Assertion fails and displays the supplied failure message “condition is true”
class
McqTests{
@Test
public void
TestAssertions(){ int
iValue1 = 200;
int iValue2 = 200;
Assume that table book is already created in the book_db database, with columns 'book_id',
public class
TransactionExample{ private
static Connection connect =
null; Answer :- A) 1
private static PreparedStatement
preparedStatement1 = null; private static
PreparedStatement preparedStatement2 = null;
In JPA, JPQL queries are translated by JPQL query processor. Consider the Answer :- A) Select m from MovieEntity m;
From the following identify the equivalent JPQL statement. Note that table is MovieDetails and entity is
MovieEntity.
92) Option A is the answer
@ManyToMany(cascade=Cascade Type.ALL)
@JoinTable(name=”book_publisher”,
joinColumns={@JoinColumn(name=”book_fk_id”)};
inverseJoinColumns={@JoinColumn(name=”publisher_fk_id”)})
Assume that BookEntity and PublisherEntity has many to many JPA Entity
93)
True
1001 Delhi
94)
a) @Embeddable
Consider that John finds difficulties in searching a book by its bookid alone, he Class BookCPK{
Private Integer bookId;
believed that book can be retrived easily than before it composite primary key for Private String publisherId;
}
publisherId is also created for the book table. @Entity
@Table(name=”book”)
Class Book{
Choose the VALID code from below to create a composite primary key for bookId &
@Embeddedid
private BookCPK bookCpk;
publisherId in book
private String bookName;
private Double price;
private String author;
}
97)
Select the valid way in which JavaScript can be associated with an HTML document.
[Choose 3]
First three option are correct
99) 1
5
Assume that book table is available in the database book_db, with following table 10
50
schema………… Run time exception in line-n
Answer: <script>
If same set of styles have to be applied across various html documents then which type of css is most approriate External CSS
Inline CSS
Internal CSS
Embedded CSS
Answer: only A
Refer the Junit code given below. @ParameterizedTest
@RepeatedTest(3)
Class TestClass{ @ParameterizedTest(3)
//Line-X @RepeatedTest
@ValueSource(ints = {1,2,4})
Public void serviceTest(final int num) {
//code goes here
} Answer: @ParameterizedTest
}
Which of the following should be placed at Line-X so that the test method executes 3 times with values 1,2 and 4
respectively.
Refer the JPA code given below. What would be written at Line-X to get the result. query.getResultList().get(0);
query.getSingleResult().get(0)
Query query=em.createQuery(“SELECT count(*) FROM CustomerEntity c”); query.getResult().get(0)
Object obj=_____________ //Line-X query.getResultObject().get(0);
System.out.println(obj);
Answer: query.getResultList().get(0);
What would happen if the code given below executes? Prints “Exception”
Assume that table Project(pid,pname) is created in the database.
Refer the JPA code given below. Assume that all required interfaces and classesare imported and “em” refers to Removed, managed
“EntityManager” and Customer is an entitybean class. Customertable has a record with customer Id 100. Removed, detached
Managed, detached
Deleted, managed
EntityManager em=emf.createEntityManager();
Entity Transaction et=em.getTranscation();
Customer c=em.find(Customer.class,100);
em.remove(c); //--Line-X Answer: removed, managed
em.persist(c); //--Line-Y
et.commit();
System.out.println(“end”);
What would be the state of the object after executing Lin-X and Line-Y respectively
Which of the following should be placed at Line-X so that theperform() method is executed.
Note: perform() method should be invoked twice, once for service Test1() and then for Service Test2() method
execution respectively.
Assume that entity classes Department and Employee given below are mapped in the database. There is a Department
department record with deptId 10, and employee record with employeeId 100 in department and employee dept=em.find(Department.class,10);
tables respectively. Employee with id 100 is not associated with any department record. Employee emp=em.find(Employee.class,100);
emp.setDepartment(dept);
@Entity et.begin();
Public class Department { et.commit();
@Id
Private String deptName;
@Entity
Public class Employee{
@Id
Private int employeeId;
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name=”deptId”)
Private Department department;
Which of the following code will associate department record whose deptid 10 with employeerecord whose
employeeid is 100. [‘em’ and ‘et’ are reference of type EntityManager and EntityTransaction respectively]