0% found this document useful (0 votes)
102 views14 pages

Sodapdf

This document provides multiple choice questions (MCQs) related to Java programming concepts. Some key points: - Questions cover topics like OOPs concepts, exceptions, collections, JDBC, Hibernate, Spring framework etc. - Each question is followed by answer options and the correct answer. - Questions have varying difficulty levels. The document acts as a practice/study resource for Java programming concepts by providing MCQs and answers on different topics.

Uploaded by

Saicharan Reddy
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)
102 views14 pages

Sodapdf

This document provides multiple choice questions (MCQs) related to Java programming concepts. Some key points: - Questions cover topics like OOPs concepts, exceptions, collections, JDBC, Hibernate, Spring framework etc. - Each question is followed by answer options and the correct answer. - Questions have varying difficulty levels. The document acts as a practice/study resource for Java programming concepts by providing MCQs and answers on different topics.

Uploaded by

Saicharan Reddy
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/ 14

mcqs:-

24)How would you make your own checked exception?

By extending Exception class

By extending Error class

By extending RuntimeException class

One cannot create a checked exception

ans -1

20)Which of the following statements about method overcading is faise?

Method overloading depends on the number of parameters

Method overloading depends on the data types of parameters

Method overloading depends on the return type of method

Method overloading depends on the name of the method

ans- 3

15)Consider the following JDBC code snippet and identify the threat that it projects
1 Statement s c.createStatement();
2 String str="select * from student WHERE id=";
3//input the id from user
4 ResultSet rs-s.executeQuery(str+String.valueOf(input));

options:-

a)Security misconfiguration

b)Insecure direct object references

c)OSOL injection

d)Cross site scripting

ans - b

13)As per the concepts of Java Spring, which of the following can be used to load a standalone applicatio
n in Spring?

Note:- There can be more than or correct answer.

a)FileSystemXmlApplicationContext.

b)ClassPathXmiApplicationContext

c)GenericXmlApplicationContext
d)ResourceApplicationContext

e)SimpleBeanFactory

ans - a,b,c

11)What will be the output of the following code snippet?

public class Test


{
public static void main(String args[])
{
String x = new String("test");

String y = "test";

System.out.println(x==y);

System.out.println(x.equals(y));
}
}

a)True
False

b)True

c)False
True

d)False
False

ans - c

7)Which line in the following source code has an error?

class abc{

public static void main(String args[]) { // Line 1

int a, b;

for (a=1, b=4; a<b; a++, b--){ // Line 2

System.out.println("a="+ a);

System.out.println("b="+ b); // Line 3


}
}
}

ans - line 1.

6)In which of the following classes, elements can be retrieved using their index?
ArrayList class

LinkedList class

HashSet class

TreeSet class

ans - ArrayList class,LinkedList class.

3)Which of the following are properties of HashMap in Java?

A) Elements are inserted into a list in order of insertion

B) Keys cannot be duplicated but duplicate values can be there

C) Values cannot be duplicated but duplicate keys can be there

1)A and C

2)A, B and C

3)A and B

4)B and C

ans - may be A

4)How does garbage collection take place in Java?

Automatically

Manually

Does not occur

None of the given options

ans - Automatically

1)Which of the following options are properties of ArrayList in Java?

A) Elements are inserted into a list in order of insertion

B) Elements are randomly inserted

C) Elements are sorted before inserting

D) Duplicate elements are removed before insertion


ans - only A

12)How many types of injection methods are there in Spring?

one

Two

Three

None

ans - two

13)Consider a table named SCHOOL In the Oracle database with the following data:

1 Student_id Student_name marks


2 101 John Smith 79

3 102 Smith 52

4 103 Mark 35

5 104 Harry 83

There is a persistent class named Student.java with following properties

public class Student implements Serializable {


private static final long serialVersionUID = 1L;
private int sid;
private String sname;
private double smarks;
//getters and setters methods
}

This class is mapped with the School table in the Configuration file.

What will be the output when the client application runs the following HQL query using the Session object
s?

String q="select from Student";

Query query=s.createQuery(q);

List 1-query.list();

Iterator 1-1.iterator();

while(1.hasNext()) {

System.out.println(i.next());
}

ans - option A (4 entries)

14)import java.util.stream. IntStream;

import java.util.*;
public class JavaEleven {

public static void main(String[] args) {

try{

IntStream input = IntStream.rangeClosed (-2, 2);

System.out.println("3"); input.forEach(System.out::println);

System.out.println("-3");

}catch(Exception exception) { System.out.println(exception);

ans -
3
-2
-1
0
1
2
-3

17)What will be the output of the following code snippet?

for (int i = 0; i <= 10; i++) {


if (i > 6) break;

System.out.println(1);

ans - Compilation Error

15)Which of the following modifiers are allowed for methods in an interface?

A. Public

B. Final

C. Static
D. Abstract

ans - A,C,D

19)What is the initial capacity of an empty StringBuffer object?

ans - 16

22)Which of the following statements about bean naming is false in Java Spring?

a) A bean may be defined without an id or a name.

b) It is possible for a bean to have multiple names.

c) The following declarations are legal.

1 <bean id="/myBean" class- foo.Bar" />

2 OR

3 <bean name="/myBean" class="foo Bar" />

d) A bean may be given multiple names via the alias-tag

ans - c

7)Which of the following data types is a 16-bit signed two’s complement integer?

a)Int

b)Byte

c)Short

d)Float

ans - c

28)Which of the given statements about the following methods in a class is true?

public class Mettl {

public static void check(){


System.out.print("1");
}

public static int check(){


return 1:
}
public static void main(String args[]) {
check():
}
}
Choose the best option

a)The two methods are overloaded.

b)The two methods are overidden.

c)The two methods are neither overloaded nor overridden, and there with be a complete time error.

d)The two methods are neither overloaded nor overridden and the code will complie successfully.

ans - c

30)Which of the following would you use to instantiate a class in Java?

a)New operator
B)Class forName("name")

Choose the best option

Only A

Only B

Both A and B

None of the given options

ans - only A

26)Which of the following options is/are properties of TreeSet in Java?

A) Elements are inserted into a list in order of insertion

B) Elements are randomly inserted

C) Elements are sorted before inserting

D) Duplicate elements are removed before insertion

Only A

A and C

A and D

C and D

ans - c and d

25)class Parent {

public void helloWorld() {

System.out.println("Base: show() called");


}
}
class Child extends Parent {
public void helloWorld() {

System.out.println("Derived: :helloWorld() called");


}
}

a)Derived helloWorld() called

b)Base show() called

c)Runtime exception

d)Compile time exception

ans - a

19)What is the default format of LocalDate in Java 8?

yyyy-MM-dd

MM-dd-YY

Oyy-mm-dd

dd-mm-yyyy

ans - yyyy-MM-dd

18)Consider two Persistent class Employee and Department mapped with two tables in the

database

What type of join the following HQL statement indicates?

String q= "FROM Employee, Department";

options:-

inner join

left outer join

right outer join

cross join

ans - cross join

17)Which of the following data types is a 64-bit signed two’s complement integer?

Int
Long

Float

Byte

ans - Long

10)As per Java serviets concepts, which of the following methods will you use to send a response in the f
orm of character cata to the client

HttpServletRequest getWriter()

HttpServerResponse getCharacterWrmer)

HttpServetRequest getOutputStream()

HttpServletResponse getWriter)

ans- HttpServletResponse getWriter)

16)output of code?
class ExtendedString extends string{
public static void main(String []s){
ExtendedString esl = "hello", es2= "world";
System.out.println (est + es2);
}
}

hello world

Compiler error Wrong function declaration with java lang string

Compiler error ExtendedString cannot inherit from final java lang string

hello+ world

ans - Compiler error ExtendedString cannot inherit from final java lang string

9)Which of the following statements about java.io. Serializable interface is true?

Object from classes that use aggregation cannot be serialized.

An object serialized on one JVM can be successfully deserialized on a differe

The values in fields with the Volatile modifier will not survive serialization an de-serialization

None of the given options

ans - None of the given options

8)Which of the following is the correct parent used for creating spring-boot application with maven?
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>{spring-boot-version}</version>
</parent>

remember:-

.boot
spring-boot-starter-parent

5)How can you instantiate a bean in Java Programming Spring?

(Note There may be more than one correct answer)

By using the constructors.

By using a static factory method.

By using an instance factory method.

By using BeanFactory.

By using ApplicationContext.

ans-all

3)class q35{

public static void main(String as[]){

int i =2;

if(i==0){

break;

else{

System.out.println("Else");

}
}
}

ans - Else

4)if the onMessage method of a message-driven bean encounters an application exception in EJB, what
would be your next step?

A. The exception must be handled, if handled completely, should not be thrown


B. If not handled, then wrap and throw that exception
Only A

Only B

Both A and B

Neither A nor B

ans - only B

11)As per la serviete concepts, which of the following Interfaces provides access to the method, getRequ
estedSessionid()?

HttpSession

HttpServletRequest

HttpServletResponse

ServletContext

ans - HttpServletRequest

16)purpose of the following source code?

public void printDescription() {

System.out.println("\nBike is " + "in gear" + this.gear + "with a cadence of " + this.cadence + " and travelli
ng at a speed of" + this.speed + ". ");
}

Inheritance

Polymorphism

Constructor

Destructor

ans - constructor

18)Given below is a spring boot code using get mapping that annotates two methods to determine the na
me and number of a user.

What is the significance of the URL Path based on the mentioned code?

@GetMapping("/root/name")
public String name()
{
return "abc";
}
@GetMapping("/(no)")
public String getNo (@PathVariable String no)
{
return "fetching userno";

options:-

a)each annotation of @getmapping will specify different path of URL

b)each annotation of @getmapping will specify same path of URL

c)each annotation of @getmapping will specify default path of URL

d)each annotation of @getmapping will specify root path of URL and then differ to different paths

ans - a

6)What is/are the purpose(s) of the following Java code?

int[] anArray {

100, 200, 300,

400, 500, 600,

700, 800, 988, 1000

};

It is the syntax to create an array

It is the syntax to initialize an array

Both of the given options

None of the given options

ans - It is the syntax to initialize an array

9)Which of the following methods would you use to make function calls in Java?

Choose the best option

Call by value

Call by reference

Call by value, as well as by reference

Neither by value nor by reference


ans- Call by value

10)What will be the output of the following code?

public interface JavaInterface


{
int count;

Rumtime error

Compile time error

Run without any runtime error

Compile successfully

ans - Compile time error.

2)
ans -

MIKE
SMITH

30)Which of the following options cannot directly cause a thread to stop executing in Java?

Calling the SetPriority() method on a thread object

Calling the wait() method on an object

Calling notify() method on an object

Calling read() method on an InputStream object

ans - Calling read() method on an InputStream object

29)Which class is the root(apex) of the entire exception handling class hierarchy?

Throwable class

Exception class

Error class

RuntimeException class

ans - Throwable class

25)You have a requirement for a collection that allows to search for values using keys (Le like a dictionary
) and also want this collection to maintain insertion order. Which of the following options will you use?
HashMap

LinkedHashMap

TreeMap

SortedMap

ans - LinkedHashMap

23)Which of the following would you use to instantiate a class in Java?

A. New operator

B. Class.forName("name")

Only A

Only B

Both A and B

None of the given options

ans - Only A

21)Which of the following commands complies a Java program in which the class is defined as "Hello"?

Compile javac Hello.java

Compile Hello.java

Javac Hello.java

Javac CLASS Hello.java

ans - Javac Hello.java

You might also like