后端Java开发人员访谈:问题和在哪里寻找答案。第2部分



我正在为Backend-Java开发人员发布面试问题和答案的集合。在第一部分中,我们介绍了Java和Spring。在这一节中,我们将讨论Hibernate,数据库,模式和开发实践,一个流行的库,对我们应用程序的支持和维护,还将介绍替代备忘单并进行总结。



TL; DR

GitHub备有完整备忘单的存储库在这里,而Habr仍然是一块蛋糕。



问题



冬眠



28. Hibernate中有哪些缓存,默认情况下哪些缓存起作用?

3级缓存:



  • 一级缓存。默认启用。
  • 二级缓存。默认禁用。
  • (Query cache). .


:





Hibernate Vlad Mihalcea:





29.懒惰与Hibernate中的Eager有何不同?
  • 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 classMappedSuperclass, . . 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. . :

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



! ! ( ) . , — .



此外,记住以上问题的答案并不能保证成功就业,做好工作和头发柔滑。




All Articles