Tagged: #java

How to setup java on unix

This is a step-by-step guide to install java (JRE) on unix machine. Step-1 Download Java Download the appropriate tar.gz JRE package from oracle, choose the package which suits your system specifications (x86 for 32 bits) (x64 for 64 bits) and copy it to your user directory .i.e. /home/PG P.S: if you install x86 version on 64 bit environment, java may not consume the...

How to setup java on windows

This is a step-by-step guide to install java (JRE) on windows machine. Step-1 Download Java Download the appropriate JRE package from oracle, choose the package which suits your windows specifications (x86 for 32 bits) (x64 for 64 bits). P.S: if you install x86 version on 64 bit environment, java may not consume the dedicated amount of memory, it happened to...

Pass data from html to servlet

In this tutorial we explain the common way of passing data from html to java servlets, we mostly focus on passing form data entered by end-users through pages like: login, sign-up, contact-us .. 1. Pass form fields to servlet Consider the following login.html:

Users interact with web applications through forms, the “form” element is the common way for asking end-users...

JSP – Hello World Tutorial

In this tutorial, we provide a step-by-step guide for creating a hello world web application using JSP technology. Prerequisites: Eclipse IDE (Mars release) Java 1.7 Apache tomcat 7 1. Create dynamic web project Open eclipse, then select File -> New -> Dynamic Web Project. In the next screen, fill the mandatory fields as above, you are free to choose any...

Servlet 3.0 – Hello World Tutorial

In this tutorial, we provide a step-by-step guide for creating a hello world web application using Servlet 3.0 technology. Servlet 3.0 supports defining and exposing servlets using annotations, if you still love to define servlets manually, refer to our previous tutorial about creating web applications using servlet 2.5. Prerequisites: Eclipse IDE (Mars release) Java 1.7 Apache tomcat 7 1. Create...

Servlet 2.5 – Hello World Tutorial

In this tutorial, we provide a step-by-step guide for creating a hello world web application using Servlet 2.x technology. Prerequisites: Eclipse IDE (Mars release) Java 1.7 Apache tomcat 7 1. Create dynamic web project Open eclipse, then select File -> New -> Dynamic Web Project. In the next screen, fill the mandatory fields as above, in case you didn’t previously...

StringBuilder VS StringBuffer

Since String is immutable, it is very costly to use it when constructing a dynamic character string due to the fact that a new memory location will be allocated at each assignment or modification. Since its first release, Java supports a mutable class called StringBuffer which constructs dynamic character strings through allocating just 1 memory location, this saves a lot...

Java try-with-resources

Java 7 supports a new statement called try-with-resources which extends the behavior of the traditional try/catch block for the sake of automatic resource management, since Java 7 developers are able to access resources (files, db connections, sockets) inside a try-with-resources block without the need to worry about closing them afterwards, the resource closure is done automatically. 1. Resource management using traditional...

Exception handling strategy

In this article we introduce a common strategy for handling exceptions in an OOP application, our strategy conforms to the best exception handling techniques and can be integrated in any application. 1. Overview The following diagram provides an overview of our strategy, it shows the flow of the exception starting from the detection phase until reaching the handling phase. The...

How to use exceptions effectively

Exception is an event which occurs during the execution of a program and disrupts its normal flow, it is mainly arised from different kind of situations such as wrong user interaction, hardware failure, network failure, database failures or even business failures. 1. Checked vs Unchecked Exceptions are of 2 types: checked and unchecked. Checked exceptions are predictable during the development...