Professional Documents
Culture Documents
@Entity
public class Product {
private string productId;
private String productName;
private String category;
private Double price;
//getters and setters
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
// 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)
a)1andrew@infy.comnull
b)1andrew@infy.comAndy
c) nullnullnult
d) NulIPointerException will be thrown
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
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"
@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);
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
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
(@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
@Entity
public class Stream{
Assumptions:
1. All necessary imports and configurations are done
2. Application is running on port 8080
3. LoanDTO 0s a Java bean class
Options are:
a)Loan deleted successfully for: 1001
b)null
c)legalStateException will be thrown
d)Loan deleted successfuly for : null
import java.util.ArrayList;
import java.util.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