Backend Java Developer Interview: Questions and Where to Look for Answers. Part 2



I am publishing the continuation of the collection of interview questions and answers for Backend-Java-developer. In the first part, we walked through Java and Spring. And in this one we'll talk about Hibernate, databases, patterns and development practices, one popular library, support and maintenance of our applications, and also look at alternative cheat sheets and summarize.



TL; DR

A GitHub repository with a full cheat sheet is here , and Habr is still a cake.



Questions



Hibernate



28. What are the caches in Hibernate and which ones work by default?

3 levels of caching:



  • First-level cache. Enabled by default.
  • Second-level cache. Disabled by default.
  • (Query cache). .


:



  • Baeldung
  • First Level Cache Second Level Cache


Hibernate Vlad Mihalcea:



  • High-Performance Java Persistence: 2, 16 โ€” Caching
  • How does Hibernate Query Cache work
  • How does Hibernate Collection Cache work
  • How does Hibernate store second-level cache entries
  • How does Hibernate NONSTRICT_READ_WRITE CacheConcurrencyStrategy work
  • How does Hibernate TRANSACTIONAL CacheConcurrencyStrategy work
  • How does Hibernate READ_ONLY CacheConcurrencyStrategy work
  • How does Hibernate READ_WRITE CacheConcurrencyStrategy work


29. How does Lazy differ from Eager in Hibernate?
  • Eager Loading โ€” , . (@OneToOne, @ManyToOne, @OneToMany, @ManyToMany) fetch = FetchType.EAGER. @OneToOne @ManyToOne.
  • Lazy Loading โ€” , . , (@OneToOne, @ManyToOne, @OneToMany, @ManyToMany) fetch = FetchType.LAZY. @OneToMany, @ManyToMany. proxy-, . LAZY- Hibernate, LazyInitializationException.


"N+1" .



Vlad Mihalcea: , LazyInitializationException .



30. ' N+1 ' Hibernate? ? ? ?

N+1 Hibernate, .



N+1 , N , . N . slow query log, , .



plain sql (jdbc, JOOQ), ( ) . , . " !?". - , - . ? JOIN . .



Hibernate. "N+1", . .



, FetchType.EAGER. N+1. @ManyToOne . JPQL JOIN FETCH . , FetchType.LAZY.



FetchType.LAZY, , N+1. , . โ€” . JOIN FETCH .



JOIN FETCH , bonjour. @OneToMany FetchMode.SUBSELECT โ€” 2 , . .. .



โ€” . @BatchSize .



:



  • JPA EntityGraph
  • Hibernate FetchProfile


N+1, db-util Vlad Mihalcea. .



JOOQ N+1 , 17- (01:16:36) +. JOOQ.



:



  • Vlad Mihalcea:
  • Hibernate โ€”
  • DOU JPA Hibernate
  • JPoint " Hibernate "


31. Hibernate?

: โ€” , . .



Hibernate, @Embeddable. , Serializable equals hashcode.



, , @EmbeddedId.



Vlad Mihalcea Hibernate.



32. JPA (Hibernate)?

4 JPA (Hibernate):



  • MappedSuperclass โ€” . . @MappedSuperClass, @Entity. , , @AttributeOverride . . .
  • Single table โ€” . , -. @Entity- @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "YOUR_DISCRIMINATOR_COLUMN_NAME") ( DTYPE VARCHAR). @DiscriminatorValue("ThisChildName") , - . , @DiscriminatorFormula, CASE...WHEN โ€” JPA, Hibernate. . . โ€” NULL.
  • Joined table โ€” , . , ( ) . @Entity- @Inheritance(strategy = InheritanceType.JOINED). JOIN, CASE...WHEN, _clazz, (0 (), 1, 2 ..) Hibernate .
  • Table per class โ€” MappedSuperclass, . . JPA 2.2 ( 2.12) , Hibernate , . @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS). (@Id) . @AttributeOverride โ€” . UNION . , Hibernate _clazz , (1, 2 ..). NULL AS some_field. .


:



  • : ,
  • Vlad Mahalcea: MappedSuperclass


, JavaDoc :



  • JPA
  • Hibernate


JPA 2.2. pdf.





33. where having SQL?

Postgresql. Postgres Pro:



WHERE HAVING , WHERE , ( , ), HAVING . , WHERE ; . HAVING, , . ( , HAVING, , . WHERE.)

:



  • How does a relational database work
  • How does a relational database execute SQL statements and prepared statements
  • How Database Internally Works
  • Let's Build a Simple Database
  • Database internals


34. ACID -
  • A โ€” (Atomicity). , .
  • C โ€” (Consistency). .
  • I โ€” (Isolation). .
  • D โ€” (Durability). (, - ).


35. . ? ? ?

:



  • Read uncommitted ( ). (, ).
  • Read committed ( ). . ยซยป ( , , ).
  • Repeatable read ( ). (, ).
  • Serializable (). , , โ€” (, ).


:



  • MSSQL: , ,
  • PostgreSQL. Postgres Professional, egorov PostgreSQL (, , ..). Postgres Professional .
  • MySQL: ,


36. ? ?

โ€” , . . /. .



:



  • B-Tree
  • HASH-
  • Bitmap
  • Spatial grid
  • Quadtree
  • R-Tree
  • .


. .

, :



  • โ€” , . B-.
  • โ€” , . .

    :
  • โ€” . ID , ; ID ; ; . .
  • โ€” , . , .


:



  • Oracle, MySQL, PostgreSQL, MS SQL
  • PostgreSQL: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
  • ยซยป MySQL (InnoDB)
  • ยซ ยป Postgres
  • , , ?
  • :
  • : ,
  • Database Indexes Explained
  • Bitmap- B*tree-: ?
  • MySQL
  • PostgreSQL Java-
  • 14 SQL Server,
  • ,
  • PostgreSQL
  • Anatomy of an SQL Index
  • SQL Indexing and Tuning e-Book
  • Deep dive into Hash indexes for In-Memory OLTP tables
  • Indexing based on Hashing
  • SQL Server Indexes Interview Questions and Answers
  • Top 25 SQL interview questions and answers about indexes
  • An in-depth look at Database Indexin


37. ?

(lock) โ€” .



โ€” , . , . . , , .

:



  • shared (read) โ€” , . , , .
  • exclusive (write) โ€” , . . , .


โ€” , ( VERSION 0). , , . โ€” (, ) , .



, , . , .



Vlad Mihalcea:



  • A beginnerโ€™s guide to Java Persistence locking
  • A beginnerโ€™s guide to database locking and the lost update phenomena
  • How do LockModeType.PESSIMISTIC_READ and LockModeType.PESSIMISTIC_WRITE work in JPA and Hibernate
  • How does LockModeType.PESSIMISTIC_FORCE_INCREMENT work in JPA and Hibernate
  • How does LockModeType.OPTIMISTIC work in JPA and Hibernate
  • How does LockModeType.OPTIMISTIC_FORCE_INCREMENT work in JPA and Hibernate
  • How to prevent OptimisticLockException with Hibernate versionless optimistic locking
  • How does database pessimistic locking interact with INSERT, UPDATE, and DELETE SQL statements
  • How does MVCC (Multi-Version Concurrency Control) work
  • How does the 2PL (Two-Phase Locking) algorithm work
  • How to prevent lost updates in long conversations


:



  • .
  • Version JPA
  • Hibernate โ€“ V.
  • PostgreSQL: 1.
  • PostgreSQL: 2.
  • PostgreSQL: 3.
  • PostgreSQL: 4.


:



  • Pessimistic Locking in JPA
  • Optimistic Locking in JPA
  • Enabling Transaction Locks in Spring Data JPA
  • Deadlock
  • Enum LockModeType
  • Postgresql
  • PostgreSQL Concurrency with MVCC
  • Locking Hibernate
  • Optimistic locking JOOQ
  • Optimistically Locking Your Spring Boot Web Services
  • Optimistic and pessimistic locking with SQL


, ,



38. SOLID

, . . , . , , , .



  • S โ€” (The Single Responsibility Principle). .
  • O โ€” / (The Open Closed Principle). , .
  • L โ€” (The Liskov Substitution Principle). . , .
  • I โ€” (The Interface Segregation Principle). , .
  • D โ€” (The Dependency Inversion Principle). , .


, , " " , . ? 3 " ". , , . , :)



, -. , . SOLID - . - SOLID .



, , , . Baeldung.



39. . ? ? ( )? -? , ?

GoF. , , โ€” refactoring.guru. , (, , , ), , . . - .



40. coupling cohesion? ( ) () / ()?

Coupling () โ€” . .



Cohesion () โ€” . .



.



. , :



  • : . , .


coupling cohesion GRASP. : .



41. ?

(scale cube, The Art of Scalability) : sharding, mirrorring microservices.



  • Sharding (data partioning) โ€” .
  • Mirroring (horizontal duplication) โ€” .
  • Microservices โ€” , -.


:





:



  • .
  • microservices.io.
  • wiki pros cons.
  • SCALING APPLICATIONS: THE SCALE CUBE.
  • .
  • .
  • Microservice Patterns and Best Practices Microservices Patterns ( ).


42. ?

-, . . - "".



โ€” Microservice Patterns and Best Practices. Medium .



microservices.io : . โ€” . .



. โ€” Enterprise Integration Patterns .



43. CAP-. MongoDB () CAP-?

CAP โ€” , , :



  • Consistency () โ€” โ€” . โ€” - , , .
  • Availability () โ€” , .
  • Partition tolerance ( ) โ€” , ( ) - ( ).


MongoDB, (), โ€” CP, โ€ฆ , . .



.



:



  • : , , , ,
  • Visual Guide to NoSQL Systems CAP
  • The CAP FAQ
  • bigdataschool
  • MongoDB stackoverflow
  • CAP Theorem IBM
  • CAP Theorem and Distributed Database Management Systems
  • What is the CAP Theorem? medium


44. ?

- (SOA) โ€” , , . SOA โ€” , . SOA - .

:



  • - ( , -, , ..);
  • ;
  • " " .

    -

    (MSA) โ€” SOA, , , (). MSA , , .

    :
  • (Unix way โ€” );
  • ;
  • ( );
  • " " .


, MSA , SOA โ€” . . โ€” , . MSA SOA . , .



:



  • SOA
  • , SOA API ibm SOA MSA
  • Monolith vs SOA vs MSA medium
  • Microservices vs SOA DZone
  • MSA SOA
  • SOA MSA


45. ?

:



  • () -> , , , , , ( )
  • ->
  • ,


:



  • () โ€” (/, ..)
  • ,


:



  • . : , , , , , 2018
  • Wikipedia
  • Microservices โ€” Not A Free Lunch!
  • โ€”
  • What are microservices?
  • To go or not to go micro: the pros and cons of microservices
  • Microservices in a Nutshell. Pros and Cons


:



  • HeadHunter
  • :
  • ,


46. ?

(composition) โ€” " " (HAS-A Relationship), .



(aggregation) โ€” " " (HAS-A Relationship), , .



:



  • vs vs
  • , ,


47. ()? ?

(Test Double) โ€” ,

:



  • Dummy โ€” , , . : , null
  • Fake โ€” , , production-. : in-memory (fake database)
  • Stub โ€” (system under test โ€” SUT)
  • Spy โ€” Stub, , , ..
  • Mock โ€” ,


Mock , โ€” .



:



  • Mock vs Stub
  • Mocks Aren't Stubs
  • Test Double
  • Test Stub
  • Test Spy
  • Mock Object
  • Fake Object
  • Interaction Based Testing Spock Framework
  • Mockito
  • Mockito Mock vs. Spy in Spring Boot Tests
  • Tag: Mockito Bealdung


48.

:



โ€œโ€ , .

:



  1. . :

    • โ€” , , . (Generic).
    • (inclusive) โ€” , . .
  2. ( ad-hoc) โ€” () . :

    • (overloading) , ().
    • โ€” , , .


Java .

:



  • Java Challengers #3:
  • JVM
  • Java
  • Java Virtual Machine Specification: Invoking Methods, invokevirtual, Linking
  • Java Language Specification: Inheritance, Overriding, and Hiding, Conversions and Contexts, Type Inference


49. REST? API RESTful? REST SOAP?

REST โ€“ , web-.

REST, :



  • URI
  • โ€” JSON, XML
  • โ€” HTTP. โ€” , . .
  • HTTP . GET: ; POST: ; PUT: ; DELETE: . โ€” PUT vs PATCH vs POST.
  • HTTP . HTTP- .
  • HATEOAS , REST,


, , HTTP- URI, API RESTful. , . , , REST โ€” , . โ€” .



REST- :



  • - (Clientโ€“server)
  • (Stateless) โ€”
  • (Cacheable) โ€”
  • (Uniform interface) โ€” , , "" , HATEOAS
  • (Layered system) โ€” , .
  • ( ) (Code on demand (optional)) โ€”


SOAP โ€” .

SOAP:



  • โ€” XML (SOAP-XML โ€” Envelope, Header, Body, Fault)
  • SOAP- WSDL( XML)
  • SOAP โ€” (TCP, UDP, HTTP, SMTP, FTP ..)
  • HTTP, GET POST


, web-, .

-:



  • REST โ€” , REST vs SOAP, Contract First, Code First, HATEOAS, Java Spring
  • REST vs SOAP. 1. REST vs SOAP. 2. ?
  • . ( !)
  • REST API Best Practices
  • RESTful
  • RESTful API
  • REST-like API
  • web API
  • RESTful API โ€“ ( 1) RESTful API โ€“ ( 2)
  • : REST
  • 7 REST API
  • JAX-WS XSD Restrictions
  • REST API Java
  • Spring Boot: REST API Java
  • RESTful Kotlin Spring boot
  • SOAP- Java Apache CXF Spring
  • SOAP Web- Spring-WS


-:



  • REST โ€” SOAP
  • REST 200
  • REST API
  • RESTful API โ€”

    :
  • REST GraphQL
  • REST? JSON-RPC

    :
  • A Brief Introduction to REST
  • REST CookBook
  • RESTful Web APIs
  • Introduction to Spring Data REST
  • What is REST
  • Building REST services with Spring
  • SOAP Web-
  • SOAP




50. Lombok?

, ! !



Lombok โ€” , , , , . Lombok .

? ? , . โ€” .



โ€” : " - ?". . , -, .



, , Lombok โ€” IDEA. , . ! 2020.3 Lombok- IDEA.



Lombok , . , Hibernate ( ) Lombok entity-. @EqualsAndHashCode, @ToString @Data, equals, hashCode toString , entities. entities .



, , "+" 7-8 โ€” . asm0dey Lombok Lombok . : " , , @SneakyThrows ?" ( ), " @Data. equals ?", " @EqualsAndHashCode StackOverflowException ?".



Lombok โ€” โ€” , . โ€” . Lombok โ€” Lombok, . - , , .



P.S. Lombok onX โ€” (@__ Java 7) . , Spring-.



:



  • Project Lombok
  • Who Needs Lombok Anyhow
  • Be Careful With Lombok
  • Donโ€™t use Lombok
  • Lombok & Hibernate: How to Avoid Common Pitfalls
  • Error handling with @Transactional and @SneakyThrows
  • Lombok, sources.jar
  • Some Dangers of Using Lombok




51. ?

, (), .

OpenNET โ€” , .

MSDN.

โ€” .



52. ?

.

:



  • Apache JMeter โ€” , opensource, HTTP, HTTPS, FTP, LDAP, SOAP, TCP, shell-. , java-based , JDBC, Message-oriented middleware (MOM) JMS Java Objects.
  • LoadRunner โ€” . , Enterprise.
  • LoadNinja โ€” , - . , .
  • WebLOAD โ€” . , , , CI/CD.
  • LoadUI Pro โ€” SOAP UI, . - , API.
  • K6 โ€” opensource , . JavaScript. , , , Kafka, Datadog, InfluxDB, JSON StatsD. CI-.
  • . โ€” , โ€” hit-based- HTTP- Phantom jMeter. , , , .
  • Gatling โ€” opensource Scala Netty Akka. Scala, Jenkins.


:



  • -
  • :
  • Gatling
  • Top 10
  • 9
  • 10 Apache JMeter
  • jMeter โ€”
  • Rest API Load testing with Apache JMeter
  • Load Testing with Gatling โ€” The Complete Guide
  • -


53. ? ? Docker?

(Virtual Machine โ€” VM) โ€” / , . โ€” , . .. , , . . VM , . backup' VM .

VM .

โ€” / , , .

KVM QEMU, XEN, VMWare Hyper-V.



Docker โ€” , , , .. .

, . , . linux namespaces. cgroups.

, Dockerfile , () , . , , . .

Docker- CI/CD.

Docker- โ€” Docker-Hub

Docker, .



Docker:



  • VM Docker?
  • " Docker": 1, 2, 3, 4, 5, 6
  • Docker.
  • docker- ( docker run runc)
  • Docker: AWS
  • : Docker .
  • docker
  • Linux namespaces
  • Docker
  • Docker
  • Docker Y
  • Docker , ,
  • Docker-
  • Docker
  • 10 Docker: 1, 2
  • Docker:
  • Docker:
  • containerd Docker
  • : containerd "" CNCF


:



  • . ?
  • . 1.1.
  • Hyper-V:
  • Hyper-V Windows 10
  • QEMU-KVM
  • KVM.
  • : KVM vs. Xen
  • Hyper-V KVM?


, :



  • Containers vs. virtual machines
  • Play with Docker
  • Docker
  • The Docker EcoSystem
  • Hardware-assisted virtualization
  • Full virtualization
  • : KVM, Hyper-V VMware?
  • KVM
  • KVM
  • Unix. 1: Kernel-based Virtual Machine (KVM)
  • Linux/Cgroups
  • : cgroups
  • , VM Docker
  • containerd
  • awesome-compose
  • Learn Docker & Containers using Interactive Browser-Based Scenarios
  • What Is Docker & Docker Container? A Deep Dive Into Docker!
  • Docker for beginners


54. ? ?

โ€” - Java- โ€” , URL- URL ..

( -, ( Java EE)):



  • โ€” Apache Tomcat. : (TomEE)
  • Jetty
  • Undertow

    โ€” , Java EE ( Jakarta EE).

    :
  • Wildfly
  • Apache TomEE
  • IBM WebSphere
  • Eclipse GlassFish


" , Tomcat" .



-



  • Java-backend, Java core (60 )
  • Spring:
  • Java 1: JPA Hibernate
  • JavaSobes telegram
  • Awesome-interview-questions/Java
  • Java Developer
  • Java Developer
  • Java
  • JBook
  • Telegram- Java: fill the gaps
  • Telegram- middlejava
  • Telegram- Java Developer
  • Telegram- microJUG miniJUG
  • Telegram- javaswag
  • 50 Docker, ,
  • โ€” Java-
  • Every Programmer Should Know
  • : 1, 2, 3




Backend-Java- . , , , " " . , JUG.RU.



, , PR GitHub .



! ! ( ) . , โ€” .



In addition, memorizing the answers to the questions above does not guarantee successful employment, good work, and silkiness of hair.




All Articles