Stripes - Hello, World!

Stripes is an open source web-application framework used to simplify Java web development. Stripes provides both View and Controllers of MVC architecture and let the developers to port their Model into the system. Comparing to Struts, Stripes is a lightweight and less configuration needed framework, but it provides almost everything provided by Struts. More details about Stripes can be found here.

This tutorial shows you; how to develop a simple web application using Stripes framework in Eclipse.

Prerequisite:
  • Java Development Kit 1.5 or latest
  • Eclipse JEE
  • Apache Tomcat (To add Apache Tomcat to Eclipse, follow this link.)
  • Stripes libraries and other dependencies
  • Basic knowledge in Java Servlets and JSP.
Create a new Dynamic Web Project
Step 1:
In Eclipe goto File → New → Project… and select Dynamic Web Project


Read More

OOP: Polymorphism

This article explains the Object Oriented Concept, Polymorphism. If you are new to Object Oriented Programming, visit to this link and get an introduction about OOP. Polymorphism is the ability of an entity to behave in different forms. Take a real world example; the Army Ants. There are different size of ants in the same ant colony with different responsibilities; workers are in different sizes and queen is the largest one. This is a polymorphic behavior where the entities have a unique feature while they share all other common attributes and behaviors.



Read More

Android Customized ListView

In the last tutorial of Android tutorial series, we developed a simple ListView application. This tutorial enhance the same application by customizing the ListView. After completing this tutorial, you must be able to create a custom Adapter and display customized ListView using that adapter. If you are not familiar with Android ListView, please follow this article and develop a Simple ListView application first, because this tutorial is a continuation of previous tutorial.

Step 1:
Create a new Android project with a package name com.javahelps.sample.customizedlistview and follow the steps given in the Android ListView article to create a basic ListView application. If you are already familiar with ListView, just download the template from this link and continue.

Step 2:
Run your application and test the application. It should list all 23 design patterns and if you click on any design pattern a short description should be displayed.

Step 3:
All these 23 design patterns are divided into three major types which are:
  • Behavioral design patterns
  • Creational design patterns
  • Structural design patterns
Our application should display icons in front of the name of design patterns based on these types. The images I have used are provided at this link. If you are interested download and use them, otherwise find some other suitable PNG images.

Step 4:
(Install the Android Drawable Importer plugin, if you do not have it.) Right click on the drawable folder and select NewScaled Drawable option (This option is provided by Android Drawable Importer plugin).


Read More

Android Drawable Importer

I have recently come to know an amazing plugin for Android Studio, the "Android Drawable Importer". This plugin reduces our effort to import scaled images into the Android project. When I used Eclipse based Android Development Tool, I had to use some third party tools to scale the images. In Android Studio I expected to have a default image re-sizer, but unfortunately there is no such an option and it was slightly hard to import scaled images into the project. This plugin simplifies the job by providing four options to import an image into the project.

This article explains, how to import this plugin into your Android Studio. The complete user guide is available at the Git Hub page of this plugin.

Step 1:
Open your Android Studio and click on the Configure button as shown here.


Read More

Android ListView

ListView is the mostly using component in Android to display any list of items. This tutorial explains the way to create a simple ListView application which displays all 23 design patterns and a short description about each of them. The official Android developers site defines the ListView as:
ListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database query and converts each item result into a view that's placed into the list.
Even though ListView can be used to display the database items, this article uses the ListView to display the data from a String array.

Step 1:
Create an Android project with a project name “ListView Sample” and a package name “com.javahelps.sample.simplelistview”.

Step 2:
Almost always ListView covers the entire screen of your application. Therefore, the parent layout is changed to the FrameLayout. FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other. To change the layout open the activity_main.xml in the XML editor and replace the RelativeLayout by FrameLayout as shown here. If there is a default Hello World TextView, delete the TextView and move to the next step.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

</FrameLayout>
Step 3:
Drag and drop a ListView component from the Container palette to the center of the layout. As shown in the screen shot, drop into the [center, center] location of the FrameLayout.


Read More
Introduction to Interface (with Java 8 Features)

Introduction to Interface (with Java 8 Features)

Interfaces are used in Java to provide a template to developers and to avoid dead diamond problem in multiple inheritance. In an interface all the fields (variables) are by default public, static and final. For an example in the following code both the MIN_SIZE and MAX_SIZE are public, static and final constants.
interface Size {
    int MIN_SIZE = 1;
    public static final int MAX_SIZE = 10;
}
For the complete project click on this link.

Up to Java 1.7 version, all the methods declared in interfaces are public and abstract by default. Since Java 1.8, an interface can have default methods and static methods as well. Therefore, the updated rule is:
An interface can have default methods and static methods. Any other methods are implicitly public and abstract. All the fields declared in an interface are implicitly public, static and final constants.
interface Super {
    /**
     * An abstract method. By default it is public and abstract.
     */
    void print();

    /**
     * Default method, introduced in Java 8.
     */
    public default void doStuff() {
        System.out.println("Hello world");
    }

    /**
     * Static method in interface, introduced in Java 8.
     */
    public static void sayHello() {
        System.out.println("Hello");
    }
}
For the complete project click on this link.

Read More
OOP: Abstraction

OOP: Abstraction

Abstraction is one of the four Object Oriented Concepts. This article briefly explains the concept and the purpose of abstraction. In object oriented programming all the problems are mapped as an interaction of objects. However, there are some real world objects which are just abstract ideas. For example take Vehicle as an object. In real world do we have an object Vehicle? Let me to briefly explain my question. If I say car, in your mind you may have an image of car. If I say motorbike, you may have a mind picture of a motorbike. If I say Vehicle, what kind of image you have in your mind? Nothing, because Vehicle is just a grouping name used in real world. Rather than saying I have a car and a motorbike, I can say I have two vehicles. That is the only purpose of having a term Vehicle.

Read More

Android Activities

Almost all the Android applications need multiple screens. This tutorial explains the way to create multiple activities(screens) in Android Studio. An activity is a combination of a Java class and an XML design. This tutorial uses the same project which is used in the last article. Download the template from this link and continue the development. The given template has the complete GUI and partially completed MainActivity.java.

In the last tutorial, we showed a Toast message during the button click event. In this article we are going to create a new activity and display the order in that new activity.

Step 1:
In the imported sample project, right click on the app folder and select New → Activity → Blank Activity.

Android Activities

Read More

Event Handling

Last Android tutorial, explains the basic layouts in Android. This tutorial covers, the way to add event listeners to user interface components. After completing this tutorial, you must be able to find the user interface components at the runtime using findViewById method, read an input from an EditText, check the status of CheckBox and RadioButton, and handle the click events using OnClickListener.

Step 1:
Download the template from this link. To focus on event handling only, the XML design is already completed in this project.


Read More

Contact Form

Name

Email *

Message *