Posts

Featured Post

HOW TO ACCESS SESSION IN STRUTS 2 WITH EXAMPLE

Some of my friends are confused, how to deal with session in struts2, because struts 2 is Servlet API independent. We will try to understand all possible way to deal with session. You can obtain the session attributes by asking the ActionContext or implementing SessionAware. Implementing SessionAware is preferred. Using ActionContext: getContext()  static method of ActionContext return instance of ActionContext, on which getSession() method  is called which return Map of HttpSession value. Map attmap = ActionContext.getContext().getSession(); Now get(), put() and remove() method of Map is used for getting, putting and removing attribute in session scope.

Singleton design pattern

S ingleton pattern is a design solution where an application wants to have one and only one instance of any class.It saves memory because object is not created with each request. Only single instance is reused again and again. But how to make any class singleton is not so easy task, because there are several way in which singleton can break. Steps: 1.       Make constructor private, so not directly instantiated class 2.       Make a static method which produce existing instance if one available else new 3.       Override clone() method. One cannot create a cloned object which also violates singleton pattern. 4.       If Singleton is class is serializable then once it serialized again deserialized it, but it will not return singleton object.

Difference between Java 8 interface and Java 7 interface

Before Java 8, interface having only abstract methods that means method without body (implementation). But Java 8 interface can contain abstract method as well as default implemented method and interface level method (static method). That means now in Java 8 interface can contain three types of methods.

A new date and time API has been designed for Java SE 8.

There are several problems with existing Date and Time API some of them are- 1. The existing classes (such as java.util.Date and SimpleDateFormatter) aren’t thread-safe 2. Poor API design. E.g. years in java.util.Date start at 1900, months start at 1, and days start at 0.

Simple Chat Application Using Applet

Image
1. Client.java package chatterapi; /*   @navindra k. jha   */ import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.net.*; import java.io.*; public class Client extends Applet implements ActionListener, Runnable {         Image Icon = Toolkit.getDefaultToolkit().getImage("D:/Example/emperian/jsf/ChatterAPI/src/chatterapi/hi.gif") ;

Hit Counter for a Web site, time of hitting and no. of current users

Many times you would be interested in knowing total number of hits of your site, time of hitting, and number of users currently using your site. This post is about creating a hit counter that counts number of site visit. There are various ways for creating hit counter in servlet but here we have implemented hit counter using ServletContextListener.   ServletContextListener is a listener interface that gets notified when the context is initialized and destroyed . index.html <body>         <form name="loginForm" method="get" action="LoginServlet">             Username<input type="text" name="txtname" size="20"><br>             Password<input type="password" name="txtpass" size="20"><br>              <input type="submit" value=...

How to export data from database to excel sheet

It is very simple to import data from database to Excel, follow below steps I have “student” table in “stu” database and book1.xlsx excel file in x drive. Student table has three field name, roll, and marks Before importing data you must have an Excel file in which data is imported and specify field name in cell like NAME, ROLL, and MARKS in different cells. NAME ROLL MARKS I am using MySql database.

Abstraction and Encapsulation

In an object-oriented programming language   Encapsulation and Abstraction are very confusing words, everyone feels confused to understand. Here I give in my own style of explanation. Abstraction:   The essential characteristics of an entity that distinguishes it from all other kinds of entities. In other word, “Only the characteristics of the system that are essential to the problem being studied are modelled; minor or irrelevant details are ignored.”   It defines a boundary relative to the perspective of the viewer. It allows us to manage complexity by concentrating on the essential characteristics of an entity.