Saturday, August 13, 2011

Java Inner Class

/*
*
*
*/
package com.blx.learn.java.core.innerclass;

/**
* This is an example Java Inner class which demonstrate various Inner classes
* available
*
* @author Nanjundan Chinnasamy
* @version 1.0
*
*/
public class LearnInnerClass {

/**
* This is a sample Member Inner class defined inside a class
*
* This inner class is instance specific to the outer class
* (LearnInnerClass). Object can be created for this class using Outer class
* object.
*
* @author Nanjundan Chinnasamy
* @version 1.0
*/
class MemberInnerClass {

/**
* Member class method
*/
public void testMethod() {
System.out.println("This is member class testMethod method");
}

/**
* Static class method
*/
public void memberlassMthd() {
// To access member class method
this.testMethod();
// To access outer class method
LearnInnerClass.this.testMethod();
}
}

/**
* This is a sample Static Member Inner class defined inside a class. Member
* class defined as static. Like other static methods, member class has
* access to all.
*
* @author Nanjundan Chinnasamy
* @version 1.0
*
*/
static class StaticMemberInnerClass {

/**
* Static class method
*/
public void testMethod() {
System.out.println("This is static class testMethod method");
}

/**
* Static class method
*/
public void staticMemClassMthd() {
this.testMethod();
}

}

/**
* Method to testMethod local Inner class
*/
void localClassMethod() {

/**
* This is local class exists inside the method. This can be reference
* only within this method.
*
* @author Nanjundan Chinnasamy
* @version 1.0
*
*/
class LocalInnerClass {
public void testMethod() {
System.out.println("This is local class testMethod mthod.");
}
}
// To access local class methods
new LocalInnerClass().testMethod();
// To access outer class methods
testMethod();

}

/**
* Method to testMethod anonymous inner class
*
*/
void anonymousClassMethod() {

/**
* Anonymous Inner class declared inside a method without any name. JVM
* will create its own name during the compile time.
*
* Such implementation might required the places where to create an
* object instances w/o creating sub class and override their methods
*
* @author Nanjundan Chinnasamy
*
* @version 1.0
*/
Runnable runnable = new Runnable() {
@Override
public void run() {
System.out.println("This is anonymous inner class");
}
};
Thread thread = new Thread(runnable);
thread.run();
}

/**
* This is an out class testMethod method
*/
void testMethod() {
System.out.println("I am outer class testMethod method");
}

/**
* @param args
*/
public static void main(String[] args) {

// This is for static member class
LearnInnerClass.StaticMemberInnerClass staticMemberInnerClass = new StaticMemberInnerClass();
staticMemberInnerClass.staticMemClassMthd();

// This is for member class
MemberInnerClass memberInnerClass = new LearnInnerClass().new MemberInnerClass();
memberInnerClass.testMethod();

// This is for Local Inner class
LearnInnerClass outerClassForLocInnTst = new LearnInnerClass();
outerClassForLocInnTst.localClassMethod();

// This is for anonymous inner class
LearnInnerClass outerClassForAnomysClassTst = new LearnInnerClass();
outerClassForAnomysClassTst.anonymousClassMethod();

}

}


Output:
This is static class testMethod method
This is member class testMethod method
This is local class testMethod mthod.
I am outer class testMethod method
This is anonymous inner class

Tuesday, June 14, 2011

Way to Prevent Duplicate Request from Form in J2EE applications -2

Guys,

Here is the another solution to prevent duplicate form submission issue in web applications irrespective of the framework implementation.

Can you please try with the below code and update me in comments?

In JSP, we can have java script method during onsubmit like below.


And our java script implementation would be like below. submitForm method return true only very first time and form will be submitted. The same will be true for the sub sequent requests. Hope this will solve our issue.

//Global variable
var submitFlag = 1;

//Submit form method
function submitForm(form) {
if ( submitFlag == 1 ) {

submitFlag = 2;
return true;

} else {
return false;

}
}


Thanks,

-Nanjundan Chinnasamy

Way to Prevent Duplicate Request from Form in J2EE applications -1

Way to Prevent Duplicate Request from Form:

Here is the common and widely used mechanism used to preventing duplication form submission from a j2ee application. Ie, disabling the submit button during on click event. Example here is ICICI bank Internet banking application.

Though this is simple and a reasonable approach if we have a single submit button within a form, this may not work if we have more than one submit buttons in a form.

Are you looking for any other simple strategy to prevent duplication form submission from client side? Follow the next blog.

Cheers,
-Nanjundan Chinnasamy

Monday, October 5, 2009

Schedule a reoccur Task(s) using Java

Going forward(from today!) I am planning to write some technical blogs related to JAVA Technology. First, we might aware of Job Scheduling. I am sure all the projects require some job scheduling. Here is the sample example on Job Scheduling using Java Program:JobSchedule.java has main method and act as a gateway for this Scheduler Task example which will call schedule method in Timer Class(Available from JDK1.3). schedule method will take 3 arguments. First will the scheduled task to be perform and second will be the scheduled task to be called and third will be the scheduled time interval (all are in milli seconds). The scheduled task should extend the TimerTask class and the same needs to be override run method will perform the task.
In the below task whenever JobSchedule.java gets called, after 1 sec PrintTask gets called and you will be getting the output called "Calling PrintTask usinf JAVA Scheduler..". You will be getting the same o/p every 5 secs.

JobSchedule.java
package com.blx.jobSchedule;
import java.io.*;
import java.util.Timer;

public class JobSchedule {
private Timer timer;public JobSchedule() {
timer = new Timer();
}public static void main(String[] args) throws IOException {
JobSchedule jobSchedule = new JobSchedule();
// Test to be performed on schedule
// Inital/start schedule time or when to start
// Fixed time interval or schedular time
jobSchedule.timer.schedule(new PrintTask(), 1000, 5000);}
}


PrintTask. java
package com.blx.jobSchedule;
import java.util.TimerTask;
public class PrintTask extends TimerTask {
public void run() {
System.out.println("Calling PrintTask usinf JAVA Scheduler..");
}
}

Wednesday, September 23, 2009

How to survive during Global Recession….

For all people, here are some tips how to survive during Global Recession as a software Engnieer..
1. Automate the Manual JOBS and TestCases
Hope this could easily be implemented in any kind of project.
· Automating Jobs: First try to find out the list of manual jobs if any (Ex. Build process). Automate them first. We can take the build process for example. People working in Development project well be aware of the build process. We have ‘n’ number of open source tools to automate the build process. Examples are anthel Pro, cruse Control Build. So whenever you checkin code to versioning system build is automatically started and placed in some share location. So we can avoid some/much time in taking a build.
· Automating TestCases: Create automated test cases for your applications. That should run before taking the build (This can be done with any build tool like Maven/Ant). If you are a JavaDeveloper, use JUNIT to write testcases for Java Layer and Cactus/StructTestcase/Shale/JSFTestcase for web component test cases. Yes we can test without container for webcomponents. Are you .net user? Use NUnit (That is the only thing I heard).
· Of course we can use PMD/Check Style to automate the code review. In general if anything takes more of your time, try to automate those.
2. Implement Scrum model in your Project: Currently most of them are working in water flow model. This will be taking considerable time(min 3 months) to complete one release if it is very small. So the user or Quality Assurance team should wait till this TAT(Turn Around Time) to see the implementation. I could see we are not able to satisfy the clients with this model. This is the reason we can go for Scrum model. In scrum model the only difference is TAT, yes it is very small (2-3 weeks). We are giving the updates/release on every 3 weeks. By doing so we could satisfy most of our clients however they can see their requirement implementation (hopefully before the billing cycle). Need more details on scrum model? Visit here: http://en.wikipedia.org/wiki/Scrum_(development)
FYI: All the project can’t follow Scrum model. It depends on the type of the project and Client, of course!
3. “Out of the box” Implementation: This we all know and have heard word from managers. Yes we should understand the business, try to find out loop holes/ area of improvements where we can save the money. Not for us guys! For client!
We implemented all of these in our project. it’s cool and going smooth.
Hope you guys do the same to make business different. I am sure you can feel the difference.
All the best!!!

Pega Decisioning Consultant - Mission Test Quiz & Answers

The Pega Certified Decisioning Consultant (PCDC) certification is for professionals participating in the design and development of a Pega ...