0% found this document useful (0 votes)
58 views20 pages

Delivery Exam

The document contains questions related to coding concepts in Java, Spring, HTML, SQL and other technologies. It covers topics like exceptions, threads, data types, REST APIs, ORM, database queries and more.

Uploaded by

Prasad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views20 pages

Delivery Exam

The document contains questions related to coding concepts in Java, Spring, HTML, SQL and other technologies. It covers topics like exceptions, threads, data types, REST APIs, ORM, database queries and more.

Uploaded by

Prasad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Delivery Exam

1)Which exception class is bound to all the exceptions thrown in Spring applications?
Ans)ArrayIndexOutofBound

DataAccessException

NullPointerException

Springexception

2)What is the purpose of the spring boot actuator?

Ans)To provide production ready features such as monitoring and metrics

To provide a way to configure beans using annotations

To provide a way to run spring boot applications as a service

To provide a way to access the underlying database of a spring boot application

3)Which exception class is bound to all the exception thrown in spring applications ?

Ans)ArrayIndexOutofBound

DataAccessException

NullPointerException

SpringException

4)Which of the following is a correct interface?

Ans) Interface A { void print() [ ] }

Abstract interface A { print(); }

Abstract interface A { abstract void print(); { }}

Interface A { void print(); }

5)Does spring boot require XML Configuration to function?

Ans) TRUE

FALSE

6)Which of these method of thread class is used to suspend a thread for a period of time?

Ans) Sleep()

Terminate()
Suspend()

Stop()

7)A bean can have more than one name in spring boot using multiple attributes

Ans)TRUE
FALSE

8)Which of the annotation is not a spring boot annotation

Ans) @Controller

@RestController

@Service

@Data

9) Which of the following statement is correct regarding the difference between TRUNCATE,
DELETE and DROP Command

1 DELETE operation can be rolled back but TRUNCATE and DROP operations cannot be rolled
back.

II TRUNCATE and DROP operations can be rolled back but DELETE operations cannot be rolled
back.

III. DELETE is an example of DML, but TRUNCATE and DROP are examples of DDL.

IV. All are an example of DDL.

OPTIONS:

II and III

I and III

II and IV

None of the above

10)What is the default mode of auto wiring?

Ans)FALSE

byName

byType

None of the above


11)Which among the following is not valid spring core Framework annotation?

Ans) @PreDestory

@PostConstruct

@PropertySource

@ComponentSource

12) What is the output of the following Java.code?

Code:

class Hackjava {

public static void main(String args[]){

int i=1,s=0;

while (i < 6){

s=s+i;

i++; }

System.out.println(s);}}

Ans)

15

21

Syntax Error

13) In Stist web services, you are working on REST-based architecture. Which of the following

Statements:

1. The GET method is used to provide write-only access to a resource.

2. The POST method is used to create a new resource.

3. The DELETE method is used to remove a resource

4. The PUT method is used to update an existing resource or create a new resource.

Ans)1,2 and 3

2,3 and 4
1,2 and 4

1,3 and 4

14)In REST API web services, which of these methods is used to remove configuration on a
device in the following statement.

HTTP______[devices/[id]/configuration/[id]

Ans)POST

DELETE

OPTIONS

PUT

15) John is working on java. While working on an application, he wants to skip the current
iteration of a loop and move to the next body for the current iteration. Help him to find the
following can be used in the above mentioned context.

Ans)break

Exit

Continue

None of the above

16)import java.util.*;

class Hacker{

static int add(int a, int b) {

return a*b/a;

static int add(int a, int b,int c){

return a*b/c;

class Hackeroverload{

public static void main(String[] args){


System.out.println(Hacker.add(4,6));

System.out.println(Hacker.add(2,4,6));

Ans)6 1

17) class Printhack {

private String name;

public String getName() {

return this.name;

public void setName(String name) {

this.name = name; // Assign the parameter value to the instance variable

class Main {

public static void main(String[] args) {

Printhack d = new Printhack(); // Correct class name

d.setName("Hacker");

System.out.println(d.getName());

d.setName("earth");

System.out.println(d.getName());

Ans) Hacker

Earth

18) Which exception class is bound to all the exceptions thrown in Spring applications?

Ans) DataAccessException
19) class Hacker{ public static void main(String[] args){ try { int res = 5% 0;} catch
(ArithmeticException e) { System.out.println("ArithmeticException => " + e.getMessage());} finally
{ System.out.println("This is the final result"); }}}

Ans) ArithmeticException => / by zero

This is the final result

20) working on lava, While working on an application, he wants to skip the current monson of a
body for the current iteration. Help him to find which of the following can be used in the

Ans)continue

21) In Spring, which of the following methods is not supported by the Thread class? public void
run() public void start() public void exit() public final int getPriority()
Ans) public void exit()

22) Bob is working on MicroServices. While working on the above mentioned context
Statements:

1. It provides each kind of client with a specific AP

2. It decreases the errors at the same time. application he wants know about the benefits of
using an AM gatory Help how to fed whe

3. It increases the number of round trips between the client and the application.

4. It simplifies the client code.

Ans)1 2 4

23) Ben wants to use the ApplicationContext loC Container in one of his programs during
deveter

Ans) FileSystemXmlApplicationContext, ClassPathXmlApplicationContext,


WebXmlApplicationContext

24) In Spring, what are the types of advice?

Ans) before, after, after returning, after-throwing and around

25) Which among the following classes is considered as an entry point to an Spring Web MVC
project?

Ans) DispatcherServlet

26) import java.util.*;

import java.io.*;
public class Hackerearth {

public Hackerearth() {

System.out.println("HackerEarth");

static Hackerearth a = new Hackerearth();

public static void main(String args[]) {

Hackerearth b;

b = new Hackerearth();

Ans)HackerEarth

HackerEarth

27) What is Weaving in Spring AOP?

Ans) Weaving is the process of linking an aspect with other application types or objects to create
an advised object

28) import java.util.*;

import java.io.*;

public class Hacker {

public static void main(String[] args) {

char i = 'a'; // Corrected the variable name and assigned it a character value

switch (i) { // Moved the semicolon inside the switch statement

case 'a': // Corrected the case label to match the character value

System.out.println("I love coding");

break;

case 'b': // Added the case label for 'b'

System.out.println("I love hackerearth.");


break;

default:

System.out.println("I love coding on hackerearth");

Ans) I love coding

28) Ben decided to use the PUI method in his REST API web service. Which of the following is
the reavons touse app

Reasons: 1. It has no side effects on successively calls

2. It is a safe method to use

3. It either creates or updates the requested resource

Ans) 1 and 3 only

29) While working on a project using Java Hob made a class. Now her wishes to convert that
class into an entity.which among the following options is needed in order to convert It?

Options: 1. Add @Entity annotation

2. Add @id annotation

3. Add Javax.persistence." package

4. All of the above

30) Table: product p_code p_name Price 1 Paul 1015 2 John 15.99 3 Mary 15.50 4 Lisa 25.25 5 Anita
30.33 6 Tara 15.55 Which of these Sql queries must be used to round off the price to one decimal
place in the above product table?

Ans) SELECT p_code, p_name, ROUND(Price, 1) AS Price FROM product; chatgpt

SELECT p_code, p_name, ROUND(Price, 1) AS Rounded_Price

FROM product; bing

31) What is the name of the thread in output in the following Java program? class
multithreaded_programing { public static void main(String args[]) { Threadt Thread.currentThread();
System.out.println(t.isAlive()); } }

Ans) True
32) In an application, Ben has designed several endpoints but just for validation purposes, he
wants to know the methods aflowers for pr Following methods would he use to achieve this?
Ans)OPTIONS

33) Alice is working on a project on Java using J2EE While witing the code for the required
application.servlet

Ans ServletException

34) In HTML5, you are woning on mulheresa atributes You have repanted a met exmer that can
occur while configuring the request. If you are required to contigues of the following
configuration syntax must be used to perform this task?

Ans) AddType video/ogg.ogv

35) In HTML h. you are woning on Web Forms 20 Which of StatemenER 1 The for attribute is
used to determine the relationship between the result of the 2. The form attribute is used to
determine the form to which the output tog in reci 3. The name attribute is used to determine
the name of the output element

1 and 2

2 and 3 DOUBT

1 and 3

All of these

36) John is working on Java While working on an application, he wants to know about the differenc
of the following statements is/are correct about the above-mentioned context 1 at is used for
floating-point numbers, while double is used for integers 2 art is a 64-bit data type, while double is a
32-bit data type 33nt is a signed data type that can hold values from -2,147,483,648 to
2,147,483,647, while dou small numbers with decimal places 4 Int is a floating-point data type that
can hold very large and very small numbers with decima from 2,147,483,648 to 2,147,483,647

Ans)1
37)
CODING

MINIMUMCOST
1) create database minicost;
use minicost;
CREATE TABLE products (
product_id INT,
product_name VARCHAR(255),
cost INT,
category VARCHAR(255)
);
show tables;

INSERT INTO products (product_id, product_name, cost, category)


VALUES
(101, 'Apple iPhone 13', 1100, 'Electronics'),
(102, 'Adidas Running shoes', 80, 'Fashion'),
(103, 'Woodland Footwear', 100, 'Fashion'),
(104, 'Highlander White Hoodie', 45, 'Fashion'),
(105, 'Tortilla', 9, 'Food'),
(106, 'Nestle Cerelac Jumbo pack', 12, 'Food'),
(107, 'Levis Jeans', 16, 'Fashion'),
(108, 'Crocs Matte black flip-flops', 52, 'Fashion'),
(109, 'Yonex Mavis 350 Shuttle corks pack of', 12, 'Sports'),
(110, 'Hollister Shirt medium', 50, 'Fashion'),
(111, 'Apple iPhone 12', 1000, 'Electronics'),
(112, 'Apple iPhone 11', 980, 'Electronics'),
(113, 'SG Tennis ball pack of 5', 6, 'Sports');
select * from products;

SELECT product_name, cost AS product_cost, category AS product_category


FROM products p1
WHERE (category, cost) IN (
SELECT category, MIN(cost)
FROM products p2
GROUP BY category
)
ORDER BY cost ASC, product_name DESC;

code for minimum cost MYSQL

2)BANK
CREATE DATABASE bank_database;

-- Use the created database


USE bank_database;

-- Create the table


CREATE TABLE bank (
Info_Date DATE,
Customer_ID INT,
Transactions INT,
Amount INT
);

-- Insert data into the table


INSERT INTO bank (Info_Date, Customer_ID, Transactions, Amount)
VALUES
('2022-11-26', 1, 90, 100000),
('2022-10-31', 2, 12, 2000),
('2022-02-23', 3, 89, 10),
('2013-10-23', 4, 13, 900),
('2022-11-01', 5, 16, 1090),
('2017-07-03', 6, 87, 1405),
('2010-10-04', 7, 102, 10901),
('2015-10-07', 8, 20, 1200);

SELECT Customer_ID
FROM bank
WHERE MONTH(Info_Date) = 10
ORDER BY Customer_ID ASC;

code for BANK MYSQL CODE

3)CANDLES
package com.candles;
import java.util.Scanner;

public class CandleLighting {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long N = scanner.nextLong();
long K = scanner.nextLong();
System.out.println(maxCandles(N, K));
}

public static long maxCandles(long N, long K) {


long total = N;
long leftovers = N;

while (leftovers >= K) {


long newCandles = leftovers / K;
leftovers = leftovers % K + newCandles;
total += newCandles;
}

return total;
}
}
4)METHOD OVERRIDING
package com.overriding;

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

class Polygon {
protected List<Double> sides;

public Polygon(List<Double> sides) {


this.sides = sides;
}

public List<Double> getSides() {


return sides;
}

public double getArea() {


// Implementation of area calculation for a generic polygon
return 0.0;
}
}

class Rectangle extends Polygon {


private double side1;
private double side2;

public Rectangle(double side1, double side2) {


super(new ArrayList<>());
this.side1 = side1;
this.side2 = side2;
this.sides.add(side1);
this.sides.add(side2);
this.sides.add(side1);
this.sides.add(side2);
}

@Override
public double getArea() {
return side1 * side2;
}
}

class Square extends Polygon {


private double side;

public Square(double side) {


super(new ArrayList<>());
this.side = side;
this.sides.add(side);
this.sides.add(side);
this.sides.add(side);
this.sides.add(side);
}

@Override
public double getArea() {
return side * side;
}
}

public class OverRiding {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Input dimensions for rectangle

double length = scanner.nextDouble();

double width = scanner.nextDouble();


Rectangle rectangle = new Rectangle(length, width);
System.out.println("Rectangle Area: " + rectangle.getArea());

// Input side length for square


double sideLength = scanner.nextDouble();
Square square = new Square(sideLength);
System.out.println("Square Area: " + square.getArea());

scanner.close();
}
}
5)REMOVE WHITE SPACES
package com.RemoveSpaces;
import java.util.Scanner;

public class RemoveSpaces {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

String input = scanner.nextLine();


String output = removeSpaces(input);

System.out.println(output);
scanner.close();
}

public static String removeSpaces(String input) {


char[] chars = input.toCharArray();
StringBuilder result = new StringBuilder();

for (char c : chars) {


if (!Character.isWhitespace(c)) {
result.append(c);
}
}

return result.toString();
}
}
6)SECOND HEIGHEST
package com.secondhighest;

import java.util.Scanner;

public class SecondHighest {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

String input = scanner.nextLine();


String[] numbersStr = input.split(" ");
int[] numbers = new int[numbersStr.length];

for (int i = 0; i < numbersStr.length; i++) {


numbers[i] = Integer.parseInt(numbersStr[i]);
}

int highest = Integer.MIN_VALUE;


int secondHighest = Integer.MIN_VALUE;

for (int number : numbers) {


if (number > highest) {
secondHighest = highest;
highest = number;
} else if (number > secondHighest && number != highest) {
secondHighest = number;
}
}

System.out.println( secondHighest);
scanner.close();
}
}
7)TAXPAYMENT
package com.TaxPayment;

import java.util.*;

public class TaxPayment {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Input N (number of employees)


int N = scanner.nextInt();

// Input the employee details into a 2D array A


int[][] A = new int[N][2];
for (int i = 0; i < N; i++) {
A[i][0] = scanner.nextInt(); // Employee ID
A[i][1] = scanner.nextInt(); // Employee salary
}

// Input Q (number of queries)


int Q = scanner.nextInt();
// Input the queries into a list of lists
List<List<Integer>> queries = new ArrayList<>();
for (int i = 0; i < Q; i++) {
List<Integer> query = new ArrayList<>();
query.add(scanner.nextInt()); // l
query.add(scanner.nextInt()); // r
query.add(scanner.nextInt()); // x
queries.add(query);
}

// Calculate and print the output


List<Integer> result = taxPayment(N, A, queries);
for (int count : result) {
System.out.print(count + " ");
}

scanner.close();
}

public static List<Integer> taxPayment(int N, int[][] A, List<List<Integer>> queries) {


List<Integer> result = new ArrayList<>();
for (List<Integer> query : queries) {
int l = query.get(0);
int r = query.get(1);
int x = query.get(2);

int count = 0;
for (int i = l - 1; i < r; i++) {
if (A[i][1] > x) {
count++;
}
}
result.add(count);
}
return result;
}
}

You might also like