Moneycontrol Buzzing Stocks

Friday, June 13, 2008

J2EE Design Patterns

Design Patterns are the best practice solutions to common recurring problems.

Some of the well known Design Patterns.
  • Session Facade
  • Mesage Facade
Session Facade

Problem description: - In J2EE environment there are some problems arise, There is direct dependence between the client and Business objects, Too many method invocations between client and server leads to network performance problems., Lack of uniform client access strategy, exposing business objects to misuse
Solution: - Use a session bean as a facade to encapsulate the complexity of interactions between the business objects participating in a workflow. The Session Facade manages the business objects, and provides a uniform coarse-grained service access layer to clients. The Session Facade abstracts the underlying business object interactions and provides a service layer that exposes only the required interfaces. The Session Facade manages the interactions between the business data and business service objects that participate in the workflow, and it encapsulates the business logic associated with the requirements.
  • When implementing the Session Facade, you must first decide whether the facade session bean is a stateful or a stateless session bean. Base this decision on the business process that the Session Facade is modeling.
  • A business process that needs only one method call to complete the service is a nonconversational business process. Such processes are suitably implemented using a stateless session bean.
  • A business process that needs multiple method calls to complete the service is a conversational business process. The conversational state must be saved between each client method invocation. In this scenario, a stateful session bean may be a more suitable approach for implementing the Session Facade.
Message Facade

Problem
:- Session bean and entity bean methods execute synchronously that means the method caller has to wait till a value is returned. In some situations like sending hundred's of mails or firing a batch process or updating processes, the client does not have to bother about return value. If you use synchronous session and entity beans in such situations, they take a long time to process methods and clients have to wait till the method returns a value.

Solution: - To avoid blocking of a client, use asynchronous message driven beans, so that client does not have to wait for a return value. If a client uses asynchronous messaging then the client need not wait for a return value but can continue its flow of execution after sending the message.
Here the client sends a message to JMS server, gets acknowledgement from the JMS server immediately in two step process and continues it's flow of execution. Whereas JMS server delivers the messages to Message driven bean (Message Facade) without blocking client's execution and Message driven bean executes messages. You can use normal JMS consumers instead of Message driven beans. This process improves performance by reducing the client's blocking time considerably.

Thursday, May 29, 2008

Collection FrameWork

A collection is simply an object that groups multiple elements into a single unit. Collections are used to store, retrieve, manipulate, and communicate aggregate data.


  • HashMap :- Hash table based implementation of the Map interface.
    • Permits null values and the null key.
    • It is unsynchronized.
    • This class makes no guarantees as to the order of the map.
    • Since it is unsynchronized to make synchronized use following
         Map m = Collections.synchronizedMap(new HashMap(...));
  • HashTable :
    • Null vaule and Key not allowed.
    • To successfully store and retrieve objects from a hashtable, the objects used as keys must implement the hashCode method and the equals method.
    • Hashtable is synchronized.

  • Comparable and Comparator :- An implementation of the Comparable interface allows the user to create a specific strategy to compare with another object(which should be mutually comparable).The Comparator on the other hand doesn't tie you with a single comparison strategy.
    • Comparable interface has “compareTo” method which is normally used for natural ordering but Comparator interface has “compare” method which takes two arguments. It can be used where you want to sort objects based of more then one parameter.
    • The java.util.Collections class has an overloaded sort method(i.e. other than sort(List) that accepts a List and a Comparator as an argument.
    • Sample Code :-
    • 1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      public class Employee implements Comparable
      {
      private String name;
      private int age;

      public Employee(String name, int age)
      {
      this.name = name;
      this.age = age;
      }

      public int compareTo(Employee e)
      {
      //Write the code for sort.
      }


      }

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      public class Main
      {
      public static void main(String[] args)
      {
      List employeeList = new ArrayList();
      employeeList.add( new Employee("Ranga", 10) );
      employeeList.add( new Employee("Madhu", 11) );
      employeeList.add( new Employee("Babu", 12) );

      Collections.sort(employeeList);

      }

  • Vector and ArrayList

    • Arraylist is not synchronized while vector is.
    • Arraylist has no default size while vector has a default size of 10.
    • Arraylist don't define any increment size while vector does.
    • Arraylist can be seen directly without any iterator while vector requires an iterator to display all it's content. (not very sure).
    • Sometimes Vector is better; sometimes ArrayList is better. Chose based on your requirement. If u don't need thread-safe collection, then use the ArrayList.
    • A Vector defaults to doubling the size of its array, while the ArrayList increases its array size by 50 percent. Depending on how you use these classes, you could end up taking a large performance hit while adding new elements. Vector does possess a slight advantage since you can set the increment value.
    • Traversing an ArrayList is since you can simply use an index instead of having to create an iterator.

Wednesday, May 28, 2008

10 Commandments for Java Developers

While searching for java Coding standards in Google I found following 10 Commandments from www.developer.com web site and found very useful. Let me brief about them.
  1. Add comments to your code.
  2. Do not complicate things
  3. Keep in Mind – "Less is more" is not always better.
  4. No hard coding please.
  5. Do not invent your own frameworks.
  6. Say no to Print lines and String Concatenations.
  7. Pay attention to the GUI.
  8. Always Prepare Document Requirements.
  9. Unit-test. Unit-test. Unit-test.
  10. Remember – quality, not quantity.

Pls go through complete details from the bellow link for detailed description given by the Aleksey Shevchenko (Author) .I hope these rules will help all of us become better programmers and professionals.

Link : http://www.developer.com/java/data/article.php/10932_3612756_1

Tuesday, May 27, 2008

Core Java Rare Questions.

1) How to redirect System.out.println() output to file or some other out stream?

By default SOP(System.out.println) prints out put on console. It is possible to redirect out put to some other file. See following sample code.

package jobset_qa.jobs;

import java.io.FileNotFoundException;
import java.io.PrintStream;

public class PrintToFile
{
public PrintToFile() { }

public static void main(String argv[]) throws FileNotFoundException
{
System.out.println("This will be printed in console..");
PrintStream fileout=new PrintStream("systemoutput.txt");
System.setOut(fileout);
System.out.println("From now.. the messages would be systemoutput.txt");
System.out.println("You ust be seeing this message in systemoutput.txt file");
}
}


Polymorphism :-Means one name, many forms.This can be achived in following two ways.

  • Method overloading : overload differs in the number or type of its arguments. Differences in argument names are not significant. A different return type is permitted, but is not sufficient by itself to distinguish an overloading method.
  • Method Overriding : override has identical argument types and order, identical return type, and is not less accessible than the original method. The overriding method must not throw any checked exceptions that were not declared for the original method."

There are two farm of polymorphism

  • Compile-time polymorphism
  • Runtime polymorphism

Compile-Time Polymorphism :- Method overloading as a form of compile-time polymorphism. Compiler determines which method (from a group of overloaded methods) will be executed, and this decision is made when the program is compiled.

Runtime Polymorphism : - This is based on method overriding. The decision as to which version of a method will be executed is based on the actual type of object whose reference is stored in the reference variable, and not on the type of the reference variable on which the method is invoked.This is sometimes referred to as late binding.

Sample Code :-

class A extends Object{ //Super Class
public void m(){
System.out.println("m in class A");
}//end method m()
}//end class A
class B extends A{ // Sub Class
public void m(){
System.out.println("m in class B");
}//end method m()
}//end class B

public class Poly03{
public static void main( String[] args){
Object var = new B();
((A)var).m(); }}
The Method Output is : m in class B

This confirms that even though the type of the reference was converted to type A, (rather than type Object or type B), the overridden version of the method defined in class B was actually executed.

Monday, May 26, 2008

JSP - Concepts

JSP Lifecycle:

Translation Phase: JSP Page will be converted to Servlet.

Compilation Phase: The resulting servlet is compiled.

Instantiate and loading Phase: Instance will be created for the servlet ands it will be loaded to memory.

Call jspinit():Perform Initialization process.

Call _jspService(): this will be called upon each request.

Call jspDestroy(): the instance will be destroyed when not needed any more.

Friday, May 23, 2008

Simplified Struts concepts

  • A request comes in from a Java Server Page into the ActionServlet.
  • The ActionServlet having already read the struts-config.xml file, knows which form bean
    relates to this JSP, and delegates work to the validate method of that form bean.
  • The form bean performs the validate method to determine if all required fields have been
    entered, and performs whatever other types of field validations that need to be performed.
  • If any required field has not been entered, or any field does not pass validation, the form bean generates ActionErrors, and after checking all fields returns back to the ActionServlet.
  • The ActionServlet checks the ActionErrors that were returned from the form bean’s validate method to determine if any errors have occurred. If errors have occurred, it returns to the originating JSP displaying the appropriate errors.
  • If no errors occurred in the validate method of the form bean, the ActionServlet passes
    control to the appropriate Action class.
  • The Action class performs any necessary business logic, and then forwards to the next
    appropriate action (probably another JSP).

Wednesday, May 7, 2008

Software Tester Skills

There are three categories of skill that needed for any software tester.
  • Testing skill
  • Domain knowledge
  • Technical expertise.

Any tester should have the basic testing skills like Manual testing and Automation testing. Tester having the common sense can even find most of the obvious bugs in the software.While testing any application tester should think like a end-user.

When tester know the functional domain better , then he/she can better write and execute more test cases and can effectively simulate the end user actions which is distinctly a big advantage.

Here is the big list of the required testing knowledge:

  • Testing skill
  • Bug hunting skill
  • Technical skill
  • Domain knowledge
  • Communication skill
  • Automation skill
  • Some programming skill
  • Quick grasping
  • Ability to Work under pressure …
It is very difficult to have all the above skills.But you can stick to one skill or can be expert in one skill and have good understanding of other skills or balanced approach of all the skills. This is the competitive market and you should definitely take advantage of it. Make sure to be expert in at least one domain before making any move.

If tester don’t have enough domain knowledge of that project they need to quickly grasp as many concepts .Try to understand the product as if you are the customer and what customer will do with application. Visit the customer site if possible know how they work with the product, Read online resources about the domain you want to test the application, participate in events addressing on such domain, meet the domain experts. Or either company will provide all this in-house training before assigning any domain specific task to testers.

Friday, May 2, 2008

Team leader roles

  1. As a team leader you are responsible for project planning, scheduling, communicating your project status to your manager and most important task of assigning and monitoring the project work.
  2. Your main responsibility is to build a team to achieve your project goals.
  3. You need to focus on handling the challenges in your project so that your team and project will grow and perform well.
  4. Ensuring project plan changes are incorporated in test plan. You might write a test plan and test strategy (In some cases it might be written by senior test team member or even by project test manager) Ensure the work is going according to this test plan. Identify the risks and try to mitigate them. At the end of project testing life cycle ensure that all test objectives are accomplished and acceptance criteria is met.
  5. More TL responsibilities includes: Test Case Review, Requirements Validation, Monitoring the execution of manual and automated test cases, Prepare test summary report and Communicate test status to seniors and prepare corresponding documents.