wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Dependency Injection and JPA Entities Worksheet

Total questions: 122

Worksheet time: 1hrs 1mins

Name
Class
Date
1.

Two beans match an injection point. Result?

a)

List injected

b)

NoUniqueBeanDefinitionException

c)

Null

d)

First one injected

2.

Why prefer Constructor Injection for required deps?

a)

Immutability and ensures object is fully valid after construction

b)

Optionality

c)

Legacy

d)

Speed

3.

@ManyToOne default fetch?

a)

Lazy

b)

Eager

c)

Delayed

d)

Manual

4.

@OneToMany default fetch?

a)

Eager

b)

None

c)

Direct

d)

Lazy

5.

Detached entity means?

a)

Locked

b)

Deleted

c)

No longer tracked by EntityManager (Session closed)

d)

New

6.

Entity lifecycle state 'Managed' means?

a)

Deleted

b)

Saved to disk

c)

Attached to Persistence Context

d)

Garbage collected

7.

Exception when accessing lazy collection outside Transaction?

a)

Timeout

b)

NullPointer

c)

SQLException

d)

LazyInitializationException

8.

Field to be ignored by JPA?

a)

@Transient

b)

@Ignore

c)

@Skip

d)

@Temp

9.

IDENTITY ID generation relies on?

a)

Random

b)

Database features (Auto Increment)

c)

Java UUID

d)

Hibernate

10.

JOIN FETCH uses which loading strategy logically?

a)

Async

b)

Eager

c)

Lazy

d)

Delayed

11.

JPQL queries target?

a)

Files

b)

Tables and Columns

c)

XML

d)

Entities and Attributes

12.

Loading children one by one leads to?

a)

N+1 Select Problem

b)

Fast UI

c)

StackOverflow

d)

Deadlock

13.

MappedSuperclass allows?

a)

Table creation

b)

Polymorphic queries

c)

Interfaces

d)

Inheriting fields without a separate table

14.

Mapping Java objects to tables is called?

a)

SQL

b)

JPA

c)

ORM (Object Relational Mapping)

d)

JDBC

15.

Required annotation for JPA class?

a)

@Row

b)

@Model

c)

@Domain

d)

@Entity

16.

Storing Enums as text?

a)

@Text

b)

@Enum

c)

@Varchar

d)

@Enumerated(EnumType.STRING)

17.

Unique identifier definition?

a)

@Id

b)

@UUID

c)

@Primary

d)

@Key

18.

Updating managed entity fields requires?

a)

Calling save()

b)

Calling commit()

c)

Calling update()

d)

Nothing (Automatic Dirty Checking)

19.

Why not use Ordinal for Enums?

a)

Not supported

b)

Takes space

c)

Too slow

d)

Fragile if enum order changes

20.

Annotation for DELETE/UPDATE queries?

a)

@Modifying

b)

@Edit

c)

@Change

d)

@Write

21.

Execute raw SQL query?

a)

EntityManager

b)

RunSQL

c)

jdbcTemplate

d)

@Query(nativeQuery = true)

22.

Interface based projection?

a)

DTO class

b)

Object array

c)

Interface with getter methods matching columns

d)

Map

23.

Main benefit of Spring Data JPA?

a)

Better SQL

b)

Faster DB

c)

New language

d)

Reduction of boilerplate DAO code

24.

Marker interface for Repositories?

a)

Repository

b)

Dao

c)

Service

d)

Component

25.

Pagination interface?

a)

Slice

b)

List

c)

Set

d)

Pageable

26.

Preventing lost updates?

a)

Backups

b)

Optimistic Locking (@Version)

c)

Locking

d)

Pessimism

27.

Query keyword for inequality?

a)

Bad

b)

NotEqual

c)

Not

d)

Diff

28.

Return type when result might be missing?

a)

Void

b)

Null

c)

User

d)

Optional

29.

Slice vs Page?

a)

Slice is slower

b)

Slice doesn't count total (Cheaper), Page counts total

c)

Same

d)

Page is deprecated

30.

Sorting parameter?

a)

Change

b)

Order

c)

By

d)

Sort

31.

To write custom HQL/JPQL?

a)

@SQL

b)

@Custom

c)

@Query

d)

@Script

32.

Who implements the interface at runtime?

a)

Compiler

b)

Spring (via JDK Proxy)

c)

You

d)

Database

33.

countByLastName(String name) is example of?

a)

Derived Query Method

b)

Native SQL

c)

Error

d)

Magic

34.

count() returns?

a)

double

b)

int

c)

long

d)

boolean

35.

exists... methods return?

a)

Boolean

b)

String

c)

Int

d)

Long

36.

Binding user.first-name to user.firstName ?

a)

Error

b)

Relaxed Binding

c)

Impossible

d)

Manual

37.

Build once, run anywhere implies?

a)

Recompiling

b)

Magic

c)

Configuration is separated from Code

d)

Java is slow

38.

Conditional Bean creation?

a)

@Profile

b)

@Check

c)

@When

d)

@If

39.

Default profile name?

a)

dev

b)

main

c)

prod

d)

default

40.

Env variables are suitable for?

a)

Logs

b)

Secrets and Container-specific config

c)

Images

d)

Code

41.

Externalized configuration mantra?

a)

Hide it

b)

Store config in environment

c)

Email it

d)

Hardcode it

42.

Inject specific key?

a)

@Get

b)

@Key

c)

@Prop

d)

@Value

43.

Loading external property file?

a)

@Load

b)

@File

c)

@PropertySource

d)

@Import

44.

Order of precedence Highest?

a)

Command Line Arguments

b)

File

c)

Internal

d)

Env var

45.

Profile specific file naming?

a)

application-profile.properties

b)

application-{profile}.properties

c)

profile-application.properties

d)

application.properties

46.

Difficulty: MEDIUM. PropertySource refers to?

a)

A map of key-values (e.g. system properties)

b)

Real estate

c)

A bean

d)

Variables

47.

Difficulty: MEDIUM. Set server port to 9090?

a)

http=9090

b)

port=9090

c)

host=9090

d)

server.port=9090

48.

Difficulty: MEDIUM. Setting active profile property?

a)

spring.profiles.active

b)

profile

c)

active

d)

mode

49.

Difficulty: MEDIUM. Spring Cloud Config uses?

a)

Local disk

b)

Git (typically) to serve config

c)

FTP

d)

Dropbox

50.

Difficulty: MEDIUM. Standard config file format?

a)

C#

b)

Properties or YAML

c)

Main

d)

HTML

51.

Difficulty: MEDIUM. Type-safe simple configuration?

a)

@Value

b)

@Type

c)

@ConfigurationProperties

d)

@Bean

52.

Difficulty: HARD. YAML advantage?

a)

Encrypted

b)

Binary

c)

Flat

d)

Hierarchical structure

53.

Difficulty: MEDIUM. Calling @Transactional method from within same class?

a)

No proxy interception (Annotation ignored)

b)

Errors

c)

Works

d)

Explodes

54.

Difficulty: MEDIUM. Controller should ideally contain?

a)

Complex logic

b)

SQL

c)

HTML

d)

Only Routing and Validation logic

55.

Difficulty: MEDIUM. DTO is used to?

a)

Save data

b)

Transfer data between processes/layers

c)

Encrypt

d)

Connect DB

56.

Difficulty: EASY. Default rollback rule?

a)

IOExceptions

b)

RuntimeExceptions and Errors

c)

Any Exception

d)

None

57.

Difficulty: EASY. Dirty Read means seeing?

a)

Uncommitted data from another transaction

b)

Deleted data

58.

(MEDIUM) Do Checked Exceptions rollback automatically?

a)

Yes

b)

Always

c)

No

d)

On Sundays

59.

(MEDIUM) Force rollback for Exception?

a)

rollback=true

b)

stop()

c)

failed=true

d)

rollbackFor=Exception.class

60.

(MEDIUM) Highest isolation level?

a)

Read Committed

b)

Repeatable Read

c)

Serializable

d)

Read Uncommitted

61.

(EASY) Idempotent operation means?

a)

Safe to retry multiple times

b)

Random result

c)

Slow

d)

Changes every time

62.

(MEDIUM) Manual mapping leads to?

a)

Speed

b)

Promotion

c)

Fun

d)

Boilerplate and errors

63.

(MEDIUM) Method visibility for @Transactional?

a)

Package

b)

Public

c)

Private

d)

Protected

64.

(MEDIUM) Primary purpose of Transaction?

a)

Security

b)

Logging

c)

Speed

d)

Data Integrity (All or Nothing)

65.

(MEDIUM) REQUIRED propagation?

a)

News

b)

Reuses existing or creates new

c)

Ignores

d)

Fails

66.

(MEDIUM) REQUIRES_NEW behavior?

a)

Merges

b)

Suspends outer, runs independent inner

c)

Fails

d)

Nothing

67.

(MEDIUM) Rich Domain Model vs Anemic?

a)

Anemic has logic

b)

Rich contains business rules, Anemic is data-only

c)

Same

d)

Rich is empty

68.

(MEDIUM) Service layer encapsulates?

a)

Business Logic

b)

UI

c)

Networking

d)

SQL

69.

(MEDIUM) Stateless service allows?

a)

Sessions

b)

Memory usage

c)

Horizontal Scaling

d)

Complexity

70.

@JsonProperty used for?

a)

Database map

b)

Null check

c)

Mapping JSON key name (e.g. 'first_name' → firstName)

d)

Hiding field

71.

Binding body to DTO requires?

a)

@Header

b)

@RequestBody

c)

@Path

d)

@Param

72.

Centralized Error Logic?

a)

Main method

b)

@ControllerAdvice

c)

Each method

d)

Filter

73.

Customizing Headers in response?

a)

Return ResponseEntity

b)

Return String

c)

Return Map

d)

Return void

74.

HTTP 200 OK vs 204 No Content?

a)

200 is fast

b)

204 is verification

c)

204 is error

d)

200 has body, 204 has no body (success for delete/void)

75.

HTTP 404 means?

a)

Not Found

b)

Unauthorized

c)

Bad Request

d)

Server Error

76.

Jackson's role?

a)

Validation

b)

Security

c)

Logging

d)

JSON Serialization/Deserialization

77.

Method for updating resource partially?

a)

PATCH

b)

PUT

c)

POST

d)

GET

78.

REST is independent of?

a)

URI

b)

HTTP

c)

Platform/Language

d)

Resources

79.

Reading '/items/5'?

a)

@Body

b)

@Get

c)

@Query

d)

@PathVariable("id")

80.

Reading '?sort=asc'?

a)

@Header

b)

@RequestParam

c)

@Path

d)

@Body

81.

Returning objects from controller is automatically converted to?

a)

JSON (if Jackson on classpath)

b)

XML

c)

Binary

d)

String

82.

Richardson Maturity Model Level 3?

a)

HATEOAS (Hypermedia)

b)

Tunneling

c)

Verbs

d)

XML

83.

Safe methods (don't modify state) include?

a)

GET and HEAD

b)

DELETE

c)

PUT

d)

POST

84.

What does being 'Stateless' mean in REST?

a)

Server does not store client context between requests

b)

Server is down

c)

No Memory

d)

No DB

85.

Building a URL?

a)

~{...}

b)

@{/path}

c)

# {...}

d)

${...}

86.

Can you open Thymeleaf file in Chrome directly?

a)

No

b)

Yes (Nature Templating)

c)

Only if compiled

d)

Only in IE

87.

Conditional display?

a)

th:display

b)

th:if

c)

th:hide

d)

th:show

88.

Decorator pattern in Thymeleaf?

a)

Via JS

b)

Layout Dialect

c)

Impossible

d)

Via CSS

89.

Default suffix for templates?

a)

.txt

b)

.html

c)

.jsp

d)

.th

90.

Expression [[...]] is?

a)

Comments

b)

Hidden

c)

Arrays

d)

Inlining (output text directly)

91.

Form binding object?

a)

th:form

b)

th:bind

c)

th:data

d)

th:object

92.

Is Thymeleaf interpreted?

a)

Yes (mostly)

b)

No

c)

Only in dev

d)

It is binary

93.

Iterating a list?

a)

th:list

b)

th:loop

c)

th:repeat

d)

th:each

94.

Replacing text content only?

a)

th:text

b)

th:val

c)

th:html

d)

th:attr

95.

Reusing header/footer?

a)

th:fragment

b)

th:replace

c)

th:each

d)

th:text

96.

Selecting a variable?

a)

@{x}

b)

*{x}

c)

#{x}

d)

${x}

97.

Sending data to View?

a)

Request.set

b)

Globals

c)

Model.addAttribute()

d)

Cookies

98.

Server-Side Rendering (SSR) sends what to browser?

a)

XML

b)

JSON only

c)

Fully rendered HTML

d)

Java code

99.

Thymeleaf works as?

a)

Compiler

b)

Database

c)

Server-side template engine

d)

Client framework

100.

Accessing current user in code?

a)

SecurityContextHolder.getContext()

b)

System.in

c)

Session.get

d)

Thread.current

101.

Allowing cross-domain AJAX?

a)

CORS (Cross Origin Resource Sharing)

b)

Firewall

c)

Proxy

d)

VPN

102.

AntMatchers are used for?

a)

Insects

b)

Regex

c)

Beans

d)

URL path matching config

103.

Authorization check for role 'ADMIN'?

a)

isUser()

b)

checkAdmin()

c)

hasRole('ADMIN')

d)

allow()

104.

Default behavior for unauthenticated request?

a)

500

b)

Allow

c)

404

d)

Redirect to Login / 401

105.

Filter order matters?

a)

Yes, strictly ordered chain

b)

Random

c)

Sometimes

d)

No

106.

FormLogin configures?

a)

Username/Password form auth

b)

OAuth

c)

Basic Auth

d)

LDAP

107.

Method level protection annotation?

a)

@Lock

b)

@Secure

c)

@PreAuthorize

d)

@Guard

108.

Preventing form forgery?

a)

XSS

b)

SQLi

c)

CSRF Token

d)

CORS

109.

Service to load user by username?

a)

UserService

b)

LoginService

c)

AuthService

d)

UserDetailsService

110.

Spring Security is implemented via?

a)

Servlet Filters (FilterChain)

b)

Agents

c)

Reflect

d)

AOP

111.

Storage for user details?

a)

String

b)

UserDetails (Interface)

c)

List

d)

Map

112.

Storing passwords safely?

a)

MD5

b)

Cleartext

c)

Adaptive Hashing (BCrypt/SCrypt)

d)

Rot13

113.

Who is the 'Principal'?

a)

Database

b)

Admin

c)

Currently logged in user

d)

Server

114.

@Email matches?

a)

IP address

b)

Domains

c)

Nothing

d)

Email format structure

115.

@Min(18) requires?

a)

String length 18

b)

Year 2018

c)

Number value >= 18

d)

Array size 18

116.

@Past validates?

a)

Timezone

b)

Date is in the past

c)

Numbers

d)

History

117.

Bean Validation standard is?

a)

JTA

b)

JDBC

c)

JSR-380 (Jakarta Validation)

d)

JPA

118.

Checking boolean is true?

a)

@True

b)

@Check

c)

@AssertTrue

d)

@Yes

119.

Checking if String has text?

a)

@HasChars

b)

@Text

c)

@NotNull

d)

@NotBlank

120.

Creating custom constraint?

a)

New Method

b)

New Interface

c)

Annotation + ConstraintValidator implementation

d)

New Class

121.

Groups allow?

a)

Batching

b)

Context-specific validation checks

c)

Sorting

d)

Teams

122.

Message interpolation handles?

a)

Speed

b)

Routing

c)

User-friendly error messages (i18n)

d)

Math