Tech M - Sample Java QB For Trained Freshers
Tech M - Sample Java QB For Trained Freshers
Tech M - Sample Java QB For Trained Freshers
MCQ:
Topic: GIT, Version Control System
Description:
You have made few commits in last 2 weeks. You need to get a log of that. Which of the below
command will retrieve the log of 2 weeks?
Topic: Maven
Description:
In a Maven project, which lifecycle phase processes and deploys the package (if needed)
before running integration tests?
Option 1: Integration-test
Option 2: Process-resources
Problem Description 1:
JSP pages provide a means to create dynamic Web pages using HTML and the Java
programming language.
Option 2: False
Problem Description 2:
A JSP custom tag was implemented and a class was extended to override a method.
Option 1: getTag()
Option 3: makeTag()
Option 4: setTag()
Description
import java.util.stream.Stream;
class Test
{
public static void main(String[] args)
{
Stream<String> stream = Stream.of("A", "B","C","D");
System.out.println(stream.peek(System.out::print).findAny().orElse("NA"));
}
}
Option 1: ABCDNA
Option 2: ABCD
Option 3: NA
Description
Topic: JPA/Hibernate
Description
What @Entity association is implemented by the below code?
@Entity
public class Exam {
@Id
private int marks;
}
@Entity
public class Result{
@Id
private int marks;
@OneToOne
private result;
}
Topic: SpringBoot
Description
You need to implement authentication and authorization in your Spring MVC application. You
want to secure certain URLs and restrict access based on user roles.
Which features of Spring MVC would you use to fulfill these requirements?
Topic: CI/CD
Description
Which of the following is(are) typical benefit(s) of using containers compared to virtual
machines?
Option 1: Containers offer the ability to run microservice applications while VMs don't.
Option 4: Containers provide faster start-up time and are ideal for scaling up applications.
[Correct Answer]
Topic: Jenkins
Description
The administrator is responsible for upgrading Jenkins plugins, but network restrictions prevent
server IP access. Also, traditional methods of accessing the server are not helpful without a
direct route to initiate plugin upgrades.
What alternative method would you use to upgrade Jenkins plugins in this scenario?
Option 1: Change the IP address of Network and delete the log file to ensure that outbound
connections are allowed for plugin downloads.
Option 2: Inspect the Jenkins log files and investigate the network-related issues or server
misconfigurations. [Correct Answer]
Option 3: Disable the firewall software running on the server temporarily to eliminate potential
interference with plugin downloads.
Option 4: Manually download the plugin updates from the Jenkins website and upload them to
the server for installation, bypassing the download error.
Java Coding:
Description
Problem Statement
You are building an application that helps users organize their seasonal activities based on the
weather conditions. You want to use EnumSet to efficiently manage the activities for each
season.
-> Create a Season enum that includes various types of seasons SPRING, SUMMER,
AUTUMN (Fall), and WINTER.
->Create an Activity enum that includes various types of activities like HIKING, SWIMMING,
SKIING, PUMPKIN_CARVING
class SeasonalActivityOrganizer
->Create an EnumSet for each season to store the activities that are appropriate for that
season.
->getActivitiesForSeason(Season season):
● This method takes a Season enum value as input and returns a set of Activity enum
values that are suitable for the given season.
The default case in the switch statement should include appropriate error handling
for cases where an unknown or unsupported season value is provided.
("Unknown season: " + season)
● This method adds an Activity enum value to the set of activities appropriate for the
specified season and then returns the updated set of activities for that season("Unknown
season: " + season).
The default case in the switch statement should include appropriate error handling
for cases where an unknown or unsupported season value is provided("Unknown
season: " + season).
->removeActivityFromAllSeasons(Activity activity):
● This method removes an Activity enum value from the set of activities for all seasons if it
exists and then returns the updated set of all activities.
->getAllActivities():
● This method returns a set containing all the Activity enum values from all seasons.
Sample Input
SeasonalActivityOrganizer organizer = new SeasonalActivityOrganizer();
organizer.addActivityForSeason(Activity.HIKING, Season.SPRING);
organizer.addActivityForSeason(Activity.SWIMMING, Season.SUMMER);
organizer.addActivityForSeason(Activity.SKIING, Season.WINTER);
organizer.getAllActivities()
organizer.getActivitiesForSeason(Season.SPRING)
organizer.getActivitiesForSeason(Season.SUMMER)
organizer.getActivitiesForSeason(Season.WINTER)
organizer.removeActivityFromAllSeasons(Activity.HIKING);
organizer.getActivitiesForSeason(Season.SPRING)
Sample Output
[HIKING]
[SWIMMING]
[SKIING]
[]
NOTE:
● You can make suitable function calls and use the RUN CODE button to check your
main() method output.
Problem Description
JSP Pages
index.jsp:
Create a task creation form with the following fields:
success.jsp:
If the task creation is successful, display a success message: "Task Created Successfully".
error.jsp:
If there is an error during task creation (e.g., empty fields), display an error message: "Failed to
create task. Please fill in all the required fields."
Task.java:
Implement a Task class to represent task data with the following private fields:
● title
● description
● dueDate
● priority
CreateTaskServlet.java:
Note
Implement the JPQL statement to fetch the list of curtains whose price is greater than the given
price and the list of curtains whose brand is equal to the given brand name.
● src/main/java/com/example/curtainmodel/repository/CurtainRepository.java
The task is to write the JPQL statement in the CurtainRepository file under the repository
folder:
● Task 1: Create a function called "getIdByPrice" that returns a list of curtains with a price
greater than the given price. You need to use query annotation to execute the function
based on the GET query.
● Task 2: Create a " getIdByBrand " function that returns the list of curtains with a brand
equal to the given brand name. You need to use query annotation to execute the
function based on the GET query.
-----------------------------------------------------------------------------------------------------
You can use the MySQL shell to view the data and query the tables.
Implement REST APIs to streamline and automate the process of managing shipments for
businesses involved in shipping goods. The API should enable users to retrieve a particular
shipment information based on the specific trackNo and also delete the requested shipment
data based on the requested shipId.
Entity Details
"shipId": 1,
"trackNo": "TRK001",
You are provided with the implementation of the models required for all the APIs. Your task is to
implement a set of REST services that exposes the endpoints, retrieves a particular shipment
information based on the specific trackNo and delete the requested shipment data based on
the requested shipId:
| API Route | API Type | Success Response Code | Validation Error Code |
|-------------------------|----------|------------------------|------------------------|
Task 1:
GET request to /shipment/{trackNo}
● 200 (OK) - If Shipment with the specified trackNo found and returned.
● 404 (Not Found) - If Shipment with the specified trackNo not found.
Task 2:
Response Body: String object should give the response as "The requested shipId-3 got
deleted" for correct shipId and response
● 200 (OK) - Shipment Id, i.e., the shipId found and deleted.
● 404 (Not Found) - Shipment with the specified shipId not found.
Task 3:
ShipmentService
● Implement the GET method which should return a Shipment data based on trackNo.
● Implement the DELETE method which should delete a Shipment data based on shipId.
Complete the given project so that it passes all the test cases when running the provided unit
tests.
● src/main/java/com/example/shipment_model/controller/ShipmentController.java
● src/main/java/com/example/shipment_model/service/ShipmentService.java
The response code is 200 and the response body, when converted to JSON, is as follows:
"shipId": 2,
"trackNo": "TRK002",
"origin": "London",
"destination": "Paris",
"status": "Pending"
The response code is 200 and the response body should return a message as follows:
You can use the MySQL shell to view the data and query the tables.