In this post, I will talk about Java performance Issues briefly.
The output of a Java compiler is a bytecode and not an executable code. The Java Virtual Machine (JVM) interprets the Java bytecode at runtime. Most of the modern programming languages such as C, C++ are not interpreted and compiled to the executable code because of the performance concern. When a program is interpreted, it generally executes slowly when compared with an executable code.
In this article let us see how to use Struts Action Class and forward a jsp file through it.
An Action class in the struts application extends Struts 'org.apache.struts.action.Action" Class. Action class acts as wrapper around the business logic and provides an interface to the application's Model layer. It acts as glue between the View and Model layer. It also transfers the data from the view layer to the specific business process layer and
In this post, I will present an example which will show how to move the selected file (drop down menu) form a servlet to another servlet which performs operations on the file.
I have created 3 Javafiles namely:
- GetImg (Servlet)
- ImgCompare (simpleJava class)
HelloServlet contains a HTML form that has a dropdown menu. Menu contains 2 JPG files. You should have following images at the given path:
In this post, I will write about how Java generics help us in using legacy code.
Generics are new in Java and now developers understand the importance of it and it is being used as required. Question arises, what about the legacy code? Consider an IT firm that is working on an application for 5 years, and they used Java 1.4 for development. They the plan to use 1.5 for development simply because it is better than 1.4. Are they supposed to convert the old code to 1.5 also? This is
Web applications differ from conventional websites in that web applications can create a dynamic response. To make it easier to reference dynamic data from a page, the Struts framework offers a set of tags. Some of the tags mimic standard HTML tag while providing added value. Other tags create non-standard, but useful controls. While HTML provides a simple a tag for creating hyperlinks, the HTML tag often requires us to include redundant information. Also the HTML tag cannot easily access dynamic
Lets make a HelloWorld example using Struts.
Suppose you want to create a simple "Hello World" example that displays a welcome message. To create a "Hello World" example, you need to do three things:
1. Create a server page HelloWorld.jsp to present the messages Java Code: <%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
Updated 11-15-2011 at 07:21 PM by Java Tip
in this post, I will write about how to setup a Struts 2 application from scratch. This will be interesting for the developer who are using Struts for the very first time.
Download the latest struts framework from the http://struts.apache.org. To get started with a new application you can setup a web infrastructure from scratch.
Setup the Web Application File Structure as follows within webapps folder. (This tutorial assumes that you are using Apache Tomcat as a web
Apache Struts is a free open-source framework for creating Java web applications. In this post, I will write about Apache Struts.
In a standard Java EE web application, the client will typically submit information to the server via a web form. The information is then either handed over to a Java Servlet which processes it, interacts with a database and produces an HTML-formatted response, or it is given to a JavaServer Pages (JSP) document which intermingles HTML and Java code to
Designing large sized enterprise applications is a difficult task because the code maintenance becomes difficult as the size of application goes. Model View Controller Architecture presents a solution to this. In this post, I will introduce you to MVC.
Web applications based on JavaServer Pages sometimes mix database code, page design code, and control flow code. In practice, we find that unless these concerns are separated, larger applications become difficult to maintain. One way
Updated 11-14-2011 at 06:57 PM by Java Tip
Taking screenshots in windows is simple and very useful in our day to day business. It is done by pressing the Print Screen key on your keyboard [PrtScn], pasting it in image editor such as MS paint and then editing and saving it. In this post, I will write about how to do this from Java program.
Java provides classes to help us which capturing screens.
java.awt.Robot is used to generate native system input events which can be used to for test automation, and other
Sometimes you want to keep legacy code and for that you have to use older version of Java. These days, people are working in Java 5 and Java 6. But still developers are using legacy code which means using Java 1.3 and Java 1.4. In this post, I will brief you how to change the Java version for projects in Eclipse.
Eclipse provides support for changing the Java version through few clicks. Eclipse 3.3.0 has Java 5.0 configured. So if you do not specify Java version, your project will
Eclipse provides a console window in which you see the output of your Java program. Normally default properties are sufficient and developers are satisfied with it. In some cases, you might want to change the look and feel of the console window. I'll write about this in this post.
The default console looks like this:
Now lets try to change the look and feel. Click
Some times you have a class with concrete methods and you want to declare an interface with all the methods in the class. You may call it backtracking. In this post, I will write about how to do this in Eclipse.
Suppose we have a class called Students that has methods defined in it. We want to generate the interface for it in Eclipse. Simply right click the class name, or simply right click anywhere in the code and select Refactor > Extract interface. A new window will open. Name
Eclipse includes a useful feature called outline. It helps the developer to get a birds eyes view of the class. In this post, I will explore it.
You can display outline panel of your class by Navigate > Show in > Outline.
Outline will show all the methods and fields in the class. It used special symbols for private, public, static fields
While the Eclipse platform is designed to serve as an open tools platform, it is architect so that its components could be used to build just about any client application. The minimal set of plug-ins needed to build a rich client application is collectively known as the Rich Client Platform.
Applications that don't require a common resource model can be built using a subset of the platform. These rich applications are still based on a dynamic plug-in model, and the UI is built using
The presentation of your Rich Client Platform application can be changed using the org.eclipse.ui.presentationFactories extension point.
This example will show how to use the R2.1 presentation, provided by the org.eclipse.ui.presentations.r21 plugin, in the RCP Browser Example application. Here is a screen shot of the browser example using the R2.1 presentation.
This is an example of a simple Eclipse Rich Client Platform (RCP) application. It is a bare bones web browser, using the SWT Browser control.
To load the browser example source into your workspace, load project org.eclipse.ui.examples.rcp.browser from the Eclipse CVS repository.
The code is in package org.eclipse.ui.examples.browser, and consists of an application class (BrowserApp), a workbench advisor for configuring the workbench (BrowserAdvisor),
The definition of a rich client application plug-in starts out similarly to the other plug-ins we've been studying. The only difference in the first part of the markup is that the list of required plug-ins is much smaller than we've been used to. XML Code: <!--?xml version="1.0" encoding="UTF-8"?-->
<!--?xml version="1.0" encoding="UTF-8"?-->
The Eclipse Rich Client Platform (RCP) allows developers to use the Eclipse architecture to design flexible and extensible applications re-using a lot of already existing functionality and coding patterns inherent in Eclipse. Programmers can build their own applications on existing platforms. Instead of having to write a complete application from scratch, they can benefit from proven and tested features of the framework provided by the platform. Building on a platform facilitates faster application
In this post, I will talk about the performance issues related to vector capacity. I have noticed, that normally developers don’t care about the performance issues and declare the vector as: Java Code: Vector vector = new Vector();
Newly created vector has no element in it so its size is 0 but its capacity is 10 by default. So if you don’t specify the capacity of the vector (and call the default constructor), its capacity will be 10. Capacity of the vector is the
Vector vector = new Vector();
Collections can be of a particular type i.e they are only allowed to hold objects of a defined type. This is called “bounded by”. For example: Java Code: ArrayList arrayList = new ArrayList();
Vector vector = new Vector();
We declared an ArrayList and a Vector both bounded by String. We cannot store objects other than String in these. Lets try to store an integer in Vector and see what happens. Java Code: Vector vector = new Vector();
ArrayList arrayList = new ArrayList();
Vector vector = new Vector();
Vector vector = new Vector();
An interface can extend other interface but cannot implement any interface. This makes sense because interface cannot have any implementation. An interface can only contain abstract methods that are implemented by the class implementing that interface.
Lets do this with an example.
Create a package named myinterfaces. Using conventions, package name should be in small case. Now create an interface named InterfaceA with 2 methods. Java Code: package myinterfaces;
LinkedList is a special type of List which is very useful in certain scenarios. Some important facts about LinkedList are:
- It is not synchronized
- It does not use array internally for storage
- It uses pointers internally to point to next node
- It implements Cloneable, List and Serializable interfaces
LinkedList is preferred when you know that you have to add and delete data from the start or from middle of the list. It perform addition and deletion
Interfaces contain abstract methods that implementing class has to implement. It is must for the implementing class to implement all the methods found in the interface. Sometimes you face a situation where you have to implement more than one interface. How to do that?
One way is to simply try to write one interface with all the abstract methods. This is not at all flexible as all of these interfaces might be used in different scenarios. So its better to keep each as a separate interface.
Constructors are used for initialization normally. Name of constructor should be same as that of the class. If no constructor is declared, a default constructor is created without parameters. Constructor does not return any thing.
Consider the example below. ClassB inherits from ClassA. In the MainClass, we made an object of ClassB. Default constructor will be called. But the output suggests that first Constructor of ClassA is called and then the constructor of classB is called.
It has been a problem with open source or community based developments that they provide more options than standards. When we look for java, standard/enterprise java and its development have always remain with standard, but while looking for some web framework in java, we get several names. From MVC based frameworks like Struts, JSF to specialized frameworks like Tapestry, Spring etc. Frameworks with similar and overlapping features making it difficult for a person to choose the best fit. When there
TreeSet belongs to Java Collection Framework and is very rare situations. In this post, I will briefly discuss when to use TreeSet and how to use it.
To use it, you have to import java.util.TreeSet in your class. TreeSet is not synchronized so if a TreeSet is concurrently accessed by threads then thread modifying the contents must be synchronized externally. TreeSet provides following constructors:
Serializable interface has no methods and fields so a class that implementing this interface does not have to override any method. The state of objects of serializable class, can be saved and restored later. The state is saved on a container that may be transient (RAM-based) or persistent (disk-based).
For network communication, the objects that you want to transfer through streams, should be Serializable. For instance, Vector, ArrayList etc implement Serializable interface so their
I have seen a lot of Java guys struggling with accessing a file and playing the data in it. File input output operations are obviously slow as compared to "in memory" operations but then you have persistent data which is of good use. Someone can argue that databases should be used for input and output but then it’s a separate debate. Just to keep it short, I would say that sometimes it is better to use text files for input and out.
In this post, I will write about randomly
Multithreading is a concept where a program is broken into two or more parts called threads and all these threads run in parallel. Multithreading can make programs more responsive and effective and it increases its performance too. For example, today web pages need to display animations with sound effects and text at the same time. If this is done by using the traditional single-threaded event loop, the application will take a lot of time to get loaded, and time is a very crucial factor for web