Popular Posts

Sunday, February 02, 2020

Welcome to Javabench!

Javabench is a collection of Java tutorials, sample code / examples, articles, interview questions & answers, OCP JP (formerly SCJP) questions & links to useful technical resources from other websites. The aim behind this blog is to collate technical knowledge useful for day to day development & interview preparation.
This covers resources on HibernateDesign PatternsSpring (DI, Batch, Security, DAO)Core / Advance Java/J2eeWeb Services (SOAP & REST), XML, UML, Struts, Maven etc.

Tuesday, February 07, 2017

Java Application Architecture Design Resources

Java / J2EE Architecture Design for a application / product / system solution is as big task as it is important. Architects need to define clear path / process / guidelines / ToDo's from day one, for each stage / phase e.g. analysis, design, development etc. There are set of good/best practices, design patterns / decisions need to be followed, and many pitfalls / anti-patterns which should be avoided at any cost.

This post is an attempt to collect resources helpful to core Java / J2ee architects. I will try to keep it updated with latest developments / changes to tools & technologies.

J2EE Architecture & Processes

Java Design Development Best Practices

Java Performance Best Practices

Clean Architecture Pros & Cons

Common Pitfalls Of Experienced Java Developers & Architects

Friday, January 27, 2017

REST & SOAP Web Service/API Difference / Comparison

Though difference between REST and SOAP web service is very old question, a updated detailed answer is always needed. Below notes help to understand which is better, and useful in different scenarios for design / development:

SOAP (Simple Object Access Protocol)
• To make applications communicate to each other (sending and receiving messages) over internet, over HTTP (it's supported by all browsers and servers) - SOAP was created.
• SOAP provides a standard way to communicate between applications running on different OS, with different technologies and languages.

• SOAP is an Application Communication PROTOCOL, which runs over a Transport Protocol
• SOAP is independent of transport protocol (could be HTTP, SMTP, FTP, TCP, UDP, even email)
• On HTTP (default SOAP transport protocol), only the POST verb is used
• SOAP is platform / language independent
• SOAP supports XML messages only
• Contract (WSDL) based system, Tightly coupled
• Action /Service oriented system (leads to Service Oriented Architecture)

• CXF, Metro, Kenai (RI), Axis, Spring WS

REST (Representational State Transfer)
• SOAP and REST can't be compared directly, since the first is a protocol and the second is an architectural style.
• Like SOAP, REST is also transport protocol independent. REST application can use any protocol for which there is an standardized URI scheme.
• REST makes full use of the specific features of that protocol (verbs GET, POST, PUT, DELETE, caching, stateless, predefined error codes – all are HTTP properties).

• Supports variety of format - JSON/XML/Plain HTML etc
• Loosely coupled, no contract needed
• Everything is just URL based
• REST is very lightweight (no heavy XML header/body needed)
• REST is data / resource oriented (leads to Resource Oriented Architecture)
• For a truly RESTFUL api, all RESTFUL Constraints (Client-Server, Stateless, Cache, Interface / Uniform Contract, Layered System, Code-On-Demand) should be followed

• CXF, Jersey (RI), RESTEasy, Spring RESTful

Designing REST API :
http://blog.mwaysolutions.com/2014/06/05/10-best-practices-for-better-restful-api/
https://stormpath.com/blog/fundamentals-rest-api-design
https://www.thoughtworks.com/insights/blog/rest-api-design-resource-modeling

Friday, December 23, 2016

Monolithic vs. Microservices Architecture

Monolithic Architecture

In a server-side application Its common to have following layers:
Presentation — responsible for handling HTTP requests and responding with either HTML or JSON/XML (for web services APIs).
Business logic — the application’s business logic.
Database access — data access objects responsible for access the database.
Application integration — integration with other services (e.g. via messaging or REST API).

Benefits of Monolithic Architecture

* Simple to develop.
* Simple to test. e.g. you can implement end-to-end testing by simply launching the application and testing the UI with Selenium.
* Simple to deploy. You just have to copy the packaged application to a server.
* Simple to scale horizontally by running multiple copies behind a load balancer.
* In the early stages of the project it works well and basically most of the big and successful applications which exist today were started as a monolith.

Drawbacks of Monolithic Architecture

* This simple approach has a limitation in size and complexity.
* Application is too large and complex to fully understand and made changes fast and correctly.
* The size of the application can slow down the start-up time.
* You must redeploy the entire application on each update.
* Impact of a change is usually not very well understood which leads to do extensive manual testing.
* Continuous deployment is difficult.
* Monolithic applications can also be difficult to scale when different modules have conflicting resource requirements.
* Another problem with monolithic applications is reliability. Bug in any module (e.g. memory leak) can potentially bring down the entire process. Moreover, since all instances of the application are identical, that bug will impact the availability of the entire application.
* Monolithic applications has a barrier to adopting new technologies. Since changes in frameworks or languages will affect an entire application it is extremely expensive in both time and cost.

Source:
https://articles.microservices.com/monolithic-vs-microservices-architecture-5c4848858f59
http://www.martinfowler.com/articles/microservices.html
http://microservices.io/patterns/microservices.html

Wednesday, November 09, 2016

Java Development / coding Best Practices / Guidelines

While developing / programming in Java, new developers / programmers are bound to make some mistakes. I have just compiled a list for To Do's in Java while writing software. It summarizes what are good practices / guidelines / ToDo's and what to avoid:

Best-practices-when-coding-java

Writing in Java by Joshua Bloch

Java Language Best Practices

OReilly Java Design & Coding

java-programming-tips-best-practices-beginners

java-best-practices

Friday, August 26, 2016

Google Java Style Guide / Coding Standards / Programming Practice

Below is link to Google' java coding standards, which provide detailed description on best programming practices for naming, formatting, source file etc.

https://google.github.io/styleguide/javaguide.html


Tuesday, May 31, 2016

MongoDB tutorial with Java


MongoDB is the most popular No-SQL database. Lets try it out:

1) Install: 
Go to the MongoDb website and download latest release.

2) Run MongoDB:
First command prompt window:
C:\Program Files\MongoDB\Server\3.2\bin>mongod.exe --dbpath D:\mongo\data
Second command prompt window:
C:\Program Files\MongoDB\Server\3.2\bin>mongo.exe

2) Creating a Database: write insert queries
db.mytable.insert({
    first: 'amit',
    last: 'kumar',
    age: 25,
    dob: '21/04/1978',
    gender: 'm',
    occupation: 'developer',
    nationality: 'indian'
});
db.mytable.insert({
    first: 'sumit',
    last: 'singh',
    age: 34,
    dob: '26/03/1940',
    gender: 'm',
    occupation: 'engineer',
    nationality: 'american'
});

3) verify
db.mytable.find()


4) Download Robomongo
connect to database and see the records present there.