Google Analytics

Monday 5 March 2012

Java Dumps


1. Which of the following is the best answer

a)Although webservers can be configured to ports other than 80 for http requests, it is fine to configure them to 8000 in production environments
b)Although webservers can be configured to ports other than 80 for http requests, it is not fine to configure them to 8000 in production environments
c)Webservers do not allow you to configure to ports other than 80 and 443
d)Ignore this Option

2. The following method is used to create a PrintWriter object that can be used to write text to the response

a) getWriter()***************************8
b) getOutputStream()
c) getBinaryStream()
d) getStream()

3. The service() method has objects of these classes as parameters - HttpServletRequest and HttpServletResponse

a) True
b) False
c) Ignore this option
d) Ignore this option

4. Consider the following servlet

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class MyServlet extends HttpServlet {
         
   int var;

   public void init() throws ServletException {
          var=0;
   }
   ....
}

For every browser request, a new instance of the servlet is created by the server

a) True
b) False
c) Ignore this option
d) Ignore this option

5. Name the class that can be used to get the cookies from the client browser

a) HttpServletResponse
b) HttpServletRequest
c) SessionContext
d) SessionConfig

6. Which of the following is not a server-side technology?

a) Servlets
b) Java Server Pages
c) DHTML
d) CGI

7. Which method returns an array of String objects containing all of the values the given request parameter has

a) getParameter()
b) getParameterNames()
c) getParameterValues()
d) None of the above

8. Which of the following statements are true?
          1] Abstract class cannot be instantiated
          2] We cannot declare abstract constructors
          3] We may declare abstract static methods

a) 1 is true
b) 2 is true
c) 1 & 2 are true
d) All of the above are true

9. What is the default access specifier in Java

a) Private
b) Protected
c) Final
d) Don't use any keyword at all (Make’s it default package level)

10. You can implement the selected methods of interface. This can be achieved by

a) inner class
b) Anonymous inner class
c) Adapter class...........................
d) Static inner class

11. Pointer facility is available in Java as
a) No such facility in Java.....................
b)  Object References
c)  Pointer itself
d)  Classes

12. When we have a ‘catch’ block in Java, it is mandatory to have

a)  Finally block
b)  Throws block
c)  Try block
d)  No need to have any mandatory block
 
13. Panel is a container

a) from which you inherit the Applet class
b) that helps you add multimedia elements
c) that helps you add event handling for your applications
d) that helps you to create windows for your applications

14. System.in can be used to directly read lines from the console

a) true********************
b) false
c) Ignore this option
d) Ignore this option

15. From OO point of view which of the following is better option for creating a thread

a) extending Thread class
b) extending Runnable interface
c) implementing Runnable interface***********************8
d) none of the above

16. Invoking Start on a Thread instance starts a new

a) derived class of Thread class
b) separately scheduled thread in the Java Virtual Machine, which then executes the code
specified in the run method of that Thread subclass
c) separately scheduled thread in the operating system, which then executes the code
specified in the run method of that Thread subclass.******************************
d) separately scheduled thread in the Java Virtual Machine, which then executes the code
specified in the start() method of that Thread subclass

17. For writing transactions, the Autocommit mode of the Connection object should be made as true

a) True*********
b) False
c) Ignore this option
d) Ignore this option

18. Socket class helps an application program to act as a server and listen on any of the available ports for request

a) True
b) False****************** ServerSocket
c) Ignore this option
d) Ignore this option

19.     ..
          Statement stmt = con.createStatement();
          String s = "INSERT INTO COFFEE " +
                        "VALUES('Frensh_Roast', 49, 8.99, 0, 0)";
what will be the next statement

a) executeQuery()
b) executeUpdate() **************************************
c) execute()
d) getResultSet()

20. getLocalPort() method of ServerSocket class will give

a) port on which Server socket is created. ********************
b)port on which client socket is created on the server machine.
c)port on which client socket is created on client machine.
d) none of the above

21. GET method of HTTP is more secure than POST method

a) true
b) false*****************8
c) can't say
d) none of the above

22. 'this' is used for referring

a) current object.....................
b) any object used in the application
c) super class object
d) none of the above 

23. In an Object-Oriented system, objects interact with each other by sending and receiving ____________________

a) arguments
b) messages...................
c) methods
d) None of these

24. Name the class that includes the getSession method that is used to get the HttpSession object.

a) HttpServletResponse
b) HttpServletRequest
c) SessionContext
d) SessionConfig

25. The method getWriter returns an object of type PrintWriter. This class has println methods to generate output. Which of these classes define the getWriter method? Choose the correct option

a) HttpServletRequest
b) HttpServletResponse
c) ServletConfig
d) ServletContext

26. To send text output in a response, the following method of HttpServletResponse may be used to get the appropriate Writer/Stream object. Choose the correct option.

a) getStream
b) getOutputStream
c) getBinaryStream
d) getWriter

27. Which method returns names of the request parameters as Enumeration of String objects

a) getParameter
b) getParameterNames
c) getParameterValues
d) None of the above

28. Servlets classes specific to your application are placed in which directory on the TOMCAT Server?

a) <webapp_root>/lib/
b) <webapp_root>/WEB-INF/classes/
c) <webapp_root>/classes
d) <webapp_root>/WEB-INF/lib/

29. A programmer wants to develop different types of windows like SpreadSheetWindows, GraphWindows etc. The contents of the windows need to be redrawn using a function called paint.Which of the following is the best OO design?

a) A virtual function "paint" is defined in  a base class called windows and each derived classes SpreadSheetWindows, GraphWindows overrides the method paint
b) The operation paint is implemented in the base class windows and SpreadSheetWindows, GraphWindows are derived from the base classes
c) Code two classes SpreadSheetWindows, GraphWindows which take care of different types of repainting for different windows
d)  A single class called windows and operations called SpreadSheetWindows, GraphWindows, paintWindows

30. If I create and load all the dialogs (say 50 dialog) in an UI Application at the start up into a dialog array and show and hide one dialog on a need basis, what do I achieve?

a) Good Performance and Bad Memory usage
b) Bad Performance and Good Memory usage
c) Good Performance and Good Memory usage
d) Bad Performance and Bad Memory usage

31. If I want to use JDBC code in my Java program what all I need to do

a) Include the jdbc class files in the CLASSPATH and import the relevant packages in the program*****************
b) Just have the jdbc class files in the CLASSPATH and run the java program with the classpath option
c) Just import the relevant JDBC packages in the program
d) Both 1 and 2

32. Given these class definitions

          class Superclass{}
          class Subclass1 extends Superclass{}

          and these objects


          Superclass a = new SuperClass();
          Subclass1 b = new Subclass1();

Which of the following explains the result of the statement a=b?

a) Compile time Error
b) Only run time Error
c) No error at all
d) Ignore this option

33. Given these code snippets,

          Boolean b1 = new Boolean(true);
          Boolean b2 = new Boolean (true);

Which expression is legal java expression that returns true?

a) b1==b2
b) b1.equals(b2)
c) both a & b
d) b1 | b2
34. Can a method in java be private and static?

a) Yes
b) No
c) Ignore this choice
d) Ignore this choice

35. How do you implement pass-by-reference in Java?

a) Using classes
b) Using Objects.....................
c) Using pointers
d) Using Wrapper Classes

36. What exception will be thrown from the code given below:

class Arr
{
          public static void main(String[] args)
          {
                    int[] ia = new int[2];
                    ia[2] = 2;
                    System.out.println(ia[2]);
          }
}

a) NullPointerException
b) ArrayIndexOutOfBoundsException....................
c) IllegalAccessException
d) No exception will be thrown

37. What will happen when you attempt to compile and run the following code

public class Bground extends Thread
{
          public static void main(String argv[])
          {
                    Bground b = new Bground();
                    b.run();
    }
    public void start()
          {
       for (int i = 0; i< 10;i++)
       System.out.println("Value of i =" +i);
    }
 }

a) A compile time error indicating that no run method is defined for the Thread class
b) A run time error indicating that no run method is defined for the Thread class
c) the programs compiles and runs correctly with values 0 to 9 printed out
d) No output in the run time************************

38. Threading in Java can be implemented by
a) Subclassing Thread and overriding run() method
b) Implementing the Runnable Interface
c) Either 1 or 2***************************
d) None of the above

39. If there are two threads with different priority, does that mean that higher-priority thread will run faster than the lower priority thread
a) True
b) False******************************
c) Ignore this option
d) Ignore this option

40. If a thread has entered a synchronized method of an instance, another thread cannot call any other methods (synchronized or non-synchronised) of the same instance.
a) True
b) False***********************
c) Ignore this option
d) Ignore this option

41. Panel is a container

a) from which you inherit the Applet class
b) that helps you add multimedia elements
c) that helps you add event handling for your applications
d) that helps you to create windows for your applications

42. If a frame uses a grid layout manager and does not contain any panels,

a) then all the components within the frame are of different width and height
b) then all the components within the frame are the same width and height.
c) then all the components within the frame are smaller
d) then all the components within the frame are not completely visible

43. A thread's run() method includes the following lines:

                    1. try{
                    2.       sleep(100);
                    3. } catch(InterruptedException e) { }


Assuming the thread is not interrupted, which one of the following statements is correct?

a) The code will not compile, because exceptions may not be caught in a threads run() method.
b) At line 2, the thread will stop running. Execution will resume in atmost 100 milliseconds
c) At line 2, the thread will stop running. Execution will resume in exactly 100 milliseconds
d) At line 2, the thread will stop running. Execution will resume in some time after 100 milliseconds have elapsed.

44.  A package is a collection of


a) Classes and Interfaces only
b) Classes ,Interfaces, and packages...............
C) Interfaces and packages only
d) Only Interfaces and Abstract classes

45. What is true with the following statement is java
super();
[  i] calls the super class constructor.......................
[ ii] is optional because there is default call to the super
class constructor
[iii] has to be the first executable statement in the subclass
constructor
[ iv] fails if there is neither implicit nor explicit zero parameter
constructor in the super class.

a) all of the above
b) [i], [ii],[iii]
c) [i], [ii] 
d) [i], [ii],[iv]

46. Ture or False?
There are methods, System.gc() and Runtime.gc() that look as of they run
tehthe garbage collector but even these methods do not have any control on
the garbage collection process.
a) False
b) True
c) Ignore this option
d) Ignore this option

47. What are the advantages of wrapper classes in Java?
a) Java contains many subsystems that work only with objects and not
   with primitive types
b) They are more object oriented than primitive data types
c) They can encapsulate the power of the functions related with something
   that they wrap which primitives cannot do.
d) all of the above..................

48. The Vector class in Java
a) provides methods for working with dynamic( growing) arrays
b) allows varies element types
c) is Serializable
d) all of the above........................

49. If one needs to find out what are the methods of one object/class
by reading a .class file(without having .java file) what way/API can help
a) API cannot do this work, you must have a specialized software for this.
b) Reflection API can do this
c) Util package has the API to do this
d) You cannot do this by any way

50. What happens when object of the file class is garbage collected
a) file is permanently deleted from the hard disk
b) file is deleted but can be retrieved using some utilities
c) file is not deleted but the reference to the file is not available
   anymore.
d) file is closed and made inaccessible.

51. Which of the following statements are correct regarding the Object
class in Java
  [i] this is super class of all other classes in Java.
 [ii] when you want to write a generic method which needs to accept any
      kind of object you can use this class
[iii] Object o=new Emp();
 [iv] Emp e=new Object();
a) all of the above
b) [i], [ii], [iii]
c) [i], [ii]
d) [i], [iii]



52. Which of the following is true about the abstract classes and interface
a) Absract class may contain some implemented,  some unimplemented methods.
   Interface cannot have implemented ones.
b) Abstract classes can have instances and interfaces cannot.
c) Abstract classes are useful without inheritance and interfaces have to
   be implemented to be usable.
d) Interfaces cannot contain anything other than method declarations
   while as abstract classes can contain variables as well.



53. Which of the following class can be used to find out the ipaddress of
your machine?
a) IpAddress
b) InetAddress**********************
c) NetAddress
d) none of the above.

54. Which one of the following object contains the description of the
current resultset.
a) ResultSet Object.
b) MetaData Object.
c) ResultSetMetaData Object***************************
d) None of the above


55. Which of the following is correct definition of parameter marshalling.
a) conversion of basic data types to bytes
b) conversion of bytes to basic data types by stub
c) packaging of the parameters to be sent to the remote methods as block
of bytes
d) all of the above


56. In java, three tier architecture is usually( in most generic way)
implemented using
a) Front end in HTML, middle tier in pure java, odbc in backend
b) Front end in applets, middle tier in beans, odbc in backend
c) Front end on HTML/Swing, middle tier in Servlets/Beans/EJB and Database
   server in the back end.************************
d) none of the above

57. Which of the following is true about DSN
a) It's a data source name used to identify which database is to connected
   from the program
b) created using control panel of windows OS and hence platform dependant
c) created while using JdbcOdbc bridge driver from the java program
d) all of the above.***************************

58. In JNDI the context object contains
a) Common information like protocol, ipaddress which is required for
   looking up most of the remote objects in one project
b) Common information like the object name, which is required for
   looking up each of the remote objects in one project
c) Specific information like unique name required for each lookup
d) none of the above

59. We can synchronize
  [i] block
 [ii] method
[iii] object
 [iv] class

a) only [ii]
b) [ii], [iii]*********************
c) [i], [ii], [iii], [iv]
d) none of the above

60. Choose best answer for the following question
Naming.rebind method
a) re-registers the same remote object again in the rmiregistry
b) registers the remote object in rmiregistry with the unique name
   given as parameter to this method.
c) removes the registration of the remote object which is already
   registered with the unique name given as parameter to this method.
d) both c and b

61. In Java, when two or more threads need access to a shared resource,
    _____is a way to ensure that the resource will be used by only one
    thread at a time.
a) creating a semaphore
b) Using mutex
c) Synchronization***********************
d) none of the above.

62. Why are programs needed on Server-side?
a) Dynamic Content generation
b) Database access
c) Transactions
d) All of the above********************

63. Any Java class can be a servlet provided
 i] It implements the javax.servlet.Servlet Interface.
ii] Extends from any class that implements the same.
a) Only i is true, ii cannot be used
b) Only ii is true, i cannot be used
c) Either of i or ii can be used
d) Both i and ii cannot be used

64. Servlet becomes thread safe by implementing the javax.servlet.
SingleThreadModel interface
a) as every request is handled by separate instances of the servlet
b) as a single thread serves all the client requests
c) as all the requests are serialised
d) a first to-be loaded servlet and is loaded by the server during startup

65. You must ideally use Servlets for
  i] Extending Server functionality and simple business logic
 ii] Work flow management and presentation logic
iii] Work flow management and complex database queries
 iv] NON-HTML data generation such as XML generation and parser

a) i only
b) i, ii, iii
c) i and ii only
d) All of i, ii, iii and iv

66. Some purposes for which servlets can be used are:
  i] file access on the client side
 ii] starting distributed transactions
iii] any purpose at the server end
 iv] calling an enterprise bean

a) All of i, ii, iii and iv
b) ii, iii and iv only. File access is not possible.
c) iii only
d) None of i, ii, iii and iv

67. What access control keyword should you use to enable other classes to access a method freely within its package,but to restrict classes outside of the package from accessing that method?
a) private
b) public
c) protected
d) Do not supply an access control keyword

68. sqlj code finally gets converted to JDBC code.
a) True
b) False
c) Ignore this option
d) Ignore this option

69. You can set a thread's priority
a) when you first create the thread
b) at any time after you create the thread
c) both of these
d) Priority cannot be changed at all***********************

70. Which methods of a remote object a client object can call?
a)  all methods
b)  methods defined in remote interface
c)  methods registered in rmiregistry
d)  none of the above

71. Which of the following tools is used to generate the stubs and skeletons
for a remote service?
a)  javac
b)  rmic
c)  java
d)  rmiregistry

72. What interface must a class inherit from before an object of that type could be written to a stream?
a)  Serializable **********************
b)  Remote
c)  any one of the above
d)  none of the above

73 Looking at the following piece of the code, Select the correct statement out of the given options
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
a) This is exactly same as import statement
b) This is used to make a connection with database
c) Usually written in the init() method of Servlet to load the driver into memory************* ????????????
d) None of the above

74.Servlets can follow
a) single thread model
b) multi thread model
c) both
d) none of the above

75. Multiple inheritance is achieved in Java with
a) Interfaces
b) classes
c) abstract classes
d) extends keyword

76. GarbageCollector can be forced to immediately recover unused memory
a) True
b) False
c) Ignore this option
d) Ignore this option

77. What is the main disadvantages of using Java vis-à-vis C/C++ language
a) Interpretation of the program before each execution makes it slow.
b) Objects can be garbage collected resulting in unstability of programs
c) The LOc (lines of code) required for a java program is more when compared to the C/C++ counterpart
d) None of the above

78. In case an error occurs in the execution of a Oracle stored procedure from a Java program
a) SQLException is thrown and the oracle error code returned
b) SQLException is thrown and the JDBC error code is returned
c) IOException is generated as the database connection is lost
d) No exception is returned but the program hangs

79. Inside the interface, while declaring a function that others can access remotely,you must extend which interface?
a) Cloneable
b) Serializable*********************
c) RemoteObject
d) Remote

80. In a try-catch-finally construct, the finally block is executed
a) Only when an exception Is caught
b) Only when no exception is caught
c) Always
d) Only when the catch block has a "return" statement

81. Threading in Java can be implemented by
a)By subclassing Thread class
b)By implementing Runnable
c)Any of the above**********************
d)None of the above

82. What variables are substitute in java for the global variables
a)Instance variables
b)static variables************************
c)public variables
d)final variables

83.Which of the following server can host servlets?
a)Apache server
b)IIs
c)Windows 2000 Server
d)Tomcat Server********************8

84. Select the odd man out of
a) JButton*****************8
b) Dialog
c) ScrollPane
d) Panel

85. class WhatHappens implements Runnable
{ public static void main(String[] args)
  { Thread tThrd = new Thread (this);
    tThrd.start();}
public void run()
{
   System.out.println("hi");
}
}
a) This program compiles and word ""hi"" appears in the standard output (once)."
b) This program compiles and word ""hi"" appears continuously in the standard output until the user hits Ctrl+C to stop the program."
c) compilation error***********************
d) runtime error

86. The URL in the POST method can be used to find out the query parameters
a) true
b) false********************
c) Ignore this option
d) Ignore this option

87. What are the uses of an Interface?
a) It allows multiple interface inheritance
b) It helps to use the Polymorphism feature of OOP
c) It helps to follow a specific standard of functions among the similar classes.
d) All of the above

88. What is overriding?
a) Writing a function in the child class, which has the same name and same function signature as that of the function in the parent class is called overriding.
b) Overriding is same as overloading but implemented in a parent child relationship between classes.
c) Writing a function in the child class, which has the same name but different function
signature as that of the function in the parent class is called overriding.
d) None of the above

89. How to create your own exception class
a) You cannot create your own exception class
b) You have to inherit your class from Exception/Throwable
c) You have to implement the Serializable interface
d) You have to extend your class from Error class

90.  Which of the following is a proper declaration an abstract methods is java?
a)   public method();
b)   public abstract method();
c)   public abstract void method(){}
d)   public abstract void method();

91. In Java the bytecode is always contained in
a)  .jar file
b) .class file
c) .java file
d) .exe file

92. Bytecode has to be
a) interpreted by the JVM
b) compiled by the JIT
c) either of the above
d) both a,b

93. Byte code verifier is used to check whether the code
a) Memory access violations
b) violates access rights on objects
c) attempt to change the object type illegaly
d) all of the above

94. A ______ is a part of JVM that loads all classes that are required for the execution of the java program.
a) JRE
b) bytecode loader
c) class verifier
d) classloader       ???????????????????????????????

95. Which one of the following interface is used to call a stored procedure from java
a) StoredCall
b) CallProcedure
c) CallableStatement***********************
d) None of the above

96. The lowest level synchronization which synchronizes the smallest unit is
a) synchronizing a method****************
b) synchronizing a object
c) synchronizing a block
d) synchronizing a class

97. Which of the following is true about rmiregistry ?
a) rmiregistry listenes on port 1099 by default for the incoming requests
b) rmiregistry is naming service used by RMI
c) rmiregistry has to be running for the client to get handle of the remote object
d) all of the above

98. The following code which is saved in c:\test.java. Choose the appropriate statement which will compile it and do the placement of the bytecode accurately.

package mypackage;
public class test
{
   
}

a) c:\>javac -d  test.java
b) c:\> javac test.java
c) c:\mypackage> javac test.java
d) c:\mypackage> javac c:\test.java

99. The capability of an object to exist beyond the execution of the program that created it its indicated by inherting from
a) Serializable interface
b) Remote interface
c) both of the above
d) this cannot be achieved without database or a file.


4 comments:

  1. Wonderful blog & good post.Its really helpful for me, awaiting for more new post. Keep Blogging!








    Java Training Courses

    ReplyDelete
  2. Java Servlet Interview Questions and Answers
    http://allinterviewquestionsandanswerspdf.blogspot.in/2016/06/top-25-java-servlet-interview-questions.html

    ReplyDelete
  3. Hi

    Can you answer all question

    ReplyDelete
  4. For java trend nxt dumps check this site really helpul for me most of the questions came from this

    Core Java trend nxt dumps on trenovision

    ReplyDelete