Tesco Java Questions: Java Questions Part 1Tab.Amp

Examrace Placement Series prepares you for the toughest placement exams to top companies.

  1. Which of the following 2 methods executes faster? class Trial { String _member; void method1 () { for (int i = 0; i<2048; i + + ) { _member + = “test” } } void method2 () { String temp; for (int i = 0; i<2048; i + + ) { temp + = “test” } _member = temp; } }

    1. method1 ()

    2. method2 ()

    3. Both method1 () and method2 () takes same time for execution

    ANS: (b)

    Accessing method variables requires less overhead than accessing class variables.

  2. Integer. ParseInt ( “12a” ) returns

    1. Exception

    2. 1

    3. 0

    4. -1

    ANS: (a)

  3. By default, Strings to functions are passed using the method

    1. Call by Value

    2. Call by Reference

    3. Strings cannot be passed to function

    ANS: (b)

    String is a class defined in java. Lang and in java all classes are passed by reference.

  4. What is the difference between OVERRIDING and OVERLOADING

  5. What is the output of following program? class Test { public static void main (String args[]) { for (int i = 0; i<2; i + + ) { System. Out. Println (i--); } } }

    1. Goes into infinite loop

    2. 0, 1

    3. 0, 1, 2

    4. None

    ANS: (a)

  6. ‘t’ is the reference to a class that extends THREAD. Then how to suspend the execution of this thread?

    1. t. Yield ()

    2. yield (t)

    3. yield ()

    4. yield (100) where 100 is the milli seconds of time

  7. What is the functionality of instanceOf ()?

  8. How many String objects are created by the following statements? String str = “a + b = 10” trim (str) str. Replace ( +,)

    1. 1

    2. 2

    3. 3

    4. 4

    ANS: (c)

    Strings are immutable. So, for each String operation, one new object is generated.

  9. (A program is given. I don't remember exactly) An ABSTRACT class is declared and the code is tried to instantiate it. The Question was whether it's legal to do it or not?

  10. A question on “interface”

  11. Cleaning operation in Java is done in the method

    1. finally ()

    2. finalize ()

    3. final ()

  12. Question on whether Static method can be overriden

  13. How to prevent a class from being the Base Class?

    1. declare it as final

    2. declare it as static

  14. If we want to read a very big text file with so many mega bytes of data, what shall we use?

    1. FileInputStream

    2. InputStreamReader

    3. BufferedReader

  15. One Question on Inner Classes.

  16. One program on Overloading and Overriding

  17. A program given using try, catch and finally and it is asked to find out which statements get executed?

  18. What code, if written, below the (//code here) will display 0. Class Test { public static void main (String argv[]) { int i = 0;//code here } }

    1. System. Out. Println (i + + )

    2. System. Out. Println (i + ‘0’ )

    3. System. Out. Println (i--)

    4. System. Out. Println (i)

    ANS: (a) (c), (d),

    The option (b) displays the ASCII value of ‘0’ So, the output in this case is: 48

  19. What is the better way of writing the Constructor with 2 parameters in the following code: Class Test { int x, y; Test (int a) {//Code for very complex operations will be written//in this place x = a; } Test (int a, int b) {//Code for very complex operations will be written//in this place (same code as in above constructor) x = a; y = b; } } 2 Table Structures are given (Something like Employee ID, Salary, Department etc). And there are 3 queries. I remember one query. Write query to find the employees with top 5 salaries? And there 2 more theoritical SQL questions What is the difference between UNION and UNION ALL? What is the difference between COMMIT and ROLLBACK?

Technical Interview

  1. Tell about yourself

  2. Why do you want to leave the present company?

  3. What do you know about our (Manhattan Associates) company?

  4. About EJB types. CMP, BMP, Session, Entity beans, their differences, when to use what type of beans?

  5. Can a Client Context call ejbRemove () method?

  6. Who calls the methods ejbLoad () and ejbStore () and where the state information is stored when they are called?

  7. Do you know about Sequence Diagrams in UML?

  8. Which is faster in execution-JSP or SERVLET? Why?

  9. What is the difference between Callable Statement and Prepared Statement?

  10. Can we declare final method in abstract class?

  11. Can we declare abstract method in final class?

  12. What is the difference between Inner Join and Outer Join?

  13. How can you pass an object of data from one JSP to another JSP? ANS: Using Session or request. GetParameter () or Hidden Variables.

  14. When these methods are used? ejbActivate (), ejbPassivate () and ejbRemove ()?

  15. What is the difference between ejbPassivate () and ejbRemove ()?

  16. Can the same object of Stateless Session bean be shared by multiple clients?

  17. Can the same object of Stateful Session bean be shared by multiple clients?

  18. How do you manage transactions in EJB?

  19. What is the difference between response. Redirect () and forward and request dispatcher? Which is faster?

  20. In java, which has more wider scope? Default or Private?