You are on page 1of 14

Consider the below Entity class and corresponding table:

@Entity
public class Product {
private string productId;
private String productName;
private String category;
private Double price;
//getters and setters

Product (product_id is primary key)


product_id product_name category
price
P10001 Dinner Set Kitchen Items
1600
P10002 Curtains Home Decor
790
P10003 Bedsheets Home Decor
959
P10004 Cup Set Kitchen Items
670
P10005 Container Set Kitchen Items
430

Consider the below repository interface:

public interface productReposi tory extends CrudRepository<product, string> {

@Query("update Product p set p.price = (p.price - 100) where p.category


= :category")
@Modifying
@Transactional
void updatePrice(@Param("category") String category);

Assumptions:
1. All necessary imports and configurations are done
2. entityManager is valid reference of JPA EntityManager
3. productRepository bae pkar iga valid reference of ProductRepository Interface

What will happen When the following code is executed?


system. out, println(productRepository . updateprice("Kitchen Items"));

O IllegalStateException: @Param annotation is missing


O QueryExecutionRequestException: Not supported for DML operations
O Nothing will be printed
O 3
Consider the following class:

// Line1
public class ExceptionHandler {
// Line2
public ResponseEnt ity<ErrorInfo> TravelBook ingExceptionHandler
(TravelBookingException exce
//rest of the code
}
}
Which annotations can be inserted at Linel and Line2 so that ExceptionHandler class
can handle the appropriate exceptions thrown from the
application? Note: Consider all necessary imports are added.

a)Line1 - @RestController
Line2 - @ExceptionHandler(TravelBookingException.class)
b)Line1 - @RestControllerAdvice
Line2 - @ExceptionHandler(TravelBookingException.class)
c)Line1 - @RestController
Line2 -@ExceptionHandler()
d)Line1 -@RestControllerAdvice
Line2- @ExceptionHandler(TravelBookingException.java)

Consider the following CustomerDTO and CustomerController classes:

public class CustomerDTO{


private Integer customerId;
private sring emailId;
private string name;
//getters and setter
}
(@Restcontroller
public class customerController {
@Put Mapping(value ="/customers/{customerId}")
public void addcustomer (@PathVariable string customerId, @RequestBody CustomerDTO
customerDTO) {
System.out.print(customerDTO. getCustomerId());
System. out.print(customerDTO.getEmailid());
system. out .print (customerDT0. getName());
//rest of the code
}
Assumption:
1. All the necessary imports and configurations are done.
What will be the output when the above REST Controller receives a HTTP PUT request
with URL "http://localhost:5555/customers/1" and below
JSON as tbody?
{
"customerId":1,
"emailId":" andrew@ìnfy.com ",
"customerName:"Andy"
}

a)1andrew@infy.comnull
b)1andrew@infy.comAndy
c) nullnullnult
d) NulIPointerException will be thrown

Consider the below code.


public class Collections Test {
public static void main (String ] args) {
List<string> numL ist = new ArrayList<>();
int litSize = numList. size();
listSize += 10;
numList.add(" Java ") ;
for (int i = 1; i < listSize; i++) {
numList. add (numList.get(i-1)+ "-Java");
numList. add (++i,"Java");
}
numList.remove (2);
System . out.println("Element at 3rd position:+ numList.get(2));
System. out. println("Size:" + numList.size());

What will be the output of above code snippet? Note: Consider all necessary imports
are added.
a)Element at 3rd position: Java-java
Size:9
b)Element at 3rd position:Java
Size: 9
c)Element at 3rd position: Java-Java
Size: 10
d)Element at 3rd position: Java-java-Java
Size: 10

public class Citizen {


public Boolean isVoter(Integer age) {
return age >= 18;
}
}

public class CitizenTest {


@Test
public void isVoterTest() {
Citizen citizen = new Citizen();
// Line 1
}
}

Assumption:
1. All necessary imports are done
Which of the following statements can replace Line 1 in CitizenTest class in order
to pass the test method isVoterTest(0? (Choose twO correct options)
Assertions.assertTrue(citizen.isVoter(18));
Assertions.assertFalse(citizen.isVoter(18));
Assertions.assertTrue(citizen.isVoter(17));
Assertions.assertFalse(citizen.isVoter(17));
Consider the following entity class and corresponding table:
@Entity
publiC class Trainee{

@Id
//Line 1
private Integer traineeId;
private string name;
private String phoneNumber;
private LocalDate dateofJoining;
//getters and setters
}
create table trainee (
trainee id int auto_increment primary key,
name varchar (30),
phone_number varchar (10),
date_of_joining date
);
Assumption:
1. All the necessary imports and configurations are done.
Which of the following statements can be inserted at Line 1 to generate primary key
values for traineeld?
a) @GeneratedValue(strategy = GenerationType.IDENTITY
b) @GeneratedValue(strategy - GenerationType.AUTO)
c) @GeneratedValue(strategy = GenerationType.SEQUENCE)
d) @GeneratedValue(strategy = GenerationType.TABLE)
Consider the following EmployeeDTO and EmployeeAPI classes:
public class EmployeeDTO {
private Integer employeeId;
private String emailId;
private String name;
private String designation;
//getters, setters, tostring
}
@RestController
@RequestMapping(value = "/infy")
public class EmployeeAPI {
@PostMapping
public void addEmployee (EmployeeDTO employeeDTO) {
System. out .println(employeeDTO);
}
}

Assumptions:
1. All the necessary imports and configurations are done
2. Port number used i 8765

What will be the output whena HTTP POST request is made to the above controller
with url as http://ocalhost:8765/nfy and below data?
"employeeId" : 1,
'emailId" : "andrew@infy. com" ,
"employeeName": "Andrew Wyatt",
"designation" : "Senior Associate"

a) EmployeeDTO [employeeld=null, emailld=null, name=null, designation=null]


b) EmployeeDTO [employeeld=1, emailld=andrew@infy.com, name=null,
designation=Senior Associate]
c) EmployeeDTo [employeeld=1, emailld= andrew@infy.com, name=Andrew Wyatt,
designation= Senior Associate]
d) 404 NOT_ FOUND error
Which methods will match the following pointcut expression?
"execution(private * com.infy.Allocation.find(..))"
a)All private methods of com.infy.Allocation class whose name starts with "find",
takes any number of arguments
b) Any methods of com.infy.Allocation class whose name starts with "find", takes
any number of arguments
c) All private methods of com.infy.Allocation class whose name is "find", takes any
number of arguments and returns void
d) None:Spring AOP supports only advising public methods.

Consider the below table and entity class:


TRAINEE (trainee _id is the primary key)
trainee_id name phone_number date_of_joining
1001 Donna 9988989899 2019-07-29
1002 Harry 9786982189 2019-01-07

@Entity
public class Trainee {
@Id
private Integer traineeId;
private string name;
private string phoneNumber;
private LocalDate dateofJoining;
//getters and setters
}
}

Assumptions:
1. All the necessary imports and configurations are done.
2. TraineeRepository interface extends CrudRepository interface
Which of the following methods can be added to TraineeRepository interface to fetch
details of trainees whose date of joining is between
given dates?
O List<Trainee> findByDateOfjoiningBetween(LocalDate fromDate, LocalDate toDate);
O List<Trainee> findByDateOfGreaterThanAndLessThan(LocalDate greaterThanDate,
LocalDate lessThanDate);
O List<Trainee> findByDateOfjoininginBetween(LocalDate fromDate, LocalDate toDate);
O List<Trainee> getDateOfjoiningBetween(LocalDate fromDate, LocalDate toDate);

public class Student {


//Line 1
private Integer studentId;
//Line 2
private string studentName;
//Line 3
private LocalDate dateofBirth:
//Line 4
private String courseName;
//getters and setters

Which Bean Validation APl annotations can be placed at Line1,Line2,Line3 and Line4
in the above class so that following contrains are met?
1. studentld should be a 5-digit number
2. studentName can only contain alphabets and spaces
3. dateOfBirth must be a past date
4. COurseName should not be null

a)Line 1: (@Min(value = 10000) (OMax (value = 99999)


Line 2: aPattern(regexp = "[a-zA-Z ]+")
Line 3: @Past
Line 4: @NotNull

b)Line 1: Min(value
Line 2: @Pattern(regexp =[a-zA-Z]+")
Line 3: @Past
Line 4: @NotNull
c)Line 1: @Max(value = 99999)
Line 2: @Pattern(regexp ="[a-zZA-Z]+")
Line 3: @PastorPresent
Line 4: @NotNull

d)Line 1: (@Min(value = 10000)@Max(value = 99999)


Line 2: @Pattern(regexp = "[a-zA-Z]+")

Consider the following Spring beans:


package com. infy.bean;
@Component
public class Trainee {
private IntegertraineeId = 709641;
private string traineeName ="Dominic Root";
public Trainee(){
System.out.println("Trainee constructor called" ) ;
}

//getters and Setters


}
package com.infy.bean;
@component
public class Classroom {

private string classroomNo = "FL5" ;


private striug classr0omtame = "Alan Turing";
privale string building "B11";
public classroom() {
System.out .println("lassroom constructor called");
}
//getters and setters
}
Assumption:
1. All the necessary imports and configurations are done
What will be the output when the following code is executed?
package com.infy;
@springBootApplication,
public class Application implements CommandLineRunner {
@Autowired
private Trainee trainee;
@Autowired

public static void main(string[ ] args) {


SpringAppliation. run(Application.class, args);
}
@Override
public void run(String... args) throws EXception {
System.out.println("Trainee:"+trainee.gettraineeId() +" is allocated "
+classroom.getclassroomNo()+"classroom");
}
}

a)Trainee constructor called


Classroom constructor called
Trainee:709641 is allocated FL5 classroom

b)Classroom constructor called


Trainee constructor called
Trainee:709641 is allocated FL5 classroom

c)Trainee:709641 is allocated FL5 classrm


Trainee constructor called
Classroom constructor called

d)Trainee:709641 isallocated FL5 classroom


Classroom constructor called
Trainee constructor called

(@Entity
public class Product {
@Id
@Generatedvalue(strategy=GenerationType.IDENTITY)
private Integer productId;
private String productName;
//getters and setters
}
PRODUCT (product id is the primary key)
product id product name
2001 Laptop
2002 Refrigerator

What will be the value of productld generated, when a new row is inserted in
PRODUCT table?
a) 2000
b) 1
c) 0001
d) 2003

Consider the following entity classes and corresponding tables:


@Entity
public class Trainee {
@Id
private Integer trainee Id;
@Entity
private String name
private String phoneNumber
private LocalDate dateofJoining;
//getters and setters
}

@Entity
public class Stream{

private Integer streamId;


private Integer streamName;
private Integer setName;
//Line1
private ListTrainee> trainees:

//getters and setters


create table trainee (
trainee id int auto increment primary key,
name varchar (30),
phone_number varchar (10),
date_of_joining date,
stream id int references stream(stream id)
);
create table stream (
stream id int primary key,
stream name varchar(30),
);
Assumption:
1. All the necessary imports and configurations are done.

Which of the following annotations can be inserted at Line1 to establish one-to-


many
relationship between Stream and Trainee

ChooseAny Two Correct Options


a)@OneToMany(cascade CascadeType.ALL)
@JoinColumn(name ="stream_id")
b)@ManyToone(cascade = CascadeType.ALL)
@joinColumn(name ="stream id")
c)@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name="streamid")
d)@OneToMany(cascade = CascadeType.ALL)
@)oinColumn(name ="stream id", unique = true)

Consider the folowing LoanController class:


package com. infy.controller;
@Restcontroller
@RequestMapping(value-"/houseLoan")
public class LoanController{
@DeleteMapping(value = "/{loantIdy}")
public ResponseEntitysString> deleteloanDetails(@PathVariable Integer loanId)
throws Exception
//restof the code
return new ResponseEntity<string>("Loan deleted successfully" , Httpstatus.oK);
}
}

Assumptions:
1. All necessary imports and configurations are done
2. Application is running on port 8080
3. LoanDTO 0s a Java bean class

What will be the output when the following code is executed?


LoanDTO l0anDTO = new LoanDTO();
loanDTO. setLoanId(1001)
string url = "http://localhost:8080/houseLoan/{loanId}";
RestTemplate restTemplate - new RestTemplate();
restTemplate. put (url, loanDTo, loanDTO.getLoantd());

Options are:
a)Loan deleted successfully for: 1001
b)null
c)legalStateException will be thrown
d)Loan deleted successfuly for : null

Give Correct option

Consider the following DTO class:


public class StudentDTO {
}
private Integer studentId;
private string studentName;
//parameterized constructor
//getters, setters, tostring method
Assumptions:
1. All necessary imports and configurations are done
2. 8765 is the port number used
What should be inserted at line 1 in below code to delete
the record of a student on the basis of studentid?

string url = "http://localhost:8765/student sl{studentId}";


RestTemplate restTemplate = new RestTemplate();
1/line 1

a)restTemplate.deleteForobject(url, studentDTO.class, studentId);


b)restTemplate.delete(url, StudentDTO.class, studentId );
c)restTemplate.delete(url, student Id);
d)restTemplate.deleteForobject(url, studentId);

import java.util.ArrayList;
import java.util.List;

public class Tester1 {


public static void main(String[] args) {
List<Customer> list = new ArrayList<Customer>();
Customer cust1 = new Customer("John");
Customer cust2 = new Customer("Joe");
Customer cust3 = new Customer("Sam");
list.add(cust1);
list.add(cust2);
list.add(cust3);

System.out.print("Before: " + list);

for (int j = 0; j < list.size(); j++) {


Customer e = list.get(j);
if (e.getCustName().equals(cust1.getCustName()))
list.remove(j+1);
}
System.out.println(" After: " + list);
}
}

Options Are
O Before: john, Joe, Sam] After: [john, Sam]
O Before: (john, Joe] After: [john]
O Before: (John, Sam] After: [Sam]
O Before: john, Sam] After: [Joe]
Give the correct option

What will be the output of the following code snippet?

public class Tester {

Map map = new TreeMap();


map.put("Spring", 1Ø);
map.put("Java", 20);
map.put("spring", 20);
public static void main(string[] args){
map.put("Java", 50);
02 : 58 : 16 HourS Minutes Seconds
System.out .println (map);
}
}
Options Are
O {Java=50, spring=20}
O {spring=10, Java=50, spring=20
O {Java=50, Spring=10, spring=20}
O {Java=20, spring=10, spring=20}
Give the correct option

You might also like