Paper Tayyari

Midterm PreparationMidterm ki tayyari

Syllabus: lectures 1–18. Past-paper MCQs are shown first.Syllabus: lecture 1–18. Past paper ki MCQs pehle dikhai gayi hain.

86 MCQs · 46 short · 21 long questions · 86 MCQs from past papers86 MCQs · 46 short · 21 long sawal · 86 MCQs past papers se

Start mock testMock test shuru karein
DoneHal kiye 0/86
– correctsahi
1.
★ Midterm past paperLecture 5

Which of the following is used for inheritance in java?

  1. Aimplements
  2. Bextends
  3. C: (colon)
  4. Dinherit

A class inherits from another class with the extends keyword.

2.
★ Midterm Fall 2008Lecture 6

Which of the following statements is true regarding Vectors with no specified base type?

  1. AA base type is needed, because Java needs to know how to allocate memory.
  2. BNo base type is needed, because Java will use the Object class as a base type.
  3. CIf a base type is not specified the code will not compile.
  4. DNo base type is needed because Vectors default to storing String objects.

A raw Vector stores elements as Object references.

3.
★ Midterm Spring 2006Lecture 6

Map interface is derived from the Collection interface.

  1. ATrue
  2. BFalse

Map is a separate interface hierarchy and does not extend Collection.

4.
★ Midterm past paperLecture 6

A collection can store..........

  1. AHomogenous objects
  2. BHeterogeneous objects
  3. CObjects as well as primitive values
  4. DAt most 100 objects

Collections hold Object references, so objects of different types can be stored together.

5.
★ Midterm past paperLecture 6

HahMap takes key as a/an _________

  1. AObject
  2. BArray
  3. CPrimitive value
  4. DFunction

HashMap keys are objects.

6.
★ Midterm past paperLecture 6

The collections API are defined in ______ package?

  1. AJava.io
  2. BJava.util
  3. CJava.sql
  4. DJava.awt

The collection classes such as ArrayList and HashMap are in java.util.

7.
★ Midterm past paperLecture 6

If no base type is specified in a Vector, Java will use:

  1. AString class
  2. BInteger class
  3. CObject class
  4. DDouble class

A raw Vector stores elements as Object.

8.
★ Midterm past paperLecture 7

There are _________ types of exceptions in Java

  1. A2
  2. B3
  3. C4
  4. D5

Exceptions are divided into checked and unchecked exceptions.

9.
★ Midterm past paperLecture 7

Which of the following belongs to a category of checked exception?

  1. ANull Pointer exception
  2. BIOException
  3. CArray index out of bounds
  4. DNumberFormatException

IOException must be caught or declared, so it is checked.

10.
★ Midterm past paperLecture 7

Which of the following exception belongs to a category of un-checked exception?

  1. AIOException
  2. BNull Pointer exception
  3. CAWTException
  4. DClassNotFoundException

NullPointerException is a RuntimeException, so it is unchecked.

11.
★ Midterm past paperLecture 7

All the exceptions and errors in java are inherited from _____ class.

  1. AException
  2. BError
  3. CThrowable
  4. DIOException

Throwable is the superclass of both Exception and Error.

12.
★ Midterm past paperLecture 7

When defining a method, which clause is used to declare exceptions that may be thrown?

  1. Atry block
  2. Bfinally block
  3. Ccatch block
  4. Dthrows clause

A method declares the checked exceptions it may throw with a throws clause.

13.
★ Midterm Fall 2008Lecture 8

Aside from the Scanner class, which of the following classes can be used for text-file file input?

  1. AObjectInputStream
  2. BBufferedReader
  3. CStringTokenizer
  4. DNone of these

BufferedReader wrapped around a FileReader reads text files line by line.

14.
★ Midterm past paperLecture 8

Which of the following package needs to be import while handling files?

  1. Ajava.util
  2. Bjava.io
  3. Cjava.awt
  4. Djavax.swing

File and stream classes are in java.io.

15.
★ Midterm past paperLecture 8

Which of the following stream is a filter stream?

  1. AFileWriter
  2. BFileReader
  3. CBufferedReader
  4. DAll of given options

BufferedReader wraps another stream and adds buffering, so it is a filter stream.

16.
★ Midterm past paperLecture 8

Based on functionality, the streams can be categorized as________

  1. AByte oriented streams and Node Streams
  2. BFilter stream and Character oriented stream
  3. CNode stream and Filter stream
  4. DByte oriented stream and Character oriented stream

By function, streams are node streams (connected to a source/sink) or filter streams (wrapping another stream).

17.
★ Midterm past paperLecture 8

Which of the following stream is a Node stream?

  1. APrintWriter
  2. BBufferedReader
  3. CFileWriter

FileWriter connects directly to a file (data source), so it is a node stream; the others are filters.

18.
★ Midterm past paperLecture 8

Which class can be used for text file input besides Scanner?

  1. AObjectInputStream
  2. BBufferedReader
  3. CStringTokenizer
  4. DNone of these

BufferedReader (wrapping a FileReader) reads text files line by line.

19.
★ Midterm Fall 2008Lecture 9

An abstract class --------------- instantiated.

  1. ACan't be
  2. BCan be
  3. CMust
  4. DNone of these

Objects cannot be created from an abstract class.

20.
★ Midterm Spring 2006Lecture 9

In Java an abstract class cannot be sub-classed

  1. ATrue
  2. BFalse

Abstract classes are meant to be subclassed.

21.
★ Midterm past paperLecture 9

An instance of abstract class cannot be created.

  1. ATRUE
  2. BFALSE

Abstract classes cannot be instantiated.

22.
★ Midterm past paperLecture 9

Which of the following is called ' pure abstract class ' ?

  1. AConcrete class
  2. BWrapper class
  3. CInterface
  4. DAbstract class with no abstract method

All methods of an interface are abstract, so it acts as a pure abstract class.

23.
★ Midterm past paperLecture 9

Which of the following is true about abstract class?

  1. AAn abstract class must have all methods declared as abstract methods.
  2. BA class must have at least one abstract method to be an abstract class.
  3. CA class without any abstract method can be declared as abstract class.
  4. DAn instance of abstract class can be created.

A class may be declared abstract even if it has no abstract methods.

24.
★ Midterm past paperLecture 9

Which of the following feature provide facility for multiple inheritances:-

  1. AAdapter Classes
  2. BWrapper Classes
  3. CInterface
  4. DCollection

A class can implement many interfaces, which gives the effect of multiple inheritance.

25.
★ Midterm past paperLecture 9

An abstract class:

  1. ACan be instantiated
  2. BCan’t be instantiated
  3. CMust be instantiated
  4. DNone of these

Objects of an abstract class cannot be created with new.

26.
★ Midterm Spring 2006Lecture 10

In Java, which of these classes implement the LayoutManager interface?

  1. ARowLayout
  2. BColumnLayout
  3. CGridBagLayout
  4. DFlowLayoutManager

GridBagLayout is a real layout manager; the others do not exist in the JDK.

27.
★ Midterm Spring 2006Lecture 10

BorderLayout is the default layout manager for a JFrame's content pane

  1. ATrue
  2. BFalse

A JFrame's content pane uses BorderLayout by default.

28.
★ Midterm past paperLecture 10

Window frame and dialog use ________ as their default layout.

  1. ABorder layout
  2. BFlow layout
  3. CGridBag layout
  4. DGrid layout

Window, Frame and Dialog use BorderLayout by default.

29.
★ Midterm past paperLecture 10

JPanel and Applet use ________ as their default layout.

  1. AFlow layout
  2. BBorder layout
  3. CGrid layout
  4. DGridBag layout

JPanel and Applet use FlowLayout by default.

30.
★ Midterm past paperLecture 10

BorderLayout is the default layout manager for a JFrame content pane

  1. ATRUE
  2. BFALSE

A JFrame's content pane uses BorderLayout by default.

31.
★ Midterm past paperLecture 10

Which of the following is a general purpose container?

  1. AJFrame
  2. BDialog
  3. CJPanel
  4. DJApplet

JPanel is a general-purpose container; the others are top-level containers.

32.
★ Midterm past paperLecture 10

Border layout divides the area into _______ regions

  1. A3
  2. B4
  3. C5
  4. D6

BorderLayout has five regions: north, south, east, west and center.

33.
★ Midterm past paperLecture 13

Adapter classes have been defined for listener interfaces except ______ interface.

  1. AMouseListener
  2. BKeyListener
  3. CWindowListener
  4. DActionListener

ActionListener has only one method, so it has no adapter class.

34.
★ Midterm Fall 2008Lecture 17

To create DataBaseMetaData object we write following line of code

  1. ADataBaseMetaData db = con.getMeataData();
  2. BResultSetMetaData rsmd = rs.getMetaData();
  3. CResultSetMetaData rsmd = rs.setMetaData();
  4. DDataBaseMetaData db = con.setMeataData();

DatabaseMetaData is obtained from the Connection with getMetaData().

35.
★ Midterm Fall 2008Lecture 18

Which of the following methods are invoked by the AWT to support paint and repaint operations?

  1. Apaint( )
  2. Brepaint( )
  3. Cdraw( )
  4. Dredraw( )

The AWT system itself calls paint() when a component must be drawn; programs call repaint() to request it.

36.
★ Midterm Fall 2008Lecture 18

Which of the following are passed as an argument to the paint ( ) method?

  1. AA Canvas object
  2. BA Graphics object
  3. CAn Image object
  4. DA paint object

paint(Graphics g) receives a Graphics object used for drawing.

37.
★ Midterm Fall 2008Lecture 18

The code below draws a line. What color is the line? g.setColor(Color.red.green.yellow.red); g.drawLine(0, 0, 100,100);

  1. ARed
  2. BGreen
  3. CYellow
  4. DBlack

Each static field access through an instance just reads the named constant, so the last one, Color.red, is used.

38.
★ Midterm Spring 2010

Java developed in __________

  1. A1990
  2. B1995
  3. C1997
  4. D2000

Sun released Java publicly in 1995, as the handout states.

39.
★ Midterm Fall 2008

A serializable class must implement the method(s) _________.

  1. AreadObject and writeObject
  2. BEither readObject or writeObject, or both, depending upon the desired behavior
  3. CNo need to implement any method
  4. DNone of the given option

Serializable is a marker interface with no methods; implementing it is enough.

40.
★ Midterm Fall 2008

You can ---------to a network using sockets.

  1. ARead
  2. BWrite
  3. CRead/Write
  4. DNone of these

A socket gives both an input stream and an output stream, so you can read and write.

41.
★ Midterm Fall 2008

Socket is a --------------communication channel between hosts.

  1. AUni-directional
  2. BBi-directional
  3. CMulti-directional
  4. DNone of these

A socket is a two-way (bi-directional) channel between two hosts.

42.
★ Midterm Fall 2008

Event source can have --------- listeners registered on it.

  1. ASingle
  2. BDouble
  3. CTriple
  4. DMultiple

Any number of listeners can be registered on one event source.

43.
★ Midterm Fall 2008

A ___________ defines the way and method of communication between two parties.

  1. ACompiler
  2. BProtocol
  3. CTool
  4. DTechnique

A protocol is the set of rules for how two parties communicate.

44.
★ Midterm Fall 2008

What if the main method is declared as private?

  1. AThe program does not compile
  2. BThe program compiles but does not run
  3. CThe program compiles and runs properly
  4. DThe program throws an exception on compile time

A private main compiles, but the launcher cannot use it as the entry point.

45.
★ Midterm Fall 2008

A member variable or method prefixed by the protected access modifier can be accessed:

  1. AWithin the same class
  2. BWithin the sub-class
  3. CWithin the same package
  4. DAll of the above

Protected members are visible in the class, its package and its subclasses.

46.
★ Midterm Spring 2006

In Java a final class must be sub-classed before it.

  1. ATrue
  2. BFalse

A final class cannot be subclassed at all.

47.
★ Midterm Spring 2006

A top level class without any modifier is accessible to

  1. Aany class
  2. Bany class within the same package
  3. Cany class within the same file
  4. Dany subclass of this class

With no modifier a class has default (package) access.

48.
★ Midterm Spring 2006

A top level class may have only the following access modifier.

  1. APackage
  2. BPrivate
  3. CProtected
  4. DPublic

A top-level class can only be public or have default access; there is no "package" keyword.

49.
★ Midterm Spring 2006

Given a one dimensional array arr, what is the correct way of getting the number of elements in arr

  1. Aarr.length
  2. Barr.length – 1
  3. Carr.size – 1
  4. Darr.length()

Arrays have a length field (not a method) giving the number of elements.

50.
★ Midterm Spring 2006

When recursive method is called to solve a problem, the method actually is capable of solving only the simpler case(s), or base case(s).

  1. ATrue
  2. BFalse

A recursive method directly solves only the base case and reduces other cases toward it.

51.
★ Midterm Spring 2006

Which of these are valid declarations for the main method?

  1. Apublic void main();
  2. Bpublic static void main(String args[]);
  3. Cstatic public void main(String);
  4. Dpublic static int main(String args[]);

The standard entry point is public static void main(String args[]).

52.
★ Midterm Spring 2006

In Java garbage collection is done by_______________

  1. AJVM (Java Virtual Machine)
  2. BProgrammer
  3. CBoth JVM (Java Virtual Machine)and Programmer
  4. DOS (Operating System)

The JVM garbage collector frees unused objects automatically.

53.
★ Midterm Spring 2006

____________is/are the JSP Implicit Object(s).

  1. Asession
  2. Bapplication
  3. Cconfig
  4. DAll of Given

session, application and config are all JSP implicit objects.

54.
★ Midterm Spring 2006

JavaBeans are?

  1. AA special Java class file
  2. BServlets
  3. CApplets
  4. DA Special form of JSP

A JavaBean is an ordinary Java class written to bean conventions.

55.
★ Midterm Spring 2006

An expression tag contains a scripting language expression that is evaluated.

  1. ATrue
  2. BFalse

A JSP expression is evaluated, converted to a String and inserted in the output.

56.
★ Midterm Spring 2006

A final class can't be extended.

  1. ATrue
  2. BFalse

Declaring a class final prevents subclassing.

57.
★ Midterm Spring 2006

ServletConfig defines a set of methods that a servlet uses to communicate with its servlet container.

  1. ATrue
  2. BFalse

That is the definition of ServletContext; ServletConfig carries one servlet's configuration.

58.
★ Midterm Spring 2006

A method can not be made final until whole class is made final.

  1. ATrue
  2. BFalse

Individual methods can be declared final in a non-final class.

59.
★ Midterm Spring 2006

Servlet session and JSP session have different abilities.

  1. ATrue
  2. BFalse

A JSP becomes a servlet, so session handling is the same.

60.
★ Midterm past paper

Java program code is compiled into form called

  1. AMachine code
  2. Bnative Code
  3. CByte Code
  4. DSource Code

javac compiles source into platform-independent bytecode for the JVM.

61.
★ Midterm past paper

Overloading is _______ whereas overriding is _____

  1. ARun time binding, compile time binding
  2. BLate binding, compile time binding
  3. CCompile time binding, run time binding
  4. DRun time binding, late time binding

Overloaded calls are resolved by the compiler; overridden methods are chosen at run time.

62.
★ Midterm past paper

Static methods only access ___

  1. Ainstance variable
  2. Binstance method
  3. Cstatic variables and methods
  4. Dboth static and instance members

Static methods have no this reference, so they directly access only static members.

63.
★ Midterm past paper

Which of the following is modifier is provided by default if no access is written explicitly?

  1. Apublic
  2. BPrivate
  3. CProtected
  4. DDefault

With no access modifier, default (package) access applies.

64.
★ Midterm past paper

Which of the following function will be used to register event handler with events generator (button)?

  1. AaddAction()
  2. BaddActionListener()
  3. CaddListener()
  4. DregisterListener()

A button registers an ActionListener with addActionListener().

65.
★ Midterm past paper

Which of the following function is declared in MouseMotionListener interface?

  1. Apublic void mousePressed (MouseEvent me);
  2. Bpublic void mouseDragged (MouseEvent me);
  3. Cpublic void mouseClicked (MouseEvent me);
  4. Dpublic void mouseEntered (MouseEvent me);

MouseMotionListener declares mouseDragged and mouseMoved; the others are in MouseListener.

66.
★ Midterm past paper

Window Listener interface contains _______ methods.

  1. AFour
  2. BSix
  3. CSeven
  4. DEight

WindowListener has seven methods, such as windowOpened and windowClosing.

67.
★ Midterm past paper

Mouse events can be trapped for ________ GUI component.

  1. AJPanel
  2. BJFrame
  3. CJButton
  4. DAll of given

Mouse events can be trapped for any component that inherits from Component.

68.
★ Midterm past paper

Which of the following package needs to import while interacting with relational database?

  1. Ajava.io
  2. Bjava.sql
  3. Cjavax.swing
  4. Djava.awt

JDBC classes and interfaces are in java.sql.

69.
★ Midterm past paper

Which of the following method is used to execute SELECT SQL statements?

  1. AexecuteUpdate(sql);
  2. BExecuteUpdate(sql);
  3. CexecuteQuery(sql);
  4. DExecuteQuery(sql);

executeQuery() runs a SELECT and returns a ResultSet.

70.
★ Midterm past paper

CREATE, ALTER, DROP are _________ SQL statements.

  1. ADML
  2. BDDL
  3. CDCL
  4. DNone of given

Statements that define or change table structure are Data Definition Language.

71.
★ Midterm past paper

Which of the following statement object is used to execute stored procedures?

  1. AStatement
  2. BPreparedStatement
  3. CCallableStatement
  4. DNone of given options

CallableStatement is used to call stored procedures.

72.
★ Midterm past paper

If a super class method is protected then overriding method _________

  1. Amust be protected
  2. Bmust be public
  3. Cmust be private
  4. Dmay be either protected or public

An overriding method cannot reduce visibility, so it may be protected or public.

73.
★ Midterm 2014

ODBC stands for ______________

  1. AOpen database communication
  2. BOpen database connection
  3. COpen database connectivity
  4. DOpen database Commission

ODBC means Open Database Connectivity.

74.
★ Midterm 2014

Which of the following command is used to compile Java code?

  1. Ajava filename
  2. Bjavac filename.java
  3. Cjavac filename
  4. Djava filename.java

javac compiles a source file and needs the .java extension.

75.
★ Midterm past paper

Java was developed in which year?

  1. A1990
  2. B1995
  3. C1997
  4. D2000

Java was publicly released by Sun Microsystems in 1995.

76.
★ Midterm past paper

Which method is invoked by AWT to support painting operations?

  1. Apaint()
  2. Brepaint()
  3. Cdraw()
  4. Dredraw()

The AWT painting system calls paint(Graphics g) to draw a component.

77.
★ Midterm past paper

A serializable class:

  1. AMust implement readObject and writeObject
  2. BMust implement only readObject
  3. CNo need to implement any method
  4. DMust implement writeObject only

Serializable is a marker interface with no methods to implement.

78.
★ Midterm past paper

Using sockets, you can perform which operation on a network?

  1. ARead
  2. BWrite
  3. CRead/Write
  4. DNone of these

A socket provides input and output streams, so both reading and writing are possible.

79.
★ Midterm past paper

Which object is passed as an argument to the paint() method

  1. ACanvas object
  2. BGraphics object
  3. CImage object
  4. DPaint object

paint() receives a Graphics object used for drawing.

80.
★ Midterm past paper

If the main method is declared as private:

  1. AProgram does not compile
  2. BProgram compiles but does not run
  3. CProgram compiles and runs properly
  4. DProgram throws exception at compile time

A private main compiles, but the launcher cannot use it as the entry point.

81.
★ Midterm past paper

Protected access modifier allows access:

  1. AWithin the same class
  2. BWithin subclass
  3. CWithin same package
  4. DAll of the above

Protected members are accessible in the class, its package and its subclasses.

82.
★ Midterm past paper

A final class can be extended.

  1. ATrue
  2. BFalse
  3. CSometimes
  4. DNone of these

A final class cannot have subclasses.

83.
★ Midterm past paper

Which is the correct way to get the number of elements in an array?

  1. Aarr.length
  2. Barr.length-1
  3. Carr.size()
  4. Darr.length()

Arrays have a length field, not a method.

84.
★ Midterm past paper

Garbage collection in Java is performed by:

  1. AJVM
  2. BProgrammer
  3. CBoth JVM and Programmer
  4. DOperating System

The JVM garbage collector reclaims unreferenced objects automatically.

85.
★ Midterm past paper

Java program code is compiled into:

  1. AMachine code
  2. BNative code
  3. CBytecode
  4. DSource code

javac compiles source into bytecode stored in .class files.

86.
★ Midterm past paper

Static methods can access:

  1. AInstance variables
  2. BInstance methods
  3. CStatic variables and methods
  4. DBoth static and instance variables

Without an object, a static method can directly use only static members.