Thursday, August 9, 2012

java model paper 1

1. What happens if Exception thrown in catch block?
             .

2. Select correct sentence related to "checked Exception" ?
                -Assure the compiler that precautions have been taken using try/catch
                -Compiler cares/concern about these Exception
                -Exceptions must be announce/declared with throws clause
                -Risky code must be wrap with try/catch
                -All

3. How do you create Servlet Instance?
       -Instance creates by servlet container

4. How the data can be trasfered between JSP pages?
      - Session & request objects

5.  Method overriding (in java 5)?
       -overriding method can have a subtype of return type (covarient overriding)

6. Is static method able to call non-static method?
       -No
     
7.   TRUNCATE in sql?
       -TRUNCATE removes all rows from a table.
       -The operation cannot be rolled back and no triggers will be fired.
       -As such, TRUCATE is faster and doesn't use as much undo space as a DELETE.

8.  Is static method allowed in Abstract Class?
        -Yes (calender & Math)

9.  How to acheive session tracking if cookies disabled in browser?
        - response.encodeURL(java.lang.url   url)
          (encode the specified URL by including sessionID in it OR if encoding is not needed
            it returns the URL unchanged)

10.  XmlBeanFactory ?
         -BeanFactory factory = new XmlBeanFactory( new FileInputStream("beans.xml"));
                  MyBean myBean = (MyBean) factory.getBean("myBean");
         - To create an XmlBeanFactory, pass a java.io.InputStream to the constructor.
         - The InputStream will provide the XML to the factory.

11. What is the use of private constructor?
       -out side code can't create a instance
       -
12.   int x=32;
        ArrayList list = new ArrayList();
         list.add(x);
         whats the correct statement below?
               . it works in all the java versions
               . it works below java 5
               . works in java 5 or higher
               . it doesn't work in any versions

13.  Run() method in Thread?
          -can be override(extending Thread class). if not overrided, actual Thread class version of
            Run() will be called but it does nothing
          - can be overloaded
          -overloaded method ignored by Thread class unless you call it yourself
          - calling overloaded method can't create a new call stack

14. select the correct statement for "variables placed in JSP declartion".
        -Multipul threads can access these variables.
        -Value(<%= getDate() %) of variable will be same regardless of how many times page loads.

15.  Collections.sort() ?
         -Sorts the specified list into ascending order,
         -according to the natural ordering of its elements.
         -All elements in the list must implement the Comparable interface
         -e1.compareTo(e2)

16. What's the correct statement to Static Method?
          -static method can't use the non-static variables
          -static method can be called by instances of the class
          -static method is called by class name
          -All above

17. How to add the cookie?
        response.addCookie(cookiename);

18.  what does creating subclass mean?
        -Creating specialized version of more general superclass

19. Below is the JSP declaration
      -<%        %>
      -<%= and %>
      -<%! and %>
      -<%@      %>

20. What the correct statement for constructor?
       -constructor needs to be mentioned explicitly
       -compile create default constructor if no user constructor defined

21. Can we have Action without form?
          -Yes

22. What is circular dependency in Spring?
       -object instatiation depends on each other with constructor injection
       -two objects are calling each other
       -two objects can be called both the directions

23. When to use Static?
      -want to have variables that are common to all objects
      -This is accomplished with the static modifier
      -They are associated with the class, rather than with any object
      -Any object can change the value of a class variable *
      -but class variables can also be manipulated without creating an instance of the class *

24.  DROP in SQL?
       -The DROP command removes a table from the database.
       -All the tables' rows, indexes and privileges will also be removed.
       -No DML triggers will be fired. The operation cannot be rolled back.

25.  How to invoke superclass version of a method from subclass that's overridden the method?
       . using super keyword (super.runreport)

26.  How to create a Thread?
             -2 ways first is extending   java.lang.Thread
              OR implementing Runnable Interface

27.  important ApplicationContext implementations in spring framework ?
          -ClassPathXmlApplicationContext
          -FileSystemXmlApplicationContext
          -XmlWebApplicationContext

28. What is correct statement to Hibernate "Entity"?
         . It must have default constructors
         . It should have getter/setters for all the fields
         . It should not contain static or final fields.
         . Above all
29. JDBC template in Spring?
        context = new ClassPathXmlApplicationContext("xyz-beans.xm.");
         datasource = new context.getBean("mySqlDatasource");
          template = new JdbcTemplate(datasource);
          template.queryForXXX();

30. What happen if constructor is created with return type?
         . then it will become regular method
  
31.  sql DELETE Statement?
       -used to delete rows in a table
       -If you omit the WHERE clause, all records will be deleted!

32. Core interfaces of Hibernate framework?
           -Configuration Interface
           -Session Interface
           -SessionFactory Interface
           -Transaction Interface
           -Query and Criteria Interface

33. What are application context advantages over the Bean factory?
          -application context is global access
          -application context also including entireprize features(i.e transaction, AOP)
          -application context has a more scope
          -above all

34.  wraper class
         -almost all wraper class implements the Comparable, Serializable interface
         -so e1.compareTo(e2) method is present, that's why these wraper classes is
           sorted  in collections(TreeSet)
         -all wraper class has equals & hashcode method

35. What is the wrong statement below?
         . Interface is 100% pure abstract class
         . class extended by only one class, but it impliments many interfaces
         . constructor can be overridden
         . interface methods are implicitly public & abstract

36. How many ways spring bean gets instatiated?
           -2 ways(static factory method, instance factory method)

37. How to create a session?
         HttpSession session=req.getSession(true);
         String sessionID=session.getId();
        -returns the current session associated with the request. OR if request doesn't have
          a session, create one

38.  Is it possible to create a regular method with Class name?
           .Yes (it should have return type)
39.  BeanFactory?
        - root interface for accessing a Spring bean container.

40.  What are the things needed for the socket connection?
          - IP address & TCP port
41.  How to find number of records in a table?
        - select count(*) FROM persons;
42.  compare(T o1,T o2) method in Comparator interface?
         -Compares its two arguments for order.
         -Returns a negative integer, zero, or a positive integer
         -as the first argument is less than, equal to, or greater than the second

43. Write a code for random number which should be between 0 to 5?
                int rand= (int) (Math.random() * 5);
44.  BeanFactory?
         -A BeanFactory is an implementation of the factory pattern that applies Inversion of Control to   separate the application’s configuration and dependencies from the actual application code.

45. m1() mehtod is overridden in subclass. how to call super calss version of m1() method from the
         instance of subclass?
             superclasstype    xy= instance;
                  superclasstype.m1();
46.  e1.compareTo(e2)
        -less than zero - invoking object less than parameter object
       
47.  What to use to get int value of String?
         Integer.parseInt();

48.   JdbcTemplate?
            -inject datasource object into JdbcTemplate
              then inject JdbcTemplate into DAO

49. Comparator
         -The Comparator is needed if you have an object
           which does not implement the Comparable interface.

50. What is the worng statement for servlet?
       . servlet instance is created for each request
       . only one servlet instance is created regardless of how many requests made
       . servlet is not thread safe (multiful threads run on single instance)



      



No comments:

Post a Comment