Enterprise Java Developer’s Survival Guide

A presentation at Java2Days in October 2017 in Sofia, Bulgaria by Petyo Dimitrov

Slide 1

Slide 1

Enterprise Java Developer’s handbook Petyo Dimitrov October, 2017

Slide 2

Slide 2

AGENDA About me Steps for survival Q&A 2 Survival guide

Slide 3

Slide 3

THE ENTERPRISE JAVA WILDERNESS 3 Survival guide

Slide 4

Slide 4

STEP 1: COME PREPARED What do I need to know to be an Enterprise Java developer? 4 Survival guide

Slide 5

Slide 5

KNOWLEDGE (1) Solid understanding of core Java & some specifics: • garbage collection strategies • class loading specifics • debugging (thread & heap dumps) Some experience with databases and middleware 5 Survival guide

Slide 6

Slide 6

KNOWLEDGE (2) Knowledge in OOP concepts and design patterns • Singleton, Dependency Injection, Factory, MVC … Core Java EE specs like Servlets, JPA & Components Basic Linux command line skills 6 Survival guide

Slide 7

Slide 7

KNOWLEDGE IMPROVEMENT Write code Collaborate with experienced people and learn from them Join an open-source project Code reviews are a great way to learn 7 Survival guide

Slide 8

Slide 8

STEP 2: BRING GEAR What tools should I be experienced in? 8 Survival guide

Slide 9

Slide 9

IDES & TOOLS 9 Survival guide

Slide 10

Slide 10

BE LAZY & AUTOMATE Builds & Tests (via Maven, Jenkins, etc.) Administrative tasks (via Scripts, custom tools) Environment setup (Vagrant, Docker) 10 Survival guide

Slide 11

Slide 11

APPLICATION GENERATION 11 Survival guide

Slide 12

Slide 12

STEP 3: GET ORIENTED Which technology stack should I choose? 12 Survival guide

Slide 13

Slide 13

SPRING VS JAVA EE 13 Survival guide

Slide 14

Slide 14

CLIENT REQUIREMENTS 14 Survival guide

Slide 15

Slide 15

KNOWLEDGE REQUIREMENTS 15 Survival guide

Slide 16

Slide 16

PROJECT REQUIREMENTS 16 Survival guide

Slide 17

Slide 17

POPULAR JAVA EE SPECIFICATIONS ZeroTurnaround’s survey of ~1700 developers 17 Survival guide

Slide 18

Slide 18

AND NOW WHAT? 18 Survival guide

Slide 19

Slide 19

STEP 4: BUILD SHELTER How do I setup the project? 19 Survival guide

Slide 20

Slide 20

BASIC SETUP (1) CI: Build: VCS: 20 Survival guide

Slide 21

Slide 21

BASIC SETUP (2) 21 Survival guide

Slide 22

Slide 22

ADVANCED SETUP 1. 2. 3. 4. 5. 6. Static code analysis 🡪 Sonar / IDE-based DB schema management 🡪 Flyway / Liquibase In-memory DB for development Easy to setup local environment Stable staging environment Continuous Delivery 22 Survival guide

Slide 23

Slide 23

UNIT TESTING! Via: • JUnit & Mockito / Powermock / EasyMock • Groovy & Spock Caveats: • one-off short-term projects • tests treated as second class code 23 Survival guide

Slide 24

Slide 24

UNIT TESTING ISSUES – USELESS TESTS def “invite calls the service”() { setup: def form = Mock(SomeInputForm) def actor = Mock(Actor) when: underTest.invite(actor, form) then: 1 * service.invite(actor, form) } 24 Survival guide

Slide 25

Slide 25

UNIT TESTING ISSUES – BRITTLE TESTS def “smart test name”() { setup: def customer = PETYO def device = SMART_DEVICE … when: def result = underTest.execute(taskData) then: 1 * deviceService.findByCustomer(customer) >> serviceResultA 0 * anotherService._ result == expected result } 25 Survival guide

Slide 26

Slide 26

STEP 5: FIND WATER How do I implement the project? 26 Survival guide

Slide 27

Slide 27

APPLICATION DESIGN Consider modules & package structure Review component interfaces Beware of excessive Dependency Injection Principles of Domain Driven Design 27 Survival guide

Slide 28

Slide 28

SHOULD I USE AN ORM? relational new nosql legacy object centric data centric CRUD queries reporting queries 28 Survival guide

Slide 29

Slide 29

WHAT PROBLEMS CAN I EXPECT? “Magic” powers i.e. hidden learning curve Reduced control over DB Loss of DB specific capabilities Difficulty fetching necessary data 29 Survival guide

Slide 30

Slide 30

HOW TO DESIGN REST API-S? • Follow the REST principles & look at the APIs of large companies • Use proper HTTP verbs (GET, PUT, POST, PATCH…) • GET /movie/1/booking • Use proper HTTP status codes • 418 I‘m a teapot 30 Survival guide

Slide 31

Slide 31

HOW TO DESIGN REST API-S? (2) • Medium grained resources • up to two levels of nesting • Security: • HTTPS • OAuth2 • BasicAuth 31 Survival guide

Slide 32

Slide 32

HOW TO DESIGN REST API-S? (3) • Proper URLs using plural nouns • GET /movies vs GET /getAllMovies • Spinal-case in URLs and camelCase / snake_case for parameters • http://www.penisland.net/ • GET /order-item/1?orderNumber=2 32 Survival guide

Slide 33

Slide 33

HOW TO DESIGN REST API-S? (4) • Consider versioning early on: • only major version • aim to have no more than 2 versions in parallel • /v1/movies, /v2/movies • Filters & sorting via URL parameters • ?sort=rating,budget&director=nolan 33 Survival guide

Slide 34

Slide 34

HOW TO DESIGN REST API-S? (5) • I18n of data: • via Accept-Language: bg_BG • Handling of operations (i.e. non-resources) • POST /email/12/send • consider JSON-RPC 34 Survival guide

Slide 35

Slide 35

STEP 6: FIND FOOD What about performance? 35 Survival guide

Slide 36

Slide 36

WHAT PROBLEMS SHOULD I EXPECT? • Infrastructure issues (available resources, unreliability, latency) • External system communication (synchronous calls, no timeouts, faulty integrations) • Lack of middleware tuning (thread & connection pools, clusters) • Garbage collection (limits, strategies) • Bugs (synchronization issues, memory leaks) 36 Survival guide

Slide 37

Slide 37

HOW TO IMPROVE PERSISTENCE? 1. 2. 3. 4. 5. 6. 7. Monitor query performance Review native SQL of sensitive queries • mark/optimize slow queries Use caching offered by ORM Beware of many-to-many relations & fetch types Run updates/deletes in bulk (beware of cascading) Paging & query projection Move logic to DB 37 Survival guide

Slide 38

Slide 38

HOW TO IMPROVE FRONT END? 1. Track time for processing each REST request 2. Use gzip 3. Partial request & responses (?fields + HTTP PATCH) 4. Cache friendly results (etag, last-modified) 5. Paging 38 Survival guide

Slide 39

Slide 39

STEP 7: STAY IN ONE PLACE VS SCOUT THE AREA 39 Survival guide

Slide 40

Slide 40

QUESTIONS? 40 Survival guide

Slide 41

Slide 41

THANK YOU petyo.dimitrov@musala.com 41 Survival guide