0% found this document useful (0 votes)
871 views60 pages

JAVA

The document contains 10 multiple choice questions about Java programming from NPTEL Online Certification Courses. It tests knowledge of Java concepts like language processors, comments, output of code snippets, variable names, arrays, debugging tools, primitive data types, and bytecode. The correct answers are provided for each question along with short explanations for some answers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
871 views60 pages

JAVA

The document contains 10 multiple choice questions about Java programming from NPTEL Online Certification Courses. It tests knowledge of Java concepts like language processors, comments, output of code snippets, variable names, arrays, debugging tools, primitive data types, and bytecode. The correct answers are provided for each question along with short explanations for some answers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

NPTEL Online Certification Courses

Indian Institute of Technology Kharagpur

PROGRAMMING IN JAVA
Assignment 1
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10 × 1 = 10
______________________________________________________________________________

QUESTION 1:
Which of the following is not a Language Processor?

a. Assembler
b. Compiler
c. Interpreter
d. Fortran

Correct Answer: d

Detailed Solution:

A computer understands instructions in machine code i.e., in the form of 0s and 1s. Special
translators are required for this operation like Assembler, Compiler and Interpreter. Fortran is a
programming language but not a language processor.
____________________________________________________________________________

QUESTION 2:
Which of the following is not a valid comment?

a. /** comment */
b. /* comment */
c. /* comment
d. // comment

Correct Answer: c

Detailed Solution:
Option c : /* comment .
This is not valid comment statement
____________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 3:
Consider the following program.

public class Question{


public static void main(String args[]){
for(int a=2;a<3;a+=1){
System.out.print(a+++a);
}
}
}

What will be the output of the program if it is executed?


a. 5
b. 2
c. 4
d. 1
Correct Answer: a

________________________________________________________________________

QUESTION 4:
Which of the following can be used for a variable name in Java?

a. boolean
b. final
c. finally
d. calloc

Correct Answer: d

Detailed Solution:
final, boolean, finally are reserved keyword in Java, which cannot be used for naming a variable
or class.

______________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 5:
Consider the following program.

public class Question1{


public static void main(String args[]){
int arr[]={0,1,2,3,4,5,6,7};
for(int b=5;b>2;b-=2){
System.out.println(arr[--b]);
}
}
}

What will be the output of the program if it is executed?


a. 4
b. 2
c. 3
d. 5
Correct Answer: a

QUESTION 6:

Following is a piece of code where some parts of a statement is missing:

public class Question3{


public static void main(String args[]){
char nptel[]={'S','W','A','Y','A','M'};
System.out.print( _______ );
}
}

In the following, some options are given. You have to choose the correct option for the argument
in System.out.print() function to print the second and the last characters in the array nptel.

a. nptel[nptel.length-1] + nptel[1]
b. nptel[1] + nptel[nptel.length-1]
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

c. "" + nptel[1] + nptel[nptel.length-1]


d. "" + nptel[nptel.length-1] + nptel[1]

Correct Answer: c

QUESTION 7:

What is the output of this program?

public class Question {


public static void main(String args[])
{
int i = 7;
System.out.print(--i * 7);
}
}

a. 20
b. 25
c. 42
d. 31
Correct Answer: c

Detailed Solution:
First the value of i will be decremented and then multiplication is performed and the result will
be printed.

QUESTION 8:
Which of the following is used to find and fix bugs in the Java programs?

a. JVM
b. JRE
c. JDK
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

d. JDB
Correct Answer: d

Detailed Solution:
The Java Debugger (JDB or jdb) is a command-line java debugger that debugs the java class.

QUESTION 9:
Which of the following is/are primitive data type(s) in Java?

a. int
b. String
c. Array
d. double

Correct Answer: a,d

Detailed Solution:
A String in Java is actually a non-primitive data type, because it refers to an object.

Array is also a non-primitive datatype.

QUESTION 10:
When you compile a program written in the Java programming language, the compiler
converts the human-readable source file into platform-independent code that a Java
Virtual Machine can understand. What is this platform-independent code called?

a. Source code
b. Bytecode
c. Machinecode
d. Opcode
Correct Answer: b

Detailed Solution:

Byte code is an intermediate code between source code and machine code that is executed by an
interpreter such as JVM. e.g., Java class files.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

******
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

PROGRAMMING IN JAVA
Assignment2
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10 × 1 = 10
______________________________________________________________________________

QUESTION 1:
What is the output of the following program?

public class Main{


public static void main(String args[]){
char a = '8';
int b=010;
System.out.println(a+b);
}
}

a. 88
b. 8010
c. 64
d. 810

Correct Answer: c

Detailed Solution:

The argument will take the + operator as the arithmetic addition on the ASCII values instead of
characters.

____________________________________________________________________________

QUESTION 2:
Which of the following is generate API documentation in HTML format from Java source
code?

a. javac
b. javadoc
c. javap
d. java
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Correct Answer: b

Detailed Solution:
javacdoc is generate API documentation in HTML format from Java source code.

___________________________________________________________________________

QUESTION 3:
Following is a program given for this question.

public class Main{


public static void main(String[] args) {
char[] copyFrom = { 'j', 'a', 'n', 'n', 'p', 't',
'e', 'l', 'j', 'a', 'v', 'a',};
char[] copyTo = new char[9];

System.arraycopy(copyFrom, 3, copyTo, 0, 9);


System.out.println(new String(copyTo));
}
}
What will be the output of the above program?
a. javanptel
b. npteljava
c. janjavanptel
d. jannpteljava

Correct Answer: b

Detailed Solution:
______________________________________________________________________

QUESTION 4:
What will happen during the execution of the following code for the command line input?

public class Question {


public static void main (String[] args) {
for (String s: args) {
System.out.println(s+args[0]);
}
}
}
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Consider the following input on command line and select the options with the correct output(s).
Input:
A: “jan java nptel”
B: 1 2 3

a. A : jannptel
javanptel
nptelnptel
b. A : jan java nptel jan java nptel

c. B : 11
21
31
d. B : 1 2 3 1

Correct Answer: b, c
Detailed Solution:
Java interpreted as a single argument, if the command line input is enclosing within quotation
marks.
____________________________________________________________________________
QUESTION 5:
Which of the following is/are TRUE about print() and println() methods?

a. print() prints in a single line only and multiple lines cannot be printed in any way.
b. print() prints and then appends a line break.
c. println() prints in a single line only and multiple lines cannot be printed.
d. println()prints and then appends a line break.

Correct Answer: d

Detailed Solution:

Method print() can be used to print in a single line only but multiple lines can be printed using
escape sequence ‘\n’. Similarly, println() prints in a single line only and multiple lines can be
printed using escape sequence ‘\n’. Method print() prints but does not appends a line break. So,
option (b) println() prints and then appends a line break is the only correct option.
____________________________________________________________________________
QUESTION 6:
What was the initial name of Java when it was first developed for embedded systems?
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

a. Greentalk
b. Oak
c. Java
d. Javac

Correct Answer: a

Detailed Solution:

Java was called "Greentalk" by James Gosling and the file extension was .gt and after that java
was called Oak and was developed as a part of the Green project.
______________________________________________________________________________

QUESTION 7:
Which of the following is a valid declaration of an object of class, say Foo?

a. Foo obj = new Foo;


b. obj = new Foo();
c. Foo obj = new Foo();
d. new Foo obj;

Correct Answer: c

Detailed Solution:
Others are invalid declarations.

______________________________________________________________________________

QUESTION 8:
Following is a program given for this question.

public class Question


{
public static void main(String[] args) {

boolean m=Integer.valueOf(0).equals(Long.valueOf(1));
System.out.println(m);
}
}

What will be the output of the above program?


a. 0
b. 1
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

c. false
d. true

Correct Answer: c

Detailed Solution:
The two objects (the Integer and the Long) have different types.

______________________________________________________________________________

QUESTION 9:
Which of the following can be used to take input from user during the execution of a
program?

a. Using the string array provided as a parameter to the main method.


b. getText() method can be used to get user input from the command line.
c. Scanner class can be used by passing the predefined object System.in
d. Once the execution starts, there is no way to provide user input.

Correct Answer: c

Detailed Solution:

The easiest way to read input in a Java program during execution is by using the Scanner class in
java.util package. It can be used for obtaining the input of the primitive types like int, double, etc.
and strings. The argument values provided in the main method is only applicable when the
execution starts but during execution no value can be passed in that argument.

QUESTION 10:

What is the output of the following program?

public class Question


{
public static void main(String[] args) {

int i = 10;
int n = i++%2;
int m = ++i%7;
System.out.println(i+n+m);
}
}
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

a. 14
b. 12
c. 15
d. 17

Correct Answer: d

____________________________________________________________________________
******
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

PROGRAMMING IN JAVA
Assignment3
TYPE OF QUESTION: MCQ
Number of questions:10 Total mark: 10 × 1 = 10
______________________________________________________________________________

QUESTION 1:
Consider the following piece of code in Java.
class A {
public int i;
protected int j;
}
class B extends A
{
void display()
{
super.j = super.j-super.i ;
System.out.println(super.i + " " + super.j);
}
}
public class inheritance
{
public static void main(String args[])
{
B obj = new B();
obj.i=3;
obj.j=6;
obj.display();
}
}
What is the output of the above program?

a. 23
b. 33
c. Runtime Error
d. Compilation Error

Answer: b

Explainantion: The java super keyword is used to refer the immediate parent class object.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

______________________________________________________________________________

QUESTION 2:
Consider the following piece of code in Java.

public class Question


{

public static int x = 7;


public static void main(String[] args) {

Question a = new Question ();


Question b = new Question ();
a.x = 2;
b.x = 2;
System.out.println(a.x+b.x+Question.x);
}
}

What is the output of the above program?

a) 6
b) 10
c) 21
d) error

Correct Answer: a

Detailed Solution:

Because x is defined as a public static int in the class Question, every reference to x will have the
value that was last assigned because x is a static variable (and therefore a class variable) shared
across all instances of the class. That is, there is only one x: when the value of x changes in any
instance it affects the value of x for all instances of Question.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 3:
If a class inheriting an abstract class does not define all of its functions then it will be known
as?
a) Default
b) Abstract
c) A simple class
d) Static class
Answer: b
Explanation: Any subclass of an abstract class must either implement all of the abstract methods in
the superclass or be itself declared abstract.
______________________________________________________________________

QUESTION 4:
Which among the following best describes polymorphism?

a) It is the ability for many messages/data to be processed in one way


b) It is the ability for a message/data to be processed in only 1 form
c) It is the ability for a message/data to be processed in more than one form
d) It is the ability for undefined message/data to be processed in at least one way

Correct Answer: c

Detailed Solution: It is actually the ability for a message/data to be processed in more than one
form. The word polymorphism indicates many-forms. So if a single entity takes more than one form,
it is known as polymorphism.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 5:
Consider the following piece of code in Java

class Men
{
int walkingDistance(int weight)
{
System.out.println(10);
return 10;
}
}
class WildMen extends Men
{
void walkingDistance(int weight)
{
System.out.println("20");
}
}
public class MethodOverriding3
{
public static void main(String[] args)
{
WildMen wc = new WildMen();
wc.walkingDistance(30);
}
}
What is the output of the above program?

a. 30
b. 20
c. Compiler error
d. Runtime error

Correct Answer: c

Detailed Solution: If the argument list is the same, the return types can not be the incomptible-
types. So, the compiler reports an error "The return type is incompatible with
Cat.jumpingHeight(int )”.

________________________________________________________________

QUESTION 6:
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

All the variables of the interface should be?


a) default and final
b) default and static
c) public, static and final
d) protect, static and final

Answer: c

Explanation: Variables of an interface are public, static, and final by default because the interfaces
cannot be instantiated, final ensures the value assigned cannot be changed with the implementing
class and public for it to be accessible by all the implementing classes.
______________________________________________________________________________

QUESTION 7:
Disadvantage(s) of inheritance in Java programming is/are

a) Code readability
b) two classes (base and inherited class) get tightly coupled
c) Code maintainability
d) Code reusability
.

Correct Answer: b

Explanation:
The main advantages of inheritance are code reusability and readability. When child class inherits the
properties and functionality of parent class, we need not write the same code again in child class.This
makes it easier to reuse the code, makes us write the less code and the code becomes much more readable.

The main disadvantage of using inheritance is that the two classes (base and inherited class) get tightly
coupled. This means one cannot be used independently of each other. Also with time, during maintenance
adding new features both base as well as derived classes are required to be changed.
___________________________________________________________________________

QUESTION 8:
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

When does method overloading is determined?


a) At run time
b) At coding time
c) At compile time
d) At execution time

Answer: c
Explanation: Overloading is determined at compile time. Hence, it is also known as compile
time polymorphism.
_____________________________________________________________________________

QUESTION 9:

public class Test1{


Test1() {
Test1 obj1 = new Test1();
}

public static void main(String []args) {


Test1 obj = new Test1();
System.out.println("Hello");
}
}

Which of the following statements is/ are true?


a. Output : Hello
b. Program will compile successfully.
c. There will be a compile-time error.
d. The program will give a runtime error.

Correct Answer: b, d

Detailed Solution:
Constructor if you defined recursively, then it will show runtime error.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 10:
Which of the following statement(s) is/are true?

a. Hiding internal data from the outside world, and accessing it only through publicly
exposed methods is known as data encapsulation.
b. Common behavior can be defined in a superclass and inherited into a subclass using
the extends keyword.
c. The term "class variable" is another name for static field.
d. A local variable stores temporary state; it is declared inside a method.
Correct Answer: a,b,c,d

Detailed Solution: The term "class variable" is another name for static field.

_____________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

PROGRAMMING IN JAVA
Assignment4
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10× 1 = 10

QUESTION 1:
Which of the following statement(s) is/are true?
a. The default package in the Java language is java.lang.
b. String is a final class and it is present in java.lang package.
c. Runnable is a class present in java.lang package.
d. Thread is a class present in java.lang package.

Correct Answer: a,b,d

Detailed Solution:

Runnable is an interface in java.lang package.


_____________________________________________________________

QUESTION 2:
Which of the following statement(s) is/are false?

a. With the import statement, generally import only a single package member or an entire
package.
b. To import all the types contained in a particular package, use the import statement with
the asterisk (*) wildcard character.
import package.*;

c. import package.A*; it used to match a subset of the classes in a package starts with
“A”.
d. import package.A*; it generates compilation error.

Correct Answer: c

Detailed Solution:
import package.A*; it generates compilation error.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 3:
Which of the following is/are class(s) of java.awt package?

a. CardLayout
b. Checkbox
c. Choice
d. MenuContainer

Correct Answer: a,b,c

Detailed Solution:
MenuContainer is an interface of java.awt package, all others are class.

___________________________________________________________________________

QUESTION 4:
Which of these access specifier(s) can be used for an interface?

a. public
b. protected
c. private
d. Both b and c

Correct Answer: a

Detailed Solution:

____________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 5:

Consider the program given below.

import static java.lang.Math.*;


public class Main{
public static void main(String args[]){
System.out.println(cos(3*PI));
}
}

What will be the output if the above program is executed?


a. It will give compile-time error
b. It will give run-time error
c. -1.0
d. 3.14

Correct Answer: c

Detailed Solution:
Test by run.
The static import statement is used to import the static members(e.g. ,PI) of java.lang.Math.
import static java.lang.Math.*;
____________________________________________________________________________

QUESTION 6:
Which of the following packages is used to includes utility classes like Calendar,
Collections, Date?

a. java.lang
b. java.util
c. java.net
d. java.awt

Correct Answer: b

Detailed Solution:
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

java.util is used to includes utility classes like Calendar, Collection, Date.

___________________________________________________________________________
QUESTION 7:
Consider the program given below.

import static java.lang.System.*;


public class Question{
public static void main(String args[])
{
out.println("JAVA");
}
}

What will be the output if the above program is executed?


a. It will give compile-time error
b. It will give run-time error
c. JAVA
d. JAV

Correct Answer: c

Detailed Solution:

_____________________________________________________________________________
QUESTION 8:
Which of the following is/are NOT valid declaration(s) of an interface?

a. public interface Question {


void method(int value) {
System.out.println("Nptel");
}
}

b. public interface Question {


void method(int value) {
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

}
}

c. public interface Question {

d. public interface Question {


default void method(int value) {
System.out.println("Nptel");

}
}

Correct Answer: a

Detailed Solution:

In option a , It has a method implementation in it. Only default and static methods have
implementations. So option a is not a valid interface. All others are valid.

_____________________________________________________________________________
QUESTION 9:
Which of the following is false statement about interface in java?

a. An interface can extend other interfaces.


b. The interface body can contain abstract methods, default methods, and static methods.
c. All constant values defined in an interface are implicitly public, static, and final.
d. A static method in an interface are implicitly private.
Correct Answer: d

Detailed Solution:

static methods in an interface are implicitly public. So you can omit the public modifier.

__________________________________________________________________________

QUESTION 10:
Which of the following statement(s) is/are true?
a. The default package in the Java language is java.lang.
b. String is a final class and it is present in java.lang package.
c. Cloneable is an interface in java.lang package.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

d. Thread is a class present in java.lang package.

Correct Answer: a,b,c,d

Detailed Solution:

All statements are true.

________________________________________________________________
************END************
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

PROGRAMMING IN JAVA
Assignment 5
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10 X 1 = 10
______________________________________________________________________________

QUESTION 1:
Which of the following is not true about throw

a. Throw is used inside a function


b. Throw can be used to declare multiple exception
c. Throw is followed by an instance.
d. Throw is a keyword

Correct Answer: b

Detailed Solution:
Throw keyword is used to throw an exception explicitly. It can throw only one exception at a time.

_________________________________________________________________________

QUESTION 2:
Which of the following is not true about custom exception in java?
a. class Exception extends Exp {
public Exception () {super () ;}
public Exception (String s) {super(s);}
}
b. class Exception extends Exp{
Exception(String s){
super(s);
}
}
c. public class Exception extends Exp {
public Exception(String s) {
super(s);
}
}
d. class Exception extends Exp {
public Exception () {super () ;}
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Correct Answer: d

Detailed Solution:
In a custom exception, the user will provide the massage which needs to be used as an argument
in the Exception () method. Hence, option (d) has no way to provide a custom exception.

_________________________________________________________________

QUESTION 3:
Which of the following is not a property of tagged interface?

a. Serializable
b. Cloneable
c. Remote
d. Cascading

Correct Answer: d

Detailed Solution:
Built-in marker or tagged interfaces are Serializable, Cloneable, and Remote.

______________________________________________________________________________

QUESTION 4:
Which of the following is not an exception in Java?
a. SQLException
b. ArrayIndexOutOfBoundException
c. OutOfMemoryError
d. StackOverflow

Correct Answer: d

Detailed Solution:
StackOverflow is not a valid exception in Java; instead StackOverflowError is thrown when a
stack overflow occurs because an application recurses too deeply.

______________________________________________________________________________

QUESTION 5:
Which of the following is type of Java Exception?
a. unchecked
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

b. checked
c. a & b
d. error

Correct Answer: c

Detailed Solution:
In java exception, there are two types of exception. Those are checked exception and unchecked
exception.

____________________________________________________________________________

QUESTION 6:
Which of the following keywords is not a part of exception handling?

a. try
b. throws
c. throw
d. thrown

Correct Answer: d

Detailed Solution:
Exceptional handling have 5 keywords – try, catch, throws, throw and finally.

_____________________________________________________________________________

QUESTION 7:
Which of the option is correct regarding multiple catch blocks?

a. The subclass exception cannot be caught at first.


b. The superclass exception cannot be caught at first.
c. The subclass exception must be caught at last.
d. The superclass exception must be caught at first.

Correct Answer: b

Detailed Solution:
The superclass exception cannot be caught at first else subclass exceptions will not be executed,
which will result in an error.
______________________________________________________________________________
QUESTION 8:
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

When an array element is accessed beyond the array size, then which exception occurs

a. ArrayElementOutOfBound
b. ArrayIndexOutOfBound
c. ArraySizeOutOfBound
d. None of the above

Correct Answer: d

Detailed Solution:
Array element is accessed beyond the array size then ArrayIndexOutOfBoundException occurs.

______________________________________________________________________________

QUESTION 9:
What is the output of this program?
class ExceptionHandling{
public static void main(String args[ ]) {
try{
int num1, num2;
num1=5;
num2=num1/0;
System.out.print("A");
}
catch(ArithmeticException e) {
System.out.print("0");
}
finally {
System.out.print("B");
}
}
}

a. 0
b. A
c. 0
d. 0B

Correct Answer: d

Detailed Solution:
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

There will be a divide-by-zero error in the statement num2 = num1/0; and as a consequence it will
throw an exception object of type ArithmeticException which will be caught by the catch
{ } block in the program. From the point of exception, the control will jump to the catch block and
then to the finally { } block.
______________________________________________________________________________

QUESTION 10:
When does an exception occur?

a. During the time of compilation of a Java program.


b. During the time of execution of a Java program.
c. Anytime, that is, during compilation and execution of a program.
d. At the end of execution of a Java program, if there is an exception.

Correct Answer: b

Detailed Solution:
Exception occurs when there is a run time error, that is, during the time of execution.

______________________________________________________________________________

************END************
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

PROGRAMMING IN JAVA
Assignment6
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10 × 1 = 10
______________________________________________________________________________

QUESTION 1:
Which of the following is NOT a method of the Thread class in Java?

a. public void run()


b. public void exit()
c. public void start()
d. public final int getPriority()

Correct Answer: b

Detailed Solution:

The java.lang.System.exit() method terminates the currently running Java Virtual Machine. It is a
status code where a nonzero or 1 indicates abnormal termination of the program whereas zero or
0 indicates normal termination of the program. It is not included in the thread class as it is not the
part of the execution cycle of the method.

____________________________________________________________________________

QUESTION 2:
What is difference between starting thread with run() and start() method?
a. There is no difference
b. When you call start() method, main thread internally calls run() method to start newly
created Thread
c. run() calls start() method internally
d. None
Correct Answer: b

Explaination:

Main difference is that when program calls start() method a new Thread is created and code
inside run() method is executed in new Thread while if you call run() method directly no
new Thread is created and code inside run() will execute on current Thread.

____________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 3:
Which of the following can be used to create an instance of Thread?

a. By implementing the Runnable interface.


b. By extending the Thread class.
c. By creating a new class named Thread and calling method run().
d. By importing the Thread class from package.

Correct Answer: a, b

Detailed Solution:

An application that creates an instance of Thread must provide the code that will run in that
thread. There are two ways to do this:

 Provide a Runnable object. The Runnable interface defines a single method, run, meant to contain the code
executed in the thread. The Runnable object is passed to the Thread constructor
 Subclass Thread. The Thread class itself implements Runnable, though its run method does nothing. An
application can subclass Thread, providing its own implementation of run

Reference:https://docs.oracle.com/javase/tutorial/essential/concurrency/runthread.html

____________________________________________________________________________

QUESTION 4:
What is the output of the following program?

public class Question


{
public static void main(String[] args) {

try {
int a=5/0;
System.out.print("a ");
} catch (ArithmeticException ae) {

System.out.print("ArithmeticException ");
}catch (Exception e) {
System.out.print(" Exception ");
}
System.out.print("Hello World");
}
}
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

a. Hello World
b. ArithmeticException
c. ArithmeticException Exception Hello World
d. ArithmeticException Hello World
Correct Answer: c

Detailed Solution: ArithmeticException is an unchecked exception in Java that occurs due to an


exceptional arithmetic condition. This generally indicates that a mathematical error has occurred
at run-time which can't be dealt with, for example, when an integer is divided by zero.

Since here devide by zero is already catched by Arithmatic exception so catch Exception block
will not execute.

____________________________________________________________________________
QUESTION 5:
Which method restarts a dead thread

a. start()
b. restart()
c. restartThread()
d. none

Correct Answer: d

Detailed Solution: Thread can not be restarted you have to create a new Thread everytime.
A thread is born, started, runs, and then dies.Once a thread enters dead state it cannot be
restarted.
____________________________________________________________________________
QUESTION 6:
Assume the following method is properly synchronized and called from a thread A on an
object B: wait(2000); After calling this method, when will the thread A become a candidate
to get another turn at the CPU?

a) After thread A is notified, or after two seconds.


b) Two seconds after thread A is notified.
c) After the lock on B is released, or after two seconds.
d) Two seconds after lock B is released.

Answer : a
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Explanation: Either of the two events (notification or wait time expiration) will make the thread
become a candidate for running again

____________________________________________________________________________
QUESTION 7:
The following is a simple program using the concept of thread.

public class Question extends Thread{


public void run(){
for(int i=1;i<5;i++){

System.out.println(++i);
}
}
public static void main(String args[]){
Question t1=new Question();
t1.run();

}
}

What is the output of the above program?

a. 1
3
b. 1
2
3
4
c. Runtime error
d. 2
4

Correct Answer: d

Detailed Solution:
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 8:
For the program given below, what will be the output after its execution?

public class Main{


public static void main(String[]args){
Thread thread=Thread.currentThread();
System.out.print(thread.activeCount());
thread.run();
System.out.print(thread.activeCount());
}
}

a. 01
b. False True
c. True True
d. 11

Correct Answer: d

Detailed Solution:

java.lang.Thread.activeCount() : Returns an estimate of the number of active threads in the current thread’s
thread group and its subgroups.

______________________________________________________________________________

QUESTION 9:
Which of the following is/are not a correct constructor for a thread object?

a. Thread(Runnable a, String str);


b. Thread(Runnable a, int priority);
c. Thread(Runnable a, ThreadGroup t);
d. Thread(int priority);

Correct Answer: b,c,d

Detailed Solution:
Thread(Runnable a, String str)creates a new Thread object. The others are not valid constructors
to create a thread object.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 10:
Which of these keywords is not a part of exception handling?

a) try
b) finally
c) thrown
d) catch

Answer: a,b,d

Explanation: Exceptional handling is managed via 5 keywords – try, catch, throws, throw and
finally.

____________________________________________________________

************END************
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

PROGRAMMING IN JAVA
Assignment7
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10 × 1 = 10
______________________________________________________________________________

QUESTION 1:
Which of the following streams contains the classes which can work on character stream?

a. InputStream
b. OutputStream
c. FileReader
d. FileWriter

Correct Answer: c, d

Detailed Solution:
Note: InputStream and OutputStream classes work on byte streams.

QUESTION 2:
In which Java APIs the classes for handling all IO-streams are defined?

a. java.lang
b. java.util
c. java.io
d. java.awt

Correct Answer: c

Detailed Solution:
java.io package is meant for handling io-streams in Java program.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 3:

import java.io.*;

public class Question {


public static void main(String[] args)
{
try {

PrintWriter writer = new PrintWriter(System.out);

writer.write(9+97);

writer.close();
}
catch (Exception e) {
System.out.println(e);
}
}
}

What will be the output if the above program is executed?


a. It will give compile-time error
b. It will give run-time error
c. j
d. 106

Correct Answer: c

Detailed Solution:

______________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 4:

import java.io.*;

public class Question7{


public static void main(String[]args){
try{
InputStream file =new FileInputStream("./Text.txt");
System.out.print(file.available());
}
catch(Exception e){
System.out.print(e);
}
}
}
The file ./Text.txt when opened with the Notepad text editor, it shows the content as shown
below.

Which of the following is the correct output for the ‘try’ portion of the code?

a. Prints the number of bytes in the file.


b. Prints the number of characters in the file.
c. Prints ‘true’, if the file is present; else prints ‘false’.
d. Prints nothing, as an exception will be caught.
Correct Answer: a
Detailed Solution:Returns an estimate of the number of remaining bytes that can be read (or skipped
over) from this input stream without blocking by the next invocation of a method for this input stream.
The next invocation might be the same thread or another thread. A single read or skip of this many bytes
will not block, but may read or skip fewer bytes.
______________________________________________________________________________

QUESTION 5:
Which method is used to write an array of byte to the current output stream?
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

a. public void write(int b)throws IOException


b. public void write(byte[ ] b)throws IOException
c. public void flush( )throws IOException
d. public void close( )throws IOException

Correct Answer: b

Detailed Solution:

public void write(byte[ ] b)throws IOException is used to write an array of byte to the current
output stream.

___________________________________________________________________________

QUESTION 6:
Which of the following is/are Standard Stream(s)?

a. System.in
b. System.out
c. System.err
d. System.console

Correct Answer: a,b,c

Detailed Solution:
The Java platform supports three Standard Streams: Standard Input, accessed
through System.in; Standard Output, accessed through System.out; and Standard Error, accessed
through System.err.

______________________________________________________________________________

QUESTION 7:
Which of the following method in java.io package help in clearing the contents of the
buffer?

a. flush ( )
b. clear( )
c. append( )
d. exit( )

Correct Answer: a
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Detailed Solution:

flush() : Flushes the stream.

Note: Clear( ) and exit( ) are not any valid methods defined in any class in java.io package.
______________________________________________________________________________

QUESTION 8:
Which method of RandomAccessFile class reads a line from the file and returns it as a
String ?

a. WriteInt( ).
b. readLine( )
c. readInt( )
d. WriteDouble( )

Correct Answer:b

Detailed Solution:

readLine() : Reads the next line of text from this file and return it as a String.

______________________________________________________________________________

QUESTION 9:
Which of the following is/are interface(s) of java.io package?

a. FileReader
b. ObjectInput
c. ObjectOutput
d. DataInput

Correct Answer: b,c,d

Detailed Solution:
FileReader is a class in java.io package. All others are interface.
___________________________________________________________________

QUESTION 10:
Which of the following statement(s) is/are true?
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

a. DataStreams detects an end-of-file condition by using EOFException, instead of


testing for an invalid return value.
b. DataStreams uses floating point numbers to represent monetary values.
c. Data streams support I/O of primitive data types.
d. Object streams support I/O of objects.

Correct Answer: a,b,c,d

Detailed Solution:

All options are correct.


DataStreams detects an end-of-file condition by catching EOFException, instead of testing for
an invalid return value.

__________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

PROGRAMMING IN JAVA
Assignment8
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10 × 1 = 10
______________________________________________________________________________

QUESTION 1:

Which of the following is NOT a class of java.awt package?

a. Button
b. Component
c. Dialog
d. Paint

Correct Answer: d

Detailed Solution:

Paint is the interface of the java.awt package.

___________________________________________________________________

QUESTION 2:
Which of the following is/are NOT an exception of java.awt package?

a. AWTError
b. AWTException
c. FontFormatException
d. all of these

Correct Answer: a

Detailed Solution:
AWTError is error of java.awt package.
_____________________________________________________________________

QUESTION 3:
Which of the following method is/are a class button of java.awt package ?
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

a. paint(Graphics g)
b. setLabel(String label)
c. getCurrent()
d. getItem(int index)

Correct Answer: b

Detailed Solution:
setLabel(String label) method Changes this button's label to be the String argument.

_________________________________________________________________________

QUESTION 4:
Which of the following container does not contain titlebar and menubar ?

a. window
b. panel
c. container
d. frame

Correct Answer: b

Detailed Solution:
Panel does not contain titlebar and menubar.

_________________________________________________________________

QUESTION 5:
Which package provides many event classes and Listener interfaces for event handling?

a. java.awt.activeevent
b. java.awt.event
c. java.awt.listener
d. none of these

Correct Answer: b

Detailed Solution:
The class Event is declared in java.awt.event package which is used for event classes and Listener
interfaces for event handling.

______________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 6:
What is the name of the method used to get the current font of an graphic in
java.awt.graphics?

a. abstract FontMetrics getFontMetrics(Font f)


b. abstract Font getFont()
c. FontMetrics getFontMetrics()
d. None of these

Correct Answer: b

Detailed Solution:
abstract Font getFont() method of graphics class get the current font of the graphics when it is
occurred.
___________________________________________________________________________

QUESTION 7:
Which of the following method remove all items from scrolling list in java.awt.list?

a. hide()
b. clear()
c. remove()
d. None

Correct Answer: b

Detailed Solution:
clear() in java.awt.list is used for remove all items from scrolling list.

_____________________________________________________________________________

QUESTION 8:
Which of the following statement is true about the update() in java.awt package?

a. Sets the color of the graphics context to be the foreground color of this component.
b. Calls this component's paint method to completely redraw this component.
c. Clears this component by filling it with the background color.
d. All of these.

Correct Answer: d
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Detailed Solution:
update() perform all of these in java.awt package.

_____________________________________________________________________________

QUESTION 9:
Which of the following methods can be used to return the current size size of a
java.awt.Component object?

a. dimension()
b. setSize()
c. area()
d. size()
e. resize()

Correct Answer: d

Detailed Solution:
size() can be used to return the current size of a component.
___________________________________________________________________________

QUESTION 10:
When we invoke update() for a java.awt.Component object, the AWT invokes which of the
following method ?

a. show( )
b. draw()
c. paint( )
d. repaint()

Correct Answer: c

Detailed Solution:
The repaint() method calls automatically update() method and in turn update() method calls
paint( ) method.

______________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

PROGRAMMING IN JAVA
Assignment9
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10× 1 = 10
______________________________________________________________________________

QUESTION 1:
Select the correct statement(s) in the following.

a. JTextField cannot be used as an alternative to JLabel.


b. JLabel cannot be used as an alternative to JTextField.
c. Button grouped radio button can be used as an alternative to JComboBox.
d. The class JPasswordField extends the class JLabel.

Correct Answer: b,c

Detailed Solution:
a) False: Setting JTextField property ‘setEditble=False’; it can be used as a label.
b) True: Label cannot be used to input data (it is never editble).
c) True: In a button grouped radio button, only one item can be selected similar to
JComboBox. So, they can be used interchangeably.
d) False: JPasswordField extends JTextField.

_________________________________________________________________________

QUESTION 2:
In Java AWT, TextArea and TextField are subclass of:

a. List.
b. Label.
c. TextComponent.
d. TextComponent and Label, respectively.

Correct Answer: c

Detailed Solution: TextArea and TextField are the two sub classes of TextComponent in Java
AWT.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 3:
Analyze the following code.

import java.awt.*;
import javax.swing.*;
public class Test {
public static void main(String[ ] args) {
JFrame frame = new JFrame("My Frame");
frame.add(new JButton("Cancel"));
frame.add(new JButton("OK "));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setVisible(true);
}
}
Which button will be displayed(or can be seen by user)?

a. OK
b. Cancel
c. both
d. None

Correct Answer: a

Detailed Solution:
By default, the layout of the content pane in a JFrame is BorderLayout. Button Cancel is placed
in the center of content pane, then button OK is placed in the same place. So you only can see
button OK.
______________________________________________________________________________

QUESTION 4:
In JLabel(Icon, int) method/constructor, the int argument specifies the horizontal
alignment of the label's contents within its drawing area.
Which of the following is/are not a valid constants for horizontal alignment?

a. RIGHT
b. LEADING
c. TRAILING
d. TOP

Correct Answer: d

Detailed Solution:
TOP is not a valid constant for horizontal alignment.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

____________________________________________________________________________

QUESTION 5:
Which of the following is/ are not related with keyboard event?

a. Class KeyEvent is used to notify if any key pressed occurs or not.


b. The KeyListener should be added either in init() or the main method.
c. RequestFocus should be added either in init() or the main method.
d. The class InputEvent should be imported explicitly in the program.

Correct Answer: d

Detailed Solution:
The InputEvent class is the super class of all the sub classes dealing with events from different
sources. When, we import java.awt.*, we import it automatically. No need to import it explicitly.

_____________________________________________________________________________

QUESTION 6:
Which of the following Listener(s) is/are supported by button (Swing component)?
a. ActionListener
b. ChangeListener
c. ItemListener
d. WindowListener

Correct Answer: a,b,c

Detailed Solution:

Except WindowListner, all other Listeners supported by button component.

_____________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 7:
Which of the following Listener Interface does not have an Adapter Class?
a. ActionListener
b. ChangeListener
c. ComponentListener
d. ItemListener
Correct Answer: a,b,d

Detailed Solution:
Only ComponentListener is having an Adapter class ComponentAdapter (among the options).

ActionListner,changeListner,ItemListner doesn’t have an Adapter class hence a,b,d is right


answer.

_________________________________________________________________________

QUESTION 8:
To set a FlowLayout in a panel, say jp, which of the following method(s) that you can not use?

a. jp.setLayout(new FlowLayout());
b. jp.setLayout(new FlowLayout(FlowLayout.CENTER));
c. jp.setLayout(new FlowLayout(FlowLayout.center));
d. jp.setLayout(FlowLayout());

Correct Answer: c, d

Detailed Solution:
(c) and (d) are not valid according to the syntax.

QUESTION 9:
Which of the following is/are interface(s) in javax.swing package?

a. MenuElement
b. BoxLayout
c. JComponent
d. Scrollable

Correct Answer: a, d

Detailed Solution:
MenuElement:
Any component that can be placed into a menu should implement this interface.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Scrollable:
An interface that provides information to a scrolling container like JScrollPane.

All others are Class.

_____________________________________________________________________________

QUESTION 10:
Which package provides many methods for graphics programming?

a. java.awt
b. java.Applet
c. java.Graphics
d. java.io

Correct Answer: a

Detailed Solution:
There is no package like java.Graphics and java.Applet. The Graphics class and other classes,
which are necessary for GUI programming is defined in java.awt package.
.
______________________________________________________________________

************END************
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

PROGRAMMING IN JAVA
Assignment10
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10 × 1 = 10
______________________________________________________________________________

QUESTION 1:
Which of these is a protocol for breaking and sending packets to an address across a
network?

a. TCP/IP
b. DNS
c. Socket
d. Proxy Server

Correct Answer: a

Detailed Solution:
TCP/IP is the protocol that breaks the packets and sends them in a network channel.

__________________________________________________________________________

QUESTION 2:
Which of the following statement(s) is/are false?

a. DatagramSocket is a UDP endpoint API .


b. DatagramSocket is a TCP server API .
c. ServerSocket is a TCP server API.
d. ServerSocket is a TCP client API.

Correct Answer: b,d

Detailed Solution:

ServerSocket is a TCP server API, and will typically accept connections from client sockets.
DatagramSocket is a UDP endpoint API and is used to send and receive datagram packets.
____________________________________________________________________________

QUESTION 3:
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

In the socket programming, for an IP address, which can be used to find the host name and IP
address of a client/ server?

a. The ServerSocket class


b. The Socket class
c. The InetAddress class
d. The Connection interface

Correct Answer: c

Detailed Solution:
An object of the InetAddress class is used to obtain the IP address and the host name of a client/
server computer connected in a network.

__________________________________________________________________________

QUESTION 4:
Which of the following package contains classes and interfaces for networking?

a. java.io
b. java.util
c. java.net
d. javax.swing

Correct Answer: c

Detailed Solution:
The java.net packages includes many classes and interfaces for network programming in Java.
_______________________________________________________________________

QUESTION 5:
In the following URL, identify the Resource name?

https://xyz.ac.in

a. https
b. xyz.ac.in
c. ac.in
d. https://xyz.ac.in

Correct Answer: b

Detailed Solution:
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Resource name is xyz.ac.in.

____________________________________________________________________________
QUESTION 6:
Which of the following is/are transport layer protocol(s)?

a. TCP
b. UDP
c. HTTP
d. FTP

Correct Answer: a,b

Detailed Solution:

TCP,UDP are transport layer protocols.

___________________________________________________________________________
QUESTION 7:
The package, which is required to be imported for the JDBC programming?

a. java.net
b. java.sql
c. java.lang
d. java.io

Correct Answer: b

Detailed Solution:
All classes and interfaces related to JDBC are defined in java.sql package.

_______________________________________________________________________
QUESTION 8:
Which of the following is/are valid Data Definition Language (DDL) command(s)?

a. SELECT
b. INSERT
c. UPDATE
d. ALTER TABLE
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

Correct Answer: d

Detailed Solution:
ALTER TABLE is a Data Definition Language (DDL).
_____________________________________________________________

QUESTION 9:
In JDBC, all raw data types (including binary documents or images) should be read and
uploaded to the database as an array of

a. int
b. char
c. byte
d. String

Correct Answer: c

Detailed Solution:
All data types should be read and uploaded to the database as an array of bytes.

______________________________________________________________________________

QUESTION 10:
Once a JDBC driver has been registered, which of the following method is used to make a
database connection?

a. getConnection(String url, String userID, String password)


b. setConnection(String url, String userID, String password)
c. Connect(String url, String userID, String password)
d. Connect(string url, string userID, string password).

Correct Answer: a

Detailed Solution:
The getConnection(String url, String userID, String password)
method is used to make the database connection.
__________________________________________________________

************END************
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

OBJECT ORIENTED PROGRAMMING WITH JAVA


Assignment11
TYPE OF QUESTION: MCQ
Number of questions: 10 Total mark: 10× 1 = 10
______________________________________________________________________________

QUESTION 1:
Which of the following is not a JDBC drivers?

a. Native – API driver


b. Thin driver
c. Network protocol driver
d. Local Protocol driver

Correct Answer: d

Detailed Solution:

There are 4 types of JDBC drivers : JDBC-ODBC bridge driver, network protocol driver, native-
API driver and thine driver.

_________________________________________________________________________

QUESTION 2:
Which of the following is a JDBC class component?

a. Connection
b. ResultSet
c. Statement
d. Driver

Correct Answer: b

Detailed Solution:

ResultSet is a JDBC class component and remaining are JDBC interface components.

_________________________________________________________________

QUESTION 3:
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

As with Statement objects, to execute a PreparedStatement object, it need to be call an


execute statement. Which of the following statement(s) is/are true regarding this?

a. executeQuery: if the query returns only one ResultSet (such as a SELECT SQL
statement).
b. executeUpdate : if the query does not return a ResultSet (such as an UPDATE SQL
statement).
c. execute : if the query might return more than one ResultSet object.
d. executupdateQuery : if the query does return a ResultSet (such as an UPDATE SQL
statement).

Correct Answer: a,b,c

Detailed Solution:

All options are correct except option (d).

__________________________________________________________________________

QUESTION 4:
Which of the following statement(s) is/are true, when the return value for executeUpdate is
0?

a. The statement executed was an update statement that affected zero rows.
b. The statement executed was a DDL statement.
c. The statement executed was an update statement that affected one row.
d. The statement executed was a DCL statement.

Correct Answer: a, b

Detailed Solution:

Either the statement executed was an update statement that affected zero rows or the statement
executed was a DDL statement, when the return value for executeUpdate is 0.

_____________________________________________________________________________

QUESTION 5:
Which of the following statement is used for executing a database stored procedure?
a. Statement
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

b. PreparedStatement
c. CallableStatement
d. None of these
Correct Answer: c

Detailed Solution:
CallableStatement in JDBC is used for executing a database stored procedure.

______________________________________________________________________________

QUESTION 6:
Once a JDBC driver has been registered, which of the following method is used to make a
database connection?

a. getConnection(String url, String userID, String password)


b. setConnection(String url, String userID, String password)
c. Connect(String url, String userID, String password)
d. Any one of the above.

Correct Answer: a

Detailed Solution:
The getConnection(String url, String userID, String password)
method is used to make the database connection.

______________________________________________________________________________

QUESTION 7:
The SQL command “USE test” implies, which of the following?

a. List all the databases those are there in the database server.
b. List all the tables those are there under the database.
c. Create a table called test.
d. Set test as the current working database, so that any SQL command bind to the test
database only.

Correct Answer: d

Detailed Solution:
The USE command is used to set the current working database.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 8:
What happens after execution of the following code?
import java.sql.*;
class InsertPrepared{
public static void main(String args[]){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost/database","Java","july");
PreparedStatement stmt=con.prepareStatement("INSERT INTO
table VALUES(?,?)");
stmt.setInt(1,"Joe");
stmt.setString(2,"Dan");
stmt.executeUpdate();
con.close();
}
catch(Exception e){
System.out.println(e);
}
}
}

a. Compilation error
b. Runtime error
c. 1,"Joe"is replaced by2,"Dan"
d. "Joe"and"Dan"both are inserted in different columns of same row.

Correct Answer: d
_________________________________________________________________

QUESTION 9:
How do you know in your Java program that a SQL warning is generated as a result of
executing a SQL statement in the database?
a. You must catch the checked SQLException which is thrown by the method which executes
the statement.
b. You must catch the unchecked SQLWarningException which is thrown by the method
which executes the statement.
c. You must invoke the getWarnings() method on the Statement object (or a sub interface
thereof ).
d. You must query the ResultSet object about possible warnings generated by the database.
Correct Answer: c

Detailed Solution:
The getWarnings() method can return, if the SQL database server returns any error or warning.
_____________________________________________________________________________
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 10:
Which one of the following SQL type represent getfloat()?

a. FLOAT
b. REAL
c. INTEGER
d. DOUBLE

Correct Answer: b

Detailed Solution:
REAL is a SQL type which represent getfloat(), that is a ResultSet method.
_____________________________________________________________________________

You might also like