wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Java Programming Quiz

Total questions: 50

Worksheet time: 50mins

Name
Class
Date
1.

Which of the following ensures memory safety and prevents pointer manipulation in Java?

a)

Garbage Collection

b)

JVM Loader

c)

Preprocessor

d)

Bytecode Compiler

2.

Which statement is TRUE about Java’s platform independence?

a)

Java compiler generates native machine code

b)

Java programs depend on OS

c)

Bytecode is executed by JVM on any platform

d)

Java is interpreted line by line

3.

Which of the following identifiers is invalid in Java?

a)

$student

b)

_count

c)

class

d)

totalValue

4.

Which naming convention follows Java standards for variables?

a)

EmployeeName

b)

employee_name

c)

employeeName

d)

Employee_name

5.

What will be the output of System.out.println(10/3);?

a)

3.3333

b)

3

c)

3.0

d)

Compile Error

6.

Which primitive type takes the least memory?

a)

byte

b)

short

c)

int

d)

char

7.

Which of these is a valid floating literal in Java?

a)

3.14f

b)

3,14

c)

.14d

d)

14.

8.

What does the literal 0b1010 represent?

a)

Octal

b)

Binary

c)

Decimal

d)

Hexadecimal

9.

What will x = 5; System.out.println(x++ + ++x); print?

a)

10

b)

12

c)

11

d)

13

10.

Which operator has the highest precedence?

a)

&&

b)

*

c)

==

d)

+

11.

How many elements does new int[5] create?

a)

4

b)

5

c)

6

d)

Undefined

12.

What is the result of accessing an array out of bounds?

a)

0

b)

null

c)

ArrayIndexOutOfBoundsException

d)

Runtime reset

13.

What is printed by: String s1 = "Java"; String s2 = new String("Java"); System.out.println(s1 == s2);

a)

true

b)

false

c)

null

d)

Compile Error

14.

Which method converts all characters in a string to uppercase?

a)

toUpper()

b)

upperCase()

c)

toUpperCase()

d)

setUpperCase()

15.

Which class provides thread-safe operations?

a)

String

b)

StringBuffer

c)

StringBuilder

d)

CharSequence

16.

Output of:

StringBuilder sb = new StringBuilder("Hi");

sb.append("Java");

System.out.println(sb);

a)

Hi

b)

Java

c)

HiJava

d)

Compile Error

17.

Which of the following can be overloaded but not overridden?

a)

Methods

b)

Constructors

c)

Variables

d)

Interfaces

18.

If no constructor is defined in a class:

a)

Compiler throws an error

b)

Compiler provides a default constructor

c)

Object cannot be created

d)

JVM crashes

19.

Which of the following can a constructor call using this()?

a)

Another constructor in the same class

b)

Static method

c)

Parent constructor directly

d)

Instance variable

20.

Constructors cannot be:

a)

Private

b)

Final

c)

Overloaded

d)

Parameterized

21.

Which of these can be overloaded in Java?

a)

Methods only

b)

Constructors only

c)

Both methods and operators

d)

Only static methods

22.

Which keyword allows one method to call another of the same class?

a)

super

b)

this

c)

return

d)

call

23.

If class B extends class A, which executes first during object creation?

a)

Constructor of A

b)

Constructor of B

c)

Static block of B

d)

None

24.

Which keyword calls the parent class constructor explicitly?

a)

super()

b)

parent()

c)

base()

d)

this()

25.

Method overriding is an example of:

a)

Compile-time polymorphism

b)

Runtime polymorphism

c)

Static binding

d)

Overloading

26.

Which keyword prevents a method from being overridden?

a)

static

b)

final

c)

const

d)

abstract

27.

An interface method without a default implementation is implicitly:

a)

public and abstract

b)

private

c)

static

d)

final

28.

Which is true about abstract classes?

a)

Can be instantiated

b)

Must have all abstract methods

c)

Can have both abstract and concrete methods

d)

Must extend an interface

29.

Which of the following handles both checked and unchecked exceptions?

a)

try-catch

b)

throws

c)

finally

d)

throw

30.

Which statement rethrows an exception?

a)

throw e;

b)

throws e;

c)

catch(e);

d)

raise e;

31.

Which method is used to execute a SELECT query?

a)

execute()

b)

executeQuery()

c)

executeUpdate()

d)

executeBatch()

32.

Which JDBC class maintains a connection to the database?

a)

Statement

b)

ResultSet

c)

Connection

d)

DriverManager

33.

Which class is best for reading text line by line?

a)

FileReader

b)

BufferedReader

c)

Scanner

d)

DataInputStream

34.

Which exception must be handled when working with IO streams?

a)

IOException

b)

NullPointerException

c)

ArrayIndexOutOfBoundsException

d)

SQLException

35.

The service() method in a servlet:

a)

Is called once during initialization

b)

Is called for every request

c)

Is called after destroy()

d)

Cannot be overridden

36.

Which method destroys a servlet instance?

a)

destroy()

b)

finalize()

c)

exit()

d)

end()

37.

Which JSP directive defines global page settings?

a)
b)
c)

jsp:forward

d)

jsp:param

38.

What is the default scripting language in JSP?

a)

Java

b)

Python

c)

JavaScript

d)

Groovy

39.

Which annotation marks a Spring Boot application entry point?

a)

@SpringBootApplication

b)

@EnableAutoConfiguration

c)

@Configuration

d)

@SpringBootMain

40.

Spring Boot auto-configuration is triggered by which annotation?

a)

@AutoConfig

b)

@EnableAutoConfiguration

c)

@ConfigClass

d)

@SpringComponent

41.

Which design principle does Dependency Injection support?

a)

Loose coupling

b)

Tight coupling

c)

Hard dependency

d)

Strong cohesion

42.

Which annotation is used for field injection?

a)

@Autowired

b)

@Qualifier

c)

@InjectBean

d)

@Component

43.

Which annotation marks an entity class?

a)

@Entity

b)

@Table

c)

@Repository

d)

@Persistence

44.

Which method in JpaRepository retrieves all records?

a)

findOne()

b)

findAll()

c)

getAll()

d)

list()

45.

Which interface defines user-specific data for authentication?

a)

UserDetails

b)

SecurityConfig

c)

AuthProvider

d)

RoleManager

46.

What is the default login URL in Spring Security?

a)

/signin

b)

/login

c)

/auth

d)

/userlogin

47.

Which annotation binds URL path variables to method parameters?

a)

@PathVariable

b)

@RequestParam

c)

@ModelAttribute

d)

@RequestBody

48.

DispatcherServlet acts as:

a)

View component

b)

Front Controller

c)

Service layer

d)

DAO layer

49.

Which annotation maps HTTP GET requests to a method?

a)

@GetMapping

b)

@PostMapping

c)

@PutMapping

d)

@RequestParam

50.

To send JSON response, a method should return:

a)

String

b)

ResponseEntity

c)

HttpRequest

d)

ModelAndView