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). .


:





Hibernate Vlad Mihalcea:





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 .



:





N+1, db-util Vlad Mihalcea. .



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



:





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. .


:





, JavaDoc :





JPA 2.2. pdf.





33. where having SQL?

Postgresql. Postgres Pro:



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

:





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


35. . ? ? ?

:



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


:





36. ? ?

โ€” , . . /. .



:





. .

, :



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

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


:





37. ?

(lock) โ€” .



โ€” , . , . . , , .

:



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


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



, , . , .



Vlad Mihalcea:





:





:





, ,



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.





:





:





42. ?

-, . . - "".



โ€” Microservice Patterns and Best Practices. Medium .



microservices.io : . โ€” . .



. โ€” Enterprise Integration Patterns .



43. CAP-. MongoDB () CAP-?

CAP โ€” , , :





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



.



:





44. ?

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

:



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

    -

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

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


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



:





45. ?

:



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


:



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


:





:





46. ?

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



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



:





47. ()? ?

(Test Double) โ€” ,

:



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


Mock , โ€” .



:





48.

:



โ€œโ€ , .

:



  1. . :

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

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


Java .

:





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-, .

-:





-:







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-.



:







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.


:





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:





:





, :





54. ? ?

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

( -, ( Java EE)):





" , Tomcat" .



-







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