Service Layer Pattern in Java: Enhancing Application Architecture with Robust Service Layers

Also known as.

  • Application Facade

Intent of Service Layer Design Pattern

The Service Layer pattern is crucial for Java developers focusing on building robust application architectures that separate business processes from user interface concerns.

The pattern encapsulate business logic in a distinct layer to promote separation of concerns and to provide a well-defined API for the presentation layer.

Detailed Explanation of Service Layer Pattern with Real-World Examples

Real-world example

Imagine a complex restaurant system where orders are managed through a centralized 'service layer' to ensure efficient operation and clear communication between the front and back of the house. Each section specializes in a part of the meal, but the waitstaff don't interact directly with the kitchen staff. Instead, all orders go through a head chef who coordinates the workflow. The head chef acts like the service layer, handling the business logic (order coordination) and providing a unified interface for the waitstaff (presentation layer) to interact with the kitchen (data access layer).

In plain words

A pattern that encapsulates business logic into a distinct layer to promote separation of concerns and provide a clear API for the presentation layer.

Wikipedia says

Service layer is an architectural pattern, applied within the service-orientation design paradigm, which aims to organize the services, within a service inventory, into a set of logical layers. Services that are categorized into a particular layer share functionality. This helps to reduce the conceptual overhead related to managing the service inventory, as the services belonging to the same layer address a smaller set of activities.

Programmatic Example of Service Layer Pattern in Java

Our Java implementation uses the Service Layer pattern to streamline interactions between data access objects (DAOs) and the business logic, ensuring a clean separation of concerns.

The example application demonstrates interactions between a client App and a service MagicService that allows interaction between wizards, spellbooks and spells. The service is implemented with 3-layer architecture (entity, dao, service).

For this explanation we are looking at one vertical slice of the system. Let's start from the entity layer and look at Wizard class. Other entities not shown here are Spellbook and Spell .

Above the entity layer we have DAOs. For Wizard the DAO layer looks as follows.

Next we can look at the Service Layer, which in our case consists of a single MagicService .

And finally, we can show how the client App interacts with MagicService in the Service Layer.

The program output:

Service Layer

When to Use the Service Layer Pattern in Java

  • Use when you need to separate business logic from presentation logic.
  • Ideal for applications with complex business rules and workflows.
  • Suitable for projects requiring a clear API for the presentation layer.

Real-World Applications of Service Layer Pattern in Java

  • Java EE applications where Enterprise JavaBeans (EJB) are used to implement the service layer.
  • Spring Framework applications using the @Service annotation to denote service layer classes.
  • Web applications that need to separate business logic from controller logic.

Benefits and Trade-offs of Service Layer Pattern

Implementing a Service Layer in Java

  • Promotes code reuse by encapsulating business logic in one place.
  • Enhances testability by isolating business logic.
  • Improves maintainability and flexibility of enterprise applications.

Trade-offs:

  • May introduce additional complexity by adding another layer to the application.
  • Can result in performance overhead due to the extra layer of abstraction.

Related Java Design Patterns

  • Facade : Simplifies interactions with complex subsystems by providing a unified interface.
  • DAO (Data Access Object) : Often used together with the Service Layer to handle data persistence.
  • MVC (Model-View-Controller) : The Service Layer can be used to encapsulate business logic in the model component.

References and Credits

  • Core J2EE Patterns: Best Practices and Design Strategies
  • Patterns of Enterprise Application Architecture
  • Spring in Action
  • Service Layer (Martin Fowler)

Building Java Enterprise Applications by Brett McLaughlin

Get full access to Building Java Enterprise Applications and 60K+ other titles, with a free 10-day trial of O'Reilly.

There are also live events, courses curated by job role, and more.

The Business Layer

Next in the design process is the task of creating a business layer. This portion of the application is wedged between presentation (what the user sees) and data (what the application depends on). The business layer, then, does just what it implies: it performs business (logic). Data on its own is rarely relevant, and often makes no sense without some context applied to it. In the same fashion, the presentation layer must have something to present (no rocket science here!). In this business layer, then, data is manipulated, transformed, and converted into content suitable for presentation.

The core of this layer is the code that actually executes business logic. This code maps to a company’s business processes; in the best case, a single module of code represents a single business process. These modules can then be called to obtain a client’s outstanding balance, for example. This figure is rarely stored in the database, but instead is calculated from the client’s purchases subtracted from his or her assets. This allows the raw data to be masked from the presentation layer of an application; instead of asking for data and performing calculations, the application needs to request only the business process that results in a client’s account balance, and format the result.

Business Logic

With entity beans in place for handling data access to most of our application, it makes sense to continue to leverage EJB for the business logic in our application. In this case, ...

Get Building Java Enterprise Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.

Don’t leave empty-handed

Get Mark Richards’s Software Architecture Patterns ebook to better understand how to design components—and how they should interact.

It’s yours, free.

Cover of Software Architecture Patterns

Check it out now on O’Reilly

Dive in for free with a 10-day trial of the O’Reilly learning platform—then explore all the other resources our members count on to build skills and solve problems every day.

business logic and presentation logic in java

  • Trending Categories

Data Structure

  • Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Effective Resume Writing
  • HR Interview Questions
  • Computer Glossary

What is the Business-Logic Layer?

The business-logic layer is a crucial component of a software application that handles the processing of data and implementation of business rules. It sits between the user interface (UI) layer, which is responsible for presenting data to the user, and the data access layer, which is responsible for storing and retrieving data from a database.

The primary function of the business-logic layer is to process and validate user input, apply business rules, and prepare data for storage or presentation. It acts as an intermediary between the UI and data access layers, ensuring that data is properly formatted and meets the requirements of the underlying system.

Why is the Business-Logic Layer Important?

The business-logic layer is important because it separates the UI and data access layers, which allows for a cleaner, more modular design. This separation of concerns makes it easier to maintain and modify the application over time.

In addition, the business-logic layer can serve as a security layer by validating user input and enforcing business rules. This helps to prevent unauthorized access to data and ensures that data is entered and processed correctly.

Finally, the business-logic layer helps to improve the performance of the application by offloading processing and validation tasks from the UI and data access layers. This allows these layers to focus on their primary responsibilities and can result in a faster, more efficient application.

Implementing the Business-Logic Layer

There are several approaches to implementing the business-logic layer in a software application. One common approach is to use a server-side language, such as Java or Python, to build the business-logic layer as a set of classes or functions. These classes or functions can be called by the UI or data access layers as needed to process data or apply business rules.

Here is an example of a simple business-logic class written in Java −

In this example, the processOrder method takes an Order object as input and performs several tasks −

Validates the order to ensure that it is in a valid state.

Applies a business rule to give a 10% discount to orders over $ 1000.

Sets the status of the order to "processed".

Saves the order to the database using a data access object (DAO).

The business-logic layer can also be implemented using a serverless architecture, such as AWS Lambda or Google Cloud Functions. In this case, the business logic is implemented as a standalone function that is triggered by an event, such as an HTTP request or a database update.

Here is an example of a simple business-logic function implemented using AWS Lambda and written in Python −

This example demonstrates how the business-logic layer can be implemented as a standalone function using AWS Lambda. The function receives an event containing order data and performs several tasks −

Saves the order to a DynamoDB table using the AWS SDK for Python (Boto3).

Benefits of Using the Business-Logic Layer

There are several benefits to using the business-logic layer in a software application −

Improved modularity − By separating the UI, business-logic, and data access layers, the application is more modular and easier to maintain.

Enhanced security − The business-logic layer can serve as a security layer by validating user input and enforcing business rules.

Improved performance − The business-logic layer can offload processing and validation tasks from the UI and data access layers, resulting in a faster, more efficient application.

Flexibility − The business-logic layer can be implemented using a variety of technologies and architectures, such as server-side languages or serverless functions, depending on the needs of the application.

Important tips

Best practices for designing the business-logic layer − There are a number of best practices that can help developers design the business-logic layer in a way that is scalable, maintainable, and easy to understand. These practices include keeping the business-logic layer thin, avoiding duplication, and separating concerns.

Testing the business-logic layer − It is important to test the business-logic layer to ensure that it is working correctly and meets the requirements of the application. There are several approaches to testing the business-logic layer, including unit testing, integration testing, and functional testing.

Reusable business-logic components − The business-logic layer can be designed to be reusable, which means that it can be used in multiple applications or contexts. Reusable business-logic components can help to reduce development time and improve the quality of the application.

Caching in the business-logic layer − The business-logic layer can make use of caching to improve the performance of the application. Caching involves storing data in memory so that it can be quickly retrieved, rather than going to the database or external service every time it is needed.

Performance optimization in the business-logic layer − There are several techniques that can be used to optimize the performance of the business-logic layer, such as minimizing database queries, using asynchronous processing, and using a distributed cache.

Handling errors and exceptions in the business-logic layer − It is important to handle errors and exceptions in the business-logic layer in a way that is appropriate for the application. This can involve logging errors, sending notifications, or failing gracefully.

The business-logic layer is a crucial component of a software application that handles the processing of data and implementation of business rules. It sits between the UI and data access layers and helps to improve the modularity, security, and performance of the application. By using the business-logic layer, developers can build more scalable and maintainable applications that meet the needs of their users.

Raunak Jain

  • Related Articles
  • What is Logic Gates?
  • What is Control Logic Gates?
  • What is the session layer?
  • What is the Ozone Layer?
  • What is Propositional Logic Based Agent?
  • What is Presentation Layer?
  • What is the measure for ozone layer?
  • What is Business Intelligence?
  • What is Business Agility?
  • What is a presentation layer?
  • What is Business Analysis and What does a Business Analyst Do?
  • What is Session Layer in the Computer Network?
  • What is Data Link Layer Switching?
  • What is Layer 2 Forwarding (L2F)?
  • What is physical layer coding violation?

Kickstart Your Career

Get certified by completing the course

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Mixing business logic and presentation layer in enum type

Let's assume I have an enum type with currency:

Now, somewhere in the presentation layer I say:

in order to see the "EUR" string in an appropriate place.

Everything is perfect, but such approach mixes the Model and View together , doesn't it? CurrencyType is widely used in business logic and this is it's main goal.

What other approach would you suggest? Or maybe my code is not so wrong as I expect?

200_success's user avatar

3 Answers 3

If you want to decouple Enum and presentation logic, consider using EnumMap . This type of collection is fast and key-safe.

IMO, there is nothing wrong to store short and full currency names in CurrencyType. But localized name (as well as country's flag and other visual aspects) better be decoupled and put into presentation layer. You can use short names as keys for resource bundles.

Furthermore, if all CurrencyType values reproduce currency short names, you can eliminate using dedicated private field for them and use Enum.name() instead.

iTollu's user avatar

Full decoupling would assign arbitrary identifiers to currencies (possibly integers sequentially) and then presentation would map them to 'EUR', 'USD' as well as their names.

However in reality there is no realistic prospect that EUR/USD/JPY are going to change and holding the ISO name 'US Dollar', etc. in the code is a good defensive fall-back if a local name is not found.

So yes, you are mixing business data / presentation and program logic but (in your case) not in a way that is certain to cause you harm.

What you are limiting is the range of currencies. Entries on the ISO4217 list don't tend to change but they do come and go.

What are you going to do when later this year 'NGD' shows up? Your organisation might not be interested in the "New Greek Drachma" but if you're holding EUR assets you might not have a choice! ;)

OK so that's a little speculative, but you get the point...

Accessing an enum directly from the presentation isn't objectively "so bad." However it suggests an architecture other than MVC such as client-server on the high end or the ever popular BBoM elsewhere.

The leaky abstraction under MVC comes from storing strings in CurrencyType . Unless the business logic requires parsing strings, all the business logic needs is:

The missing piece is a clearly defined interface between the View and the Controller.

The controller should pass a value to the view. It could pass 1 , 2 , or 3 directly from CurrencyType , but that's probably not a good idea for obvious reasons. An alternative is for the controller to pass the tuple of strings, i.e. something that would serialize to JSON as:

The point of showing this as JSON is not love of JSON. It's that the MVC architecture should define the Model-Controller and Controller-View interfaces so that the layers on each side can be written in different languages, e.g. SQL->Java->JavaScript.

Each interface should be designed to explicitly serialize and deserialize data in both directions to prevent leaky abstractions.

ben rudgers's user avatar

Your Answer

Sign up or log in, post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

Not the answer you're looking for? Browse other questions tagged java mvc enum or ask your own question .

  • The Overflow Blog
  • Best practices for cost-efficient Kafka clusters
  • The hidden cost of speed
  • Featured on Meta
  • Announcing a change to the data-dump process
  • Bringing clarity to status tag usage on meta sites

Hot Network Questions

  • How to change upward facing track lights 26 feet above living room?
  • If a Palestinian converts to Judaism, can they get Israeli citizenship?
  • An instructor is being added to co-teach a course for questionable reasons, against the course author's wishes—what can be done?
  • In Lord Rosse's 1845 drawing of M51, was the galaxy depicted in white or black?
  • Online databases for integrals/series/constants/equations
  • Libsodium: Why hiding the field arithmetics?
  • How do we know the strength of interactions in degenerate matter?
  • How best to cut (slightly) varying size notches in long piece of trim
  • How to Interpret Statistically Non-Significant Estimates and Rule Out Large Effects?
  • Why didn't Air Force Ones have camouflage?
  • The state of the art on topological rings - the Jacobson topology
  • Short story about humanoid creatures living on ice, which can swim under the ice and eat the moss/plants that grow on the underside of the ice
  • Find the global maxima over the interval [0,1]
  • How do I prevent a problem with a player/character that has a history of doing whatever they think is funniest if my character doesn't know that?
  • Why are poverty definitions not based off a person's access to necessities rather than a fixed number?
  • Sylvester primes
  • How do I safely download and run an older version of software for testing without interfering with the currently installed version?
  • Is there a way to do a PhD such that you get a broad view of a field or subfield as a whole?
  • How to run only selected lines of a shell script?
  • Why is there so much salt in cheese?
  • Pressure of a gas on the inside walls of a cylinder canonical ensemble
  • Pull up resistor question
  • Is response variable/dependent variable data required for simr simulation?
  • Deleting all files but some on Mac in Terminal

business logic and presentation logic in java

  • Skip to content
  • Accessibility Policy
  • QUICK LINKS
  • Oracle Cloud Infrastructure
  • Oracle Fusion Cloud Applications
  • Oracle Database
  • Download Java
  • Careers at Oracle

 alt=

  • Create an Account

Servlets and JSP Pages Best Practices

by Qusay H. Mahmoud March 2003

Java Servlet technology and JavaServer Pages (JSP pages) are server-side technologies that have dominated the server-side Java technology market; they've become the standard way to develop commercial web applications. Java developers love these technologies for myriad reasons, including: the technologies are fairly easy to learn, and they bring the Write Once, Run Anywhere paradigm to web applications. More importantly, if used effectively by following best practices, servlets and JSP pages help separate presentation from content. Best practices are proven approaches for developing quality, reusable, and easily maintainable servlet- and JSP-based web applications. For instance, embedded Java code (scriptlets) in sections of HTML documents can result in complex applications that are not efficient, and difficult to reuse, enhance, and maintain. Best practices can change all that.

In this article, I'll present important best practices for servlets and JSP pages; I assume that you have basic working knowledge of both technologies. This article:

  • Presents an overview of Java servlets and JavaServer pages (JSP pages)
  • Provides hints, tips, and guidelines for working with servlets and JSP pages
  • Provides best practices for servlets and JSP pages

Overview of Servlets and JSP Pages

Similar to Common Gateway Interface (CGI) scripts, servlets support a request and response programming model. When a client sends a request to the server, the server sends the request to the servlet. The servlet then constructs a response that the server sends back to the client. Unlike CGI scripts, however, servlets run within the same process as the HTTP server.

When a client request is made, the service method is called and passed a request and response object. The servlet first determines whether the request is a GET or POST operation. It then calls one of the following methods: doGet or doPost . The doGet method is called if the request is GET , and doPost is called if the request is POST . Both doGet and doPost take request ( HttpServletRequest ) and response ( HttpServletResponse ).

In the simplest terms, then, servlets are Java classes that can generate dynamic HTML content using print statements. What is important to note about servlets, however, is that they run in a container, and the APIs provide session and object life-cycle management. Consequently, when you use servlets, you gain all the benefits from the Java platform, which include the sandbox (security), database access API via JDBC, and cross-platform portability of servlets.

JavaServer Pages (JSP)

The JSP technology--which abstracts servlets to a higher level--is an open, freely available specification developed by Sun Microsystems as an alternative to Microsoft's Active Server Pages (ASP) technology, and a key component of the Java 2 Enterprise Edition (J2EE) specification. Many of the commercially available application servers (such as BEA WebLogic, IBM WebSphere, Live JRun, Orion, and so on) support JSP technology.

How Do JSP Pages Work?

A JSP page is basically a web page with traditional HTML and bits of Java code. The file extension of a JSP page is .jsp rather than .html or .htm, which tells the server that this page requires special handling that will be accomplished by a server extension or a plug-in.

When a JSP page is called, it will be compiled (by the JSP engine) into a Java servlet. At this point the servlet is handled by the servlet engine, just like any other servlet. The servlet engine then loads the servlet class (using a class loader) and executes it to create dynamic HTML to be sent to the browser, as shown in Figure 1. The servlet creates any necessary object, and writes any object as a string to an output stream to the browser.

Figure 1: Request/Response flow calling a JSP page

The next time the page is requested, the JSP engine executes the already-loaded servlet unless the JSP page has changed, in which case it is automatically recompiled into a servlet and executed.

Best Practices

In this section, I present best practices for servlets and particularly JSP pages. The emphasis on JSP best practices is simply because JSP pages seem to be more widely used (probably because JSP technology promotes the separation of presentation from content). One best practice that combines and integrates the use of servlets and JSP pages is the Model View Controller (MVC) design pattern, discussed later in this article.

  • Don't overuse Java code in HTML pages : Putting all Java code directly in the JSP page is OK for very simple applications. But overusing this feature leads to spaghetti code that is not easy to read and understand. One way to minimize Java code in HTML pages is to write separate Java classes that perform the computations. Once these classes are tested, instances can be created.
  • Include directive: <%@ include file="filename" %>
  • Include action: <jsp:include page="page.jsp" flush="true" />

The first include mechanism includes the content of the specified file while the JSP page is being converted to a servlet (translation phase), and the second include includes the response generated after the specified page is executed. I'd recommend using the include directive, which is fast in terms of performance, if the file doesn't change often; and use the include action for content that changes often or if the page to be included cannot be decided until the main page is executed.

Another include mechanism is the <c:import> action tag provided by the JavaServer pages Standard Tag Library (JSTL). You can use this tag to bring in, or import, content from local and remote sources. Here are some examples:

  • Reusable components: Different applications will be able to reuse the components.
  • Separation of business logic and presentation logic: You can change the way data is displayed without affecting business logic. In other words, web page designers can focus on presentation and Java developers can focus on business logic.
  • Protects your intellectual property by keeping source code secure.

If you use Enterprise JavaBeans (EJBs) components with your application, the business logic should remain in the EJB components which provide life-cycle management, transaction support, and multi-client access to domain objects (Entity Beans).

JSP technology allows you to introduce new custom tags through the tag library facility. As a Java developer, you can extend JSP pages by introducing custom tags that can be deployed and used in an HTML-like syntax. Custom tags also allow you to provide better packaging by improving the separation between business logic and presentation logic. In addition, they provide a means of customizing presentation where this cannot be done easily with JSTL.

Some of the benefits of custom tags are:

  • They can eliminate scriptlets in your JSP applications. Any necessary parameters to the tag can be passed as attributes or body content, and therefore no Java code is needed to initialize or set component properties.
  • They have simpler syntax. Scriptlets are written in Java code, but custom tags can be used in an HTML-like syntax.
  • They can improve the productivity of nonprogrammer content developers, by allowing them to perform tasks that cannot be done with HTML.
  • They are reusable. They save development and testing time. Scriptlets are not reusable, unless you call cut-and-paste "reuse."

In short, you can use custom tags to accomplish complex tasks the same way you use HTML to create a presentation.

The following programming guidelines are handy when writing custom tag libraries:

  • Keep it simple: If a tag requires several attributes, try to break it up into several tags.
  • Make it usable: Consult the users of the tags (HTML developers) to achieve a high degree of usability.
  • Do not invent a programming language in JSP pages: Do not develop custom tags that allow users to write explicit programs.
  • Try not to re-invent the wheel: There are several JSP tag libraries available, such as the Jakarta Taglibs Project. Check to see if what you want is already available.
  • Do not reinvent the wheel : While custom tags provide a way to reuse valuable components, they still need to be created, tested, and debugged. In addition, developers often have to reinvent the wheel over and over again and the solutions may not be the most efficient. This is the problem that the JavaServer Pages Standard Tag Library (JSTL) solves, by providing a set of reusable standard tags. JSTL defines a standard tag library that works the same everywhere, so you no longer have to iterate over collections using a scriptlet (or iteration tags from numerous vendors). The JSTL includes tags for looping, reading attributes without Java syntax, iterating over various data structures, evaluating expressions conditionally, setting attributes and scripting variables in a concise manner, and parsing XML documents.
  • Use the JSTL Expression Language : Information to be passed to JSP pages is communicated using JSP scoped attributes and request parameters. An expression language (EL), which is designed specifically for page authors, promotes JSP scoped attributes as the standard way to communicate information from business logic to JSP pages. Note, however, that while the EL is a key aspect of JSP technology, it is not a general purpose programming language. Rather, it is simply a data access language, which makes it possible to easily access (and manipulate) application data without having to use scriptlets or request-time expression values.

In JSP 1.x, a page author must use an expression <%= aName %> to access the value of a system, as in the following example:

or the value of a custom JavaBeans component:

<%= aCustomer.getAddress().getCountry() %>

An expression language allows a page author to access an object using a simplified syntax. For example, to access a simple variable, you can use something like:

<someTags:aTag attribute="${aName}">

And to access a nested JavaBeans property, you would use something like:

If you've worked with JavaScript, you will feel right at home, because the EL borrows the JavaScript syntax for accessing structured data.

  • Use filters if necessary : One of the new features of JSP technology is filters. If you ever come across a situation where you have several servlets or JSP pages that need to compress their content, you can write a single compression filter and apply it to all resources. In Java BluePrints, for example, filters are used to provide the SignOn.
  • Use a portable security model : Most application servers provide server- or vendor-specific security features that lock developers to a particular server. To maximize the portability of your enterprise application, use a portable web application security model. In the end, however, it's all about tradeoffs. For example, if you have a predefined set of users, you can manage them using form-based login or basic authentication. But if you need to create users dynamically, you need to use container-specific APIs to create and manage users. While container-specific APIs are not portable, you can overcome this with the Adapter design pattern.
  • Use a database for persistent information : You can implement sessions with an HttpSession object, which provides a simple and convenient mechanism to store information about users, and uses cookies to identify users. Use sessions for storing temporary information--so even if it gets lost, you'll be able to sleep at night. (Session data is lost when the session expires or when the client changes browsers.) If you want to store persistent information, use a database, which is much safer and portable across browsers.
  • Cache content : You should never dynamically regenerate content that doesn't change between requests. You can cache content on the client-side, proxy-side, or server-side.
  • Use connection pooling : I'd recommend using the JSTL for database access. But if you wish to write your own custom actions for database access, I'd recommend you use a connection pool to efficiently share database connections between all requests. However, note that J2EE servers provide this under the covers.
  • Cache results of database queries : If you want to cache database results, do not use the JDBC's ResultSet object as the cache object. This is tightly linked to a connection that conflicts with the connection pooling. Copy the data from a ResultSet into an application-specific bean such as Vector , or JDBC's RowSets .
  • Adopt the new JSP XML syntax if necessary . This really depends on how XML-compliant you want your applications to be. There is a tradeoff here, however, because this makes the JSP more tool-friendly, but less friendly to the developer.
  • Read and apply the Enterprise BluePrints : Sun's Enterprise BluePrints provide developers with guidelines, patterns , and sample applications, such as the Adventure Builder and Pet Store. Overall, the J2EE BluePrints provide best practices and a set of design patterns, which are proven solutions to recurring problems in building portable, robust, and scalable enterprise Java applications.

Integrating Servlets and JSP Pages

The JSP specification presents two approaches for building web applications using JSP pages: JSP Model 1 and Model 2 architectures. These two models differ in the location where the processing takes place. In Model 1 architecture, as shown in Figure 2, the JSP page is responsible for processing requests and sending back replies to clients.

Figure 2: JSP Model 1 Architecture

The Model 2 architecture, as shown in Figure 3, integrates the use of both servlets and JSP pages. In this mode, JSP pages are used for the presentation layer, and servlets for processing tasks. The servlet acts as a controller responsible for processing requests and creating any beans needed by the JSP page. The controller is also responsible for deciding to which JSP page to forward the request. The JSP page retrieves objects created by the servlet and extracts dynamic content for insertion within a template.

Figure 3: JSP Model 2 Architecture

This model promotes the use of the Model View Controller (MVC) architectural style design pattern. Note that several frameworks already exist that implement this useful design pattern, and that truly separate presentation from content. The Apache Struts is a formalized framework for MVC. This framework is best used for complex applications where a single request or form submission can result in substantially different-looking results.

Best practices -- which are proven solutions to recurring problems -- lead to higher quality applications. This article presented several guidelines and best practices to follow when developing servlet- and JSP-based web applications.

Keep an eye on servlets and JSP technologies, because several exciting things are in the works. JavaServer Faces (JFC), for example, a Java Community Process effort that aims to define a standard web application framework, will integrate nicely with Apache Struts.

For more information

  • JavaServer Pages
  • Enterprise BluePrints
  • Apache Struts
  • Code Conventions for the JavaServer Pages Technology Version 1.x Language
  • Java Server Faces (JSF)

Acknowledgments

Special thanks to Gregory Murray of Sun Microsystems, whose feedback helped me improve this article.

About the author

Qusay H. Mahmoud provides Java consulting and training services. He has published dozens of articles on Java, and is the author of Distributed Programming with Java (Manning Publications, 1999) and Learning Wireless Java (O'Reilly, 2002).

Many feel that when using MVC, code in a JSP which performs a task not directly related to presentation (such as business logic, validation, error handling, etc.) probably belongs elsewhere. For example, the most natural home for validation code is the Model Object.

This is a specific example of a general guideline of lasting value - the idea of separating the "layers" of the application : the user interface, the business logic or model, and the database. The underlying reason for this separation is, ultimately, to allow people with different skills to make significant and effective contributions to the development of an application. User interface designers should be concerned almost entirely with presentation issues, while a database expert should be concerned almost entirely with writing SQL.

(See as well the package by feature, not layer topic.)

  • Data Science
  • Data Analysis
  • Data Visualization
  • Machine Learning

Deep Learning

  • Computer Vision
  • Artificial Intelligence
  • AI ML DS Interview Series
  • AI ML DS Projects series
  • Data Engineering
  • Web Scrapping

Machine learning with Java

Machine learning (ML) with Java is an intriguing area for those who prefer to use Java due to its performance, robustness, and widespread use in enterprise applications. Although Python is often favored in the ML community, Java has its own set of powerful tools and libraries for building and deploying machine learning models.

Machine-learning-with-Java

Here’s a comprehensive guide to getting started with machine learning in Java, including setup, libraries, and a practical example.

Table of Content

What is Machine Learning?

Types of machine learning, setting up your development environment in java, installing java development kit (jdk), choosing an integrated development environment (ide), key applications and use cases, getting started with machine learning in java, setting up your development environment, machine learning libraries in java, basic concept of machine learning, data handling and preprocessing, supervised learning, unsupervised learning, model deployment, real-time machine learning, diabites predection projects with java – weka.

Machine learning is a branch of artificial intelligence focused on building systems that can learn from data and improve their performance over time without being explicitly programmed. The primary aim is to develop algorithms that can recognize patterns and make decisions based on data inputs.

  • Classification : Predicting discrete labels, such as determining whether an email is spam or not.
  • Regression : Predicting continuous values, such as forecasting house prices based on various features.
  • Clustering : Grouping similar data points together, like segmenting customers into different categories based on purchasing behavior.
  • Dimensionality Reduction : Reducing the number of features in a dataset while preserving essential information, such as using Principal Component Analysis (PCA) to simplify datasets.
  • Reinforcement Learning : This approach involves training models to make decisions by interacting with an environment and receiving feedback in the form of rewards or penalties. It is often used in areas like game playing and robotics.

To start working with machine learning in Java, you need to have the Java Development Kit (JDK) installed. Download the latest version of the JDK from the Oracle website or adopt OpenJDK. Ensure that the JAVA_HOME environment variable is set correctly and that Java is added to your system’s PATH.

Select an Integrated Development Environment (IDE) that supports Java development. Popular choices include:

  • IntelliJ IDEA : Known for its advanced features and user-friendly interface.
  • Eclipse : A widely used IDE with a robust plugin ecosystem.
  • NetBeans : Offers good support for Java and is easy to set up

Machine learning has broad applications across various domains:

  • Healthcare : Disease diagnosis, personalized treatment plans, and drug discovery.
  • Finance : Fraud detection, algorithmic trading, and risk management.
  • Marketing : Customer segmentation, recommendation systems, and sentiment analysis.
  • Autonomous Vehicles : Object detection, navigation, and decision-making.

To start working with machine learning in Java, you need to set up your development environment. Begin by installing the Java Development Kit (JDK) from the Oracle website. Ensure that your JAVA_HOME environment variable is configured correctly. For development, choose an Integrated Development Environment (IDE) such as IntelliJ IDEA or Eclipse, which provides robust support for Java development.

To manage project dependencies, use build tools like Maven or Gradle. Maven, for instance, allows you to specify machine learning libraries in a pom.xml file:

Java has several libraries to facilitate machine learning tasks:

  • Weka : A toolkit for data mining and machine learning with various algorithms for classification, regression, and clustering.
  • Deeplearning4j (DL4J) : A deep learning library supporting neural networks and big data integration.
  • MOA : Designed for real-time data stream mining.
  • Apache Spark MLlib : Provides scalable machine learning algorithms integrated with Spark’s big data framework.
  • Smile : Offers a range of machine learning algorithms and statistical tools.
  • Data Formats : Common formats include CSV, ARFF, and LibSVM. Use appropriate libraries to load and manage these formats.
  • Preprocessing : Handle missing values, normalize and standardize features, and engineer features to improve model performance.
  • Classification : Algorithms like decision trees and logistic regression are used for tasks like categorizing data.
  • Regression : Techniques like linear regression predict continuous values based on input features.
  • Clustering : Algorithms like K-means group similar data points together.
  • Dimensionality Reduction : PCA simplifies datasets while retaining essential information.
  • Deeplearning4j (DL4J) : Build and train deep neural networks for complex tasks. It supports various network architectures and integrates with big data tools.
  • Saving and Loading Models : Use libraries to serialize models and restore them for use.
  • Integration : Embed models in applications or expose them through web services using frameworks like Spring Boot.
  • MOA : For real-time data stream mining.
  • Apache Spark MLlib : For real-time predictions with streaming data.

1. Load and Prepare the Data

Here’s the Java code for loading and preparing the data:

2. Build and Evaluate a Model

Here’s the Java code for building and evaluating a J48 model:

  • Correctly Classified Instances: The percentage of instances correctly predicted by the model.
  • Incorrectly Classified Instances: The percentage of instances that were misclassified.
  • Kappa Statistic: A measure of agreement between the classifier and the actual labels, adjusting for chance agreement.
  • Mean Absolute Error: The average error per instance.
  • Confusion Matrix: A matrix showing the true positive, true negative, false positive, and false negative counts.

FAQ – Machine learning with Java

1. what is machine learning, and how does it relate to java.

Machine Learning (ML) is a field of artificial intelligence that involves creating algorithms that allow computers to learn from and make predictions or decisions based on data. Unlike traditional programming, where specific instructions are given, ML algorithms identify patterns and learn from data to improve their performance over time. Java is a powerful, object-oriented programming language often used in enterprise applications. While Python is commonly used in the ML community due to its extensive libraries and simplicity, Java offers robust performance, scalability, and integration capabilities, making it a valuable choice for implementing ML solutions in large-scale systems.

2. How Do I Set Up a Development Environment for Machine Learning in Java?

To get started with machine learning in Java: Install Java Development Kit (JDK): Download and install the latest JDK from the Oracle website or use OpenJDK. Ensure the JAVA_HOME environment variable is set correctly and Java is added to your system’s PATH. Choose an Integrated Development Environment (IDE): Popular choices include: IntelliJ IDEA: Known for its advanced features and ease of use. Eclipse: Offers a rich plugin ecosystem. NetBeans: Provides good support for Java and is user-friendly. Use Build Tools: Employ tools like Maven or Gradle for managing project dependencies. For example, Maven allows you to specify machine learning libraries in a pom.xml file.

3. What Are Some Common Challenges When Using Java for Machine Learning?

Java is a powerful language, but there are some challenges when using it for machine learning: Library Ecosystem: Java’s ML library ecosystem is less extensive compared to Python’s. While libraries like Weka, Deeplearning4j, and Smile are useful, Python offers a wider range of mature libraries like TensorFlow and Scikit-Learn. Learning Curve: Java’s syntax and concepts can be more complex and verbose compared to Python, making it harder to quickly prototype and iterate on ML models. Community and Support: The ML community is more vibrant around Python, which means finding help and resources can be easier for Python users. Java has fewer community resources and examples specifically for ML. Integration with Big Data: While Java has strong big data support with frameworks like Apache Hadoop and Spark, integrating ML models with these tools can sometimes be more complex compared to Python’s offerings.

4. What Are the Advantages of Using Java for Machine Learning Compared to Other Languages?

Java offers several advantages for machine learning: Performance: Java is known for its performance and speed, which can be beneficial for large-scale machine learning tasks and real-time applications. Scalability: Java’s robust concurrency model and ability to handle large datasets make it suitable for scalable machine learning solutions, especially when integrated with big data tools. Integration: Java seamlessly integrates with various enterprise systems and databases, which can be advantageous for deploying machine learning models in enterprise environments. Cross-Platform Compatibility: Java’s “write once, run anywhere” capability allows ML models to be deployed across different platforms without modification. Rich Ecosystem: Java has a rich ecosystem of libraries and tools for various applications, including machine learning, data processing, and enterprise integration.

Please Login to comment...

Similar reads.

  • Top Android Apps for 2024
  • Top Cell Phone Signal Boosters in 2024
  • Best Travel Apps (Paid & Free) in 2024
  • The Best Smart Home Devices for 2024
  • 15 Most Important Aptitude Topics For Placements [2024]

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
  • OverflowAI GenAI features for Teams
  • OverflowAPI Train & fine-tune LLMs
  • Labs The future of collective knowledge sharing
  • About the company Visit the blog

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Get early access and see previews of new features.

Does separation of the business logic from presentation logic increase the security?

We can seperate the business logic from presentation logic in jsp .It facilitates to write the java code inside a html environment if we use servlets then we need to write the html tags inside out.write() number of times. In which cases it is not possible to combines the businesslogic and presentation logic? And why it reduces security ?

krupal's user avatar

  • It's always possible. And it doesn't have anything to do with security (although, if the code is a mess, there's a good chance that security handling is like the code) –  JB Nizet Commented Jun 30, 2012 at 7:04
  • There are three questions here. Which are you asking? –  user207421 Commented Jun 30, 2012 at 8:38
  • I read in book that when we combines the businesslogic and presentation logic it reduces security ,is it true ? –  krupal Commented Jul 3, 2012 at 12:14

Know someone who can answer? Share a link to this question via email , Twitter , or Facebook .

Your answer.

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Sign up or log in

Post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

Browse other questions tagged security jsp servlets or ask your own question .

  • The Overflow Blog
  • Best practices for cost-efficient Kafka clusters
  • The hidden cost of speed
  • Featured on Meta
  • Announcing a change to the data-dump process
  • Bringing clarity to status tag usage on meta sites
  • What does a new user need in a homepage experience on Stack Overflow?
  • Feedback requested: How do you use tag hover descriptions for curating and do...
  • Staging Ground Reviewer Motivation

Hot Network Questions

  • Star Trek: The Next Generation episode that talks about life and death
  • How best to cut (slightly) varying size notches in long piece of trim
  • Find the global maxima over the interval [0,1]
  • Largest prime number with +, -, ÷
  • Was the term " these little ones" used as a code word for believers?
  • Why is there so much salt in cheese?
  • Does the USA plan to establish a military facility on Saint Martin's Island in the Bay of Bengal?
  • Light switch that is flush or recessed (next to fridge door)
  • Do all instances of a given string get replaced under a rewrite rule?
  • What other marketable uses are there for Starship if Mars colonization falls through?
  • Convert 8 Bit brainfuck to 1 bit Brainfuck / Boolfuck
  • What should I do if my student has quarrel with my collaborator
  • When can the cat and mouse meet?
  • Why would autopilot be prohibited below 1000 AGL?
  • Can I Use A Server In International Waters To Provide Illegal Content Without Getting Arrested?
  • German and American Driver's License
  • Pressure of a gas on the inside walls of a cylinder canonical ensemble
  • Why do sentences with いわんや often end with をや?
  • How to change upward facing track lights 26 feet above living room?
  • Microsoft SQL In-Memory OLTP in SQL Express 2019/2022
  • How to run only selected lines of a shell script?
  • quantulum abest, quo minus .
  • Is it safe to install programs other than with a distro's package manager?
  • Would an LEO asking for a race constitute entrapment?

business logic and presentation logic in java

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

What is the difference between business and application logic? [closed]

Please note that I asked the same question on stackoverflow but they directed me to ask here.

While I am trying to discerne the difference between the application logic and business logic I have found set of articles but unfortunately there is a contradiction between them.

Here they say that they are the same but the answer here is totally different.

For me I understand it in the following way:

If we look up for the definition of the Logic word in Google we will get

system or set of principles underlying the arrangements of elements in a computer or electronic device so as to perform a specified task.

So, if the logic is set of principles underlying the arrangements of elements then the business logic should be set of principles underlying the arrangements of the business rules , in other words it means the rules that should be followed to get a system reflects your business needs.

And for me the application logic is the principles that the application based on , in other words, how to apply these rules to get a system reflects your business needs, for example should I use MVC or should not I use? should I use SQL or MSSQl?.

So please could anybody help me to get rid of confusion about the difference between the application and the business logic.

  • business-logic
  • business-rules

Mo Haidar's user avatar

  • 3 The answers below the second SO link ( stackoverflow.com/questions/1456425/… ) you gave are correct and comprehensive. In short, they say "Business logic" is a subset of "Application logic". –  Doc Brown Commented Aug 17, 2015 at 13:29
  • 2 ... and the encyclopedia2 link you gave tells IMHO the same, so where is your problem? –  Doc Brown Commented Aug 17, 2015 at 13:35
  • 1 ... and since you decided not to add any clarification, I am voting to close as "unclear what you are asking": –  Doc Brown Commented Aug 17, 2015 at 20:36
  • @DocBrown, I have edited the title of the question and the last paragraph in the question, but I think that it was clear what I wanted and I got the answer!! have you read the question??. –  Mo Haidar Commented Aug 19, 2015 at 9:12

4 Answers 4

I agree with SO's LoztInSpace that this is quite opinionated answer and that everyone can have slightly different definitions. Especially if historical influences are involved. This is how I would define the terms:

Business logic is logic, that is created with collaboration and agreement with business experts. If business expert says that "Customer cannot withdraw more money than he has in his account.", then this is a business rule. In ideal world, this logic would be in some kind of library or service, so it can be either reused across multiple applications or changed in all relevant applications at once.

Application logic is simply everything else. Example can be "clicking this button opens window to add new customer". It has nothing to do with business, but it is still logic that needs to be implemented. In ideal world, application logic will use library or service, that is implementing the business rules. Multiple application, each with different application logic, can reuse one business logic. Imagine web app, web service and mobile app all operating using one business logic, but each clearly need different application logics.

The reason why I think those two get mixed up, is that keeping them separate is extremely hard. Even if you do your most to keep them separate, use cases surface where you have to mix them up. If for example you have all your business logic in service, it keeps it separate. But having some business logic in local application that is using the service might increase responsiveness or user comfort, because the local application doesn't need to call service for every small change.

Another reason why they are mixed together is that for many non-technical people. UI is "the application", so anything reflected in the UI is important. In the ideal "business logic" case, there is no UI. There would probably be suite of automated tests to verify the logic, but nothing that can be shown to business people. So to business people, everything is same kind of "logic". IMO.

Euphoric's user avatar

  • 3 "Application logic is simply everything else" - to be nitty, I would say "it includes business logic and everything else" (but it probably depends on whom you talk to) –  Doc Brown Commented Aug 17, 2015 at 13:31
  • @euphoric I like to add more, the application logic you described consists of two things, UI-specific logic, and Application-specific logic. The Application-specific logic pays about flows and the way you manage situations. It could be changed without changing business logic. the UI logic pays to UI-specific logic that could be changed without changing application logic. Consider removing emails in a mail service. The UX designer may have defined a delayed operation for critical operations. it is not related to the application-specific logic and is defined by the UX designer. –  S.M.Mousavi Commented Mar 25 at 21:58
  • in other words, the business logic is defined by the businessman, application logic is defined by the developer, and UI logic is defined by the UX designer. That is in my mind and my personal approach. –  S.M.Mousavi Commented Mar 25 at 22:01

As others have pointed out, these terms do not have one universally accepted meaning. I will describe the definitions I have encountered more often, i.e. in several projects with different companies.

The business logic defines a normalized, general-purpose model of the business domain for which an application is written, e.g.

  • Classes like Customer , Order , OrderLine , and associations like customer-order , and so on.
  • General-purpose operations such as registerCustomer , cancelOrder

Very often this class model is mapped to a database model and the mapping is implemented using ORM. The operations are normally performed each in their own transaction and provide the basic API for modifying the database, i.e. the persistent state of the application.

The application logic is a layer built on top of the business logic and serves to implement specific use cases. Application logic modules may use ad-hoc data representation, e.g. a CustomerSummary class without any association to Order if you want to list customers only. Such ad-hoc data representation must be mapped to the underlying normalized representation provided by the business model. For example, CustomerSummary can be defined as a view on top of Customer .

Note that the boundary between the two layers may not be so clearly-defined. E.g. after implementing several use cases one might notice similar data structures in the application logic and decide to unify (normalize) them and move them to the business logic.

Giorgio's user avatar

Every system or application is going to have its own definitions of what is business logic and what is application logic. It will either be explicit or implicit.

In my experience data driven applications (e.g. DBs etc.) tend to have a more formal definition of what the business logic is.

The application logic tends to focus on getting information from point A to point B, the business logic centres around what the information is - and the language of the business logic is usually domain specific. Put another way, the application logic is focused on the question "how does it work?", the business logic on "what does it do?" - again, the distinction can be very fuzzy and is more often that not domain specific.

Niall's user avatar

Na, they're just different terms for the same thing - the "middle tier" of program code that does the things you want your program to perform. Like many things in software, there are no hard-and-fast terminology for pieces of a system, as there are no single formal definitions for building systems.

So sometimes people will call it business logic, others application logic, others will call it program logic, its all much of a muchness. Don't bother trying to define this so rigidly, nearly every system varies in how its built so be glad there's only this minor level of vagueness in terminology!

gbjbaanb's user avatar

Not the answer you're looking for? Browse other questions tagged business-logic business-rules or ask your own question .

  • The Overflow Blog
  • Best practices for cost-efficient Kafka clusters
  • The hidden cost of speed
  • Featured on Meta
  • Announcing a change to the data-dump process
  • Bringing clarity to status tag usage on meta sites

Hot Network Questions

  • Getting error with passthroughservice while upgrading from sitecore 9 to 10.2
  • In Lord Rosse's 1845 drawing of M51, was the galaxy depicted in white or black?
  • Does the USA plan to establish a military facility on Saint Martin's Island in the Bay of Bengal?
  • Pattern-matching of monomials
  • Is it safe to install programs other than with a distro's package manager?
  • Light switch that is flush or recessed (next to fridge door)
  • Has any astronomer ever observed that after a specific star going supernova it became a Black Hole?
  • Is the front wheel supposed to turn 360 degrees?
  • Why do the opposite of skillful virtues result in remorse?
  • Microsoft SQL In-Memory OLTP in SQL Express 2019/2022
  • How do I safely download and run an older version of software for testing without interfering with the currently installed version?
  • Are all citizens of Saudi Arabia "considered Muslims by the state"?
  • What are the most commonly used markdown tags when doing online role playing chats?
  • Current in a circuit is 50% lower than predicted by Kirchhoff's law
  • How do we know the strength of interactions in degenerate matter?
  • Why do sentences with いわんや often end with をや?
  • You find yourself locked in a room
  • If a Palestinian converts to Judaism, can they get Israeli citizenship?
  • How do I apologize to a lecturer who told me not to ever call him again?
  • Word for when someone tries to make others hate each other
  • When can the cat and mouse meet?
  • How to securely connect to an SSH server that doesn't have a static IP address?
  • What other marketable uses are there for Starship if Mars colonization falls through?
  • Work required to bring a charge from an infinite distance away to the midpoint of a dipole

business logic and presentation logic in java

COMMENTS

  1. Business-Logic Layer

    In summary, The Business-Logic Layer (BLL) is a component of a software architecture that is responsible for implementing the business logic of an application. It sits between the presentation layer and the data access layer, and is responsible for processing and manipulating data before it is presented to the user or stored in the database. It ...

  2. java

    My first thought was to create an interface that would have all the methods that will be needed by the GUI for the business logic and then have a network implementation and a local implementation. This works fine for request-response messages.

  3. Service Layer Pattern in Java: Enhancing ...

    The Service Layer pattern is crucial for Java developers focusing on building robust application architectures that separate business processes from user interface concerns. The pattern encapsulate business logic in a distinct layer to promote separation of concerns and to provide a well-defined API for the presentation layer.

  4. Architectural Overview

    Architectural Overview - Presentation, Business Logic and Data Access layers. An application system consists of three logical layers. The presentation layer is what a system user sees or interacts with. It can consist of visual objects such as screens, web pages or reports or non-visual objects such as an interactive voice response interface.

  5. architecture

    Before the popular frontend frameworks came into use, e.g. 10-15 years ago, when Java EE and Spring were the most popular, does only a small part of the presentation layer run on client side, and do most of the presentation layer, the entire business logic layer and the entire data access layer run on the server side?

  6. design patterns

    Application logic is logic related to the fact that you are running a computer program. This can be stuff such as CSV import export, wizards, etc. Could also contain stuff like creating forgotten password emails. The kind of "business logic" that you can place in the controller layer is Application logic.

  7. The Business Layer

    The Business Layer. Next in the design process is the task of creating a business layer. This portion of the application is wedged between presentation (what the user sees) and data (what the application depends on). The business layer, then, does just what it implies: it performs business (logic). Data on its own is rarely relevant, and often ...

  8. What is the Business-Logic Layer?

    Conclusion. The business-logic layer is a crucial component of a software application that handles the processing of data and implementation of business rules. It sits between the UI and data access layers and helps to improve the modularity, security, and performance of the application. By using the business-logic layer, developers can build ...

  9. Mixing business logic and presentation layer in enum type

    If you want to decouple Enum and presentation logic, consider using EnumMap. This type of collection is fast and key-safe. IMO, there is nothing wrong to store short and full currency names in CurrencyType. But localized name (as well as country's flag and other visual aspects) better be decoupled and put into presentation layer.

  10. Servlets and JSP Pages Best Practices

    Separation of business logic and presentation logic: You can change the way data is displayed without affecting business logic. In other words, web page designers can focus on presentation and Java developers can focus on business logic. Protects your intellectual property by keeping source code secure.

  11. Presentation logic

    Presentation logic. In software development, presentation logic is concerned with how business objects are displayed to users of the software, e.g. the choice between a pop-up screen and a drop-down menu. [1] The separation of business logic from presentation logic is an important concern for software development and an instance of the ...

  12. java

    Using our current method above we find classes grow very quickly and can become confusing on big projects. There is some debate as to whether we should change our business classes to look like the below: public class CreateOrderBL. {. public void RunLogic(OrderDTO order) {. CreateOrder(); SendEmail(); }

  13. Java Practices->JSPs should contain only presentation logic

    Concise presentations of java programming practices, tasks, and conventions, amply illustrated with syntax highlighted code examples. ... the user interface, the business logic or model, and the database. The underlying reason for this separation is, ultimately, to allow people with different skills to make significant and effective ...

  14. Business logic

    In computer software, business logic or domain logic is the part of the program that encodes the real-world business rules that determine how data can be created, stored, and changed.It is contrasted with the remainder of the software that might be concerned with lower-level details of managing a database or displaying the user interface, system infrastructure, or generally connecting various ...

  15. java

    I suggest checking out UnitOfWork design pattern for the business layer because it suits with the transaction management purposed by Objectify. Briefly summarised, the pattern aims to encapsulate business operations as a whole (unit of work or business transaction). It contextualizes the changes that our business does in the state of the data.

  16. jsf

    2. I've been developing my first Java EE app, which has a number of JPA entity classes, each of which have a corresponding EJB class for dealing with the business logic. What I've done is changed one of those beans from Stateless to SessionScoped, so I can use it to allow a user to work their way through a series of form fields, all of which ...

  17. Why put the business logic in the model? What happens when I have

    ElYusubov's answer mostly nails it, domain logic should go into the model and application logic into the controller.. Two clarifications: The term business logic is rather useless here, because it is ambiguous. Business logic is an umbrella term for all logic that business-people care about, separating it from mere technicalities like how to store stuff in a database or how to render it on a ...

  18. Machine learning with Java

    Machine Learning Libraries in Java. Java has several libraries to facilitate machine learning tasks: Weka: A toolkit for data mining and machine learning with various algorithms for classification, regression, and clustering.; Deeplearning4j (DL4J): A deep learning library supporting neural networks and big data integration. MOA: Designed for real-time data stream mining.

  19. jsp

    We can seperate the business logic from presentation logic in jsp .It facilitates to write the java code inside a html environment if we use servlets then we need to write the html tags inside out.write() number of times. In which cases it is not possible to combines the businesslogic and presentation logic? And why it reduces security ?

  20. What is the difference between business and application logic?

    In my experience data driven applications (e.g. DBs etc.) tend to have a more formal definition of what the business logic is. The application logic tends to focus on getting information from point A to point B, the business logic centres around what the information is - and the language of the business logic is usually domain specific.