A presentation at Java2Days in in Sofia, Bulgaria by Petyo Dimitrov
Enterprise Java Developer’s handbook Petyo Dimitrov October, 2017
AGENDA About me Steps for survival Q&A 2 Survival guide
THE ENTERPRISE JAVA WILDERNESS 3 Survival guide
STEP 1: COME PREPARED What do I need to know to be an Enterprise Java developer? 4 Survival guide
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
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
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
STEP 2: BRING GEAR What tools should I be experienced in? 8 Survival guide
IDES & TOOLS 9 Survival guide
BE LAZY & AUTOMATE Builds & Tests (via Maven, Jenkins, etc.) Administrative tasks (via Scripts, custom tools) Environment setup (Vagrant, Docker) 10 Survival guide
APPLICATION GENERATION 11 Survival guide
STEP 3: GET ORIENTED Which technology stack should I choose? 12 Survival guide
SPRING VS JAVA EE 13 Survival guide
CLIENT REQUIREMENTS 14 Survival guide
KNOWLEDGE REQUIREMENTS 15 Survival guide
PROJECT REQUIREMENTS 16 Survival guide
POPULAR JAVA EE SPECIFICATIONS ZeroTurnaround’s survey of ~1700 developers 17 Survival guide
AND NOW WHAT? 18 Survival guide
STEP 4: BUILD SHELTER How do I setup the project? 19 Survival guide
BASIC SETUP (1) CI: Build: VCS: 20 Survival guide
BASIC SETUP (2) 21 Survival guide
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
UNIT TESTING! Via: • JUnit & Mockito / Powermock / EasyMock • Groovy & Spock Caveats: • one-off short-term projects • tests treated as second class code 23 Survival guide
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
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
STEP 5: FIND WATER How do I implement the project? 26 Survival guide
APPLICATION DESIGN Consider modules & package structure Review component interfaces Beware of excessive Dependency Injection Principles of Domain Driven Design 27 Survival guide
SHOULD I USE AN ORM? relational new nosql legacy object centric data centric CRUD queries reporting queries 28 Survival guide
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
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
HOW TO DESIGN REST API-S? (2) • Medium grained resources • up to two levels of nesting • Security: • HTTPS • OAuth2 • BasicAuth 31 Survival guide
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
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
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
STEP 6: FIND FOOD What about performance? 35 Survival guide
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
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
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
STEP 7: STAY IN ONE PLACE VS SCOUT THE AREA 39 Survival guide
QUESTIONS? 40 Survival guide
THANK YOU petyo.dimitrov@musala.com 41 Survival guide
I have been working in the enterprise Java field for a while now and periodically friends and colleagues ask me for help and advice. Over time I have collected several of their questions and would like to share them together with my view and experience on the subject. Questions vary from how to choose between popular Java frameworks, benefits and drawbacks of using ORM, designing REST APIs, performance considerations, etc. Some of them are specific to the Java field, while others are general topics for enterprise applications.