Thursday, March 24, 2016

What are JSP implicit objects-

There are 9 JSP implicit objects are following -

-out
-request
-response
-config
-application
-page
-pageContext
-session
-exception

and also you can remember this one through "ORRCAPPSE"

Monday, March 21, 2016

JAVA 8 Features



1. Lambda expression − Adds functional processing capability to Java.
2. Method references − Referencing functions by their names instead of invoking them directly. Using functions as parameter.
3. Default method − Interface to have default method implementation.
4. New tools − New compiler tools and utilities are added like ‘jdeps’ to figure out dependencies.
5. Stream API − New stream API to facilitate pipeline processing.
6. Date Time API − Improved date time API.
7. Optional − Emphasis on best practices to handle null values properly.
8. Nashorn, JavaScript Engine − A Java-based engine to execute JavaScript code.

Monday, February 8, 2016

What are the JAVA 5 features-

Java 5 features are following-

1. for-each loop
2. varargs (variable argument)
3. static import
4. Autoboxing and Unboxing
5. Enum
6. Covariant return type
7. Annotation
8. Generics

Thursday, January 28, 2016

How avoid duplicate user defined object in HashSet

For avoiding duplicate user defined object we need to implement the hashCode and equals method

import java.util.HashSet;
import java.util.Set;

class Employee
{
    int id;
    String name;
    Employee(int id,String name)
    {
        this.id=id;
        this.name=name;
    }
    public int getId()
    {
        return id;
    }
    public String getName()
    {
        return name;
    }

    public int hashCode()
    {
        System.out.println("In hashcode");
        int hashcode = 0;
        hashcode = id*3; //use any prime number
        hashcode += name.hashCode();
        return hashcode;
    }

   public boolean equals(Object obj)
   {
        System.out.println("In equals");
        if (obj instanceof Employee) 
        {
            Employee e = (Employee) obj;
            return (e.name.equals(this.name) && e.id == this.id);
        }
        else 
        {
            return false;
        }
    }
}

  public class HelloWorld
  {
       public static void main(String []args){
       Employee e1=new Employee(1,"Ramesh");
       Employee e2=new Employee(1,"Ramesh");
       Set<Employee> set=new HashSet<Employee>();
       set.add(e1);
       set.add(e2);
       System.out.println("Size = "+set.size());
   }
}

***
Suppose we want to add object based on name only -

        Employee e1=new Employee(1,"Ramesh");
        Employee e2=new Employee(2,"Ramesh");

Here name is same but id is different so how we will avoid this type of duplicate object based on name -

Only hashCode and equals method need to update-

public int hashCode()
 {
        System.out.println("In hashcode");
        int hashcode = 0;
        // only name hashCode require
        hashcode += name.hashCode();
        return hashcode;
 }
   
   public boolean equals(Object obj)
   {
        System.out.println("In equals");
        if (obj instanceof Employee) 
        {
            Employee e = (Employee) obj;
            return (e.name.equals(this.name)); // no need to compare id
        } 
        else
        {
            return false;
        }
    }

Thursday, August 27, 2015

Only Java interview questions.....



Q. What are the JAVA 5 features ?

Q. What are the JAVA 8 features ?

Q. What are JSP implicit objects?

Q. Write a program to print triangle star.

Q. Write a program to calculate the angle between hour hand and minute hand
 (hint: http://www.geeksforgeeks.org/calculate-angle-hour-hand-minute-hand/)

Q. Cyclic inheritance in java possible or not ?

Q. JVM,JRE and JDK

Q. difference between '==' and equals() in java

Q. is servlet is thread safe? How you will make thread safe servlet ?

Q. SingleThreadedModel in java?

Q. Difference between servlet and jsp?

Q. Difference between servlet and struts?

Q. How struts life cyle?

Q. Servlet life cycle?

Q. JSP life cycle?

Q. transient, volatile keyword?

Q. Arraylist travelling ways in java?

Q. serialization interface in java?

Q. how forward to jsp from servlet?

Q. private constructor in java ?

Q. how parse integer value from string example Integer.parseInt("123") any other way to do this ?

Q. difference between hashTable and HashMap

Q. difference between servletConfig and servletContext

Q. difference between fail safe and fail fast iterator in java

Q. difference between Iterator and Enumerator in java?

Q. print collection using iterator and enumerator.

Q. difference between iterator and for each loop to iterate a collection.

Q. difference between comparator and comparable interface.

Q. when ConcurrenModificationException will come ?

Q. page versus pageContext in jsp

Q. page scope in jsp

Q. how deadlock will come in java program ? how to resolve that ?

Q. how you will handle exception in java? (try, catch and finally)

Q. What is use of finally and without catch can we use finally block?

Q. what is POJO class and what is significance of it?

Q. method overloading and overriding ?

Q. can we override final method?

Q. can we overload final method?

Q static method - overloading and overriding

Q. can you overload main method?

Q can you override main method?

Q. How Jdk 1.4 is differ from jdk 1.6 in terms of overriding (covariant return type feature in jdk 1.6)

Q. Difference between ArrayList and LinkedList?

Q. What is hashing, hashcode?

Q. explain internal implementation of hashmap?

Q. difference between interface and abstract class.

Q. in exception handling - how to avoid finally block execution (ans- using system.exit() we can avoid finally block execution)

Q. Exception hierarchy in java- super class in exception hierarchy ?

Q. Difference between checked and unchecked exception with examples.

Q. Write a program for prime number.

Q. Reverse string program without in built function and complexity should be O(n/2)

Q. collection API hierarchy in java.

Q. difference between sendRedirect and forward in servlet.

Q. Design patterns in java.

Q. Java thread class- list all static method of thread class.

Q. different types to create thread in java.

Q. Future Interface in java.

Q. difference between GET and POST

Q. ArratList v/s Set

Q. ArrayList v/s Array

Q. Vector v/s Arraylist

Q. List interface - ArrayList, Vector, LinkedList

Q. Implement a stack program in java

Q. implement Linked List program in java

Tuesday, August 18, 2015

Q. What are the method of Object class.
Ans.
Clone()
equals()
finalize()
getClass()
hashCode()
notify()
notifyAll()
wait()

Sunday, August 16, 2015



Q. What are the OOPS features-
Ans.- Encapsulation, Inheritance, Abstraction, Polymorphism

Q. What is difference between String and StringBuffer-
Ans. String is immutable and StringBuffer is mutable class
        When perform operations on string object, it will create new object, but in case of stringbuffer its will use same instance without creating new object.

Q. Difference between String declaration - String s1="string"; and String s=new String("string");
Ans. First one will create string in string pool and second will create the string object in hash memory.

Q. StringBuffer and StringBuilder
Ans.- StringBuffer and StringBuilder both are mutable
          StringBuffer are having synchronize method and StringBuilder doesn't have any synchonized method.
          StringBuffer are thread safe. StringBuilder are thread unsafe