CUET Information practice (IP) Chapter 3 Java Programming Fundamentals (Revision Tour-I)

  • Board
    CBSE
  • Textbook
    NCERT
  • Class
    Class 12
  • Subject
    Informative Practices (IP)
  • Chapter
    CUET Information practice (IP) Chapter 3 Java Programming Fundamentals (Revision Tour-I)
  • Chapter Name
    Chapter 3 Java Programming Fundamentals (Revision
  • Category
    CUET (Common University Entrance Test) UG

Practice MCQ Based questions for CUET Information practice (IP) Chapter 3 Java Programming Fundamentals (Revision Tour-I)

This page is created by HT experts and consists of MCQ-based questions with detailed explanations for CUET Information practice (IP) Chapter 3 Java Programming Fundamentals (Revision Tour-I). All the important concepts of Chapter 3 Java Programming Fundamentals (Revision Tour-I) for the CUET entrance exam are covered by MCQ questions with detailed explanations. Do solve chapter-wise MCQ questions for CUET Computer Science and CUET IP prepared by experts. 

MCQ Based questions for CUET Information practice (IP) Chapter 3 Java Programming Fundamentals (Revision Tour-I) Set-A

Informatics Practices - MCQ on Java GUI Programming Revision Tour-I

Class XII

Q.1 GUI are built from

a) icons.

b) containers.

c) controls.

d) classes.

Answer:

(c)

Explanation- GUI is built from GUI components known as control. A GUI component is an object with which the user interacts.

Q.2 GUI builder is also known as

a) Design area.

b) GUI creation.

c) Source area.

d) Java virtual machine.

Answer:

(a)

Explanation- GUI builder is also called Design area or Design space. It is the place where GUI design takes place in the IDE.

Q.3 Window which contains all the components needed to create GUI application is

a) Inspector window.

b) Code editor window.

c) Properties window.

d) Palette.

Answer:

(d)

Explanation- The Palette contains all the components needed to create GUI application. It includes the icons of various types of controls available under Java Swing API.

Q.4 While drawing a container control on the form, we first draw

a) container control.

b) child control.

c) toolkit.

d) swing.

Answer:

(a)

Explanation- First, a container control is drawn as it can hold other controls within it. Then controls are drawn inside the container known as child controls.

Q.5 When a button is pushed,

a) a message is generated.

b) an action event is generated.

c) a key event is generated.

d) mouse event is generated.

Answer:

(b)

Explanation- A user invokes the button by clicking over it and then action event gets activated.

Q.6 The listener interface that gets activated when the user presses a key on the keyboard is

a) ActionListener.

b) KeyListener.

c) ChangeListener.

d) FocusListener.

Answer:

(b)

Explanation- We can use this event (KeyEvent) to watch for specific keystrokes entered by the user.

Q. 7 Backspace, tab, carriage return etc. are examples of

a) graphic characters.

b) string characters.

c) missing characters.

d) non-graphic characters.

Answer:

(d)

Explanation- The characters that cannot be typed directly from the keyboard are called non-graphic characters. These can be represented by using escape sequences.

Q.8 Unicode characters can be represented in

a) 8 bits.

b) 16 bits.

c) 32 bits.

d) 64 bits.

Answer:

(b)

Explanation- Java programs display characters from the Unicode character set.

Q.9 A method that returns the text currently stored in a text based GUI component is

a) getText().

b) parse() method.

c) setText().

d) returnText().

Answer:

(a)

Explanation- The Swing components that support getText() method includes: TextField, TextArea, Button, Label etc.

Q.10 A component that displays an icon but that doesn’t react to user clicks is

a) textbox.

b) label.

c) list.

d) table.

Answer:

(b)

Explanation- With the JLabel class, we can display unselectable text and images.

Q.11 Swing components that do not rely on native GUI are referred to as

a) lightweight components.

b) heavyweight components.

c) GUI components.

d) non-GUI components.

Answer:

(a)

Explanation- A lightweight component directly implements the look-and-feel of the component in Java rather than delegating the look-and-feel to a native peer. Lightweight components can be more efficient at utilizing system resource and can be transparent.

Q.12 Java compiler translates Java source code into

a) java bytecode.

b) machine code.

c) assembly code.

d) another high-level language code.

Answer:

(a)

Explanation- Java compiler compiles the Java source code files (*.java) into binary files (*.class). Java bytecode is the form of instructions that the Java virtual machine executes.

Q.13 Pressing a button generates a/an

a) ItemEvent.

b) MouseEvent.

c) MouseMotionEvent.

d) ContainerEvent

Answer:

(d)

Explanation- The ContainerEvent class extends from the ComponentEvent class. This is a low-level event that is generated when container's contents change because of addition or removal of components.

Q.14 The operator ‘=’ is a/an

a) assignment operator.

b) relational operator.

c) comparison operator.

d) unary operator.

Answer:

(a)

Explanation- ‘=’ is used to assign a value. For example, value = 5 assigns 5 to value.

Q.15 IDE stands for

a) Integrated Developed Environment.

b) Integration Development Environment.

c) Integrated Development Environment.

d) Integration Developed Environment.

Answer:

(c)

Explanation- It is an application program consisting of different development tools needed for developing an application.

CUET Information practice (IP) Chapter 3 Java Programming Fundamentals (Revision Tour-I) Set-B

Q.16 JVM stands for

a) Java Vocal Machine.

b) Java Virtual Machine.

c) Java Vocal Macintosh.

d) Java Virtual Macintosh.

Answer:

(b)

Explanation- Java Virtual Machine is an abstract machine that is implemented on the top of the existing processors.

Q.17 RAD stands for

a) Rapid Application Development.

b) Rapid Access Development.

c) Rapid Application Data.

d) Rapid Access Data.

Answer:

(a)

Explanation- Rapid development of application is possible through RAD tools.

Q.18 To be a listener for ActionEvent, an object must be an instance of

a) ActionEvent.

b) ActionListener.

c) EventObject.

d) WindowListener.

Answer:

(b)

Explanation- The ActionListener interface must be implemented to capture an ActionEvent. This interface provides processAction () method, which is called when the ActionEvent for which the ActionListener is registered occurs.

Q.19 User clicking on a button, generates a/an

a) event.

b) button object.

c) container.

d) listener.

Answer:

(a)

Explanation- Whenever we click a mouse button, move the mouse or type on the computer keyboard, we are generating what is referred to as an event.

Q. 20 An object that defines a screen element such as a push button, text field, scroll bar, menu etc. is called

a) toolkit.

b) component.

c) container.

d) button.

Answer:

(b)

Explanation- The components that we use for creating a GUI in Java are available through Swing API.

Q. 21 AWT stands for

a) Atomic Weight Toolkit.

b) Abstract Window Toolkit.

c) Applet Wise Toolkit.

d) Absolute Window Toolkit.

Answer:

(b)

Explanation- Abstract Window Toolkit is a basic GUI toolkit of Java platform. Swing internally borrows functionality from AWT.

Q.22 Java compiler translates Java source code into

a) java bytecode.

b) machine code.

c) assembly code.

d) another high-level language code.

Answer:

(a)

Explanation- Java compiler compiles the Java source code files (*.java) into binary files (*.class). Java bytecode is the form of instructions that the Java virtual machine executes.

Q.23 The area on the frame where GUI components are placed is called

a) container.

b) content pane.

c) label.

d) control.

Answer:

(b)

Explanation- GUI components include container control and child control. These controls can be drawn on forms/windows/frames.

Q.24 When a button is pushed,

a) a message is generated.

b) an action event is generated.

c) a key event is generated.

d) mouse event is generated.

Answer:

(b)

Explanation- A user invokes the button by clicking over it and then Action Event gets activated.

Q. 25 Java programs are compiled into Java

a) setup.

b) interpreter.

c) compiler.

d) bytecode.

Answer:

(d)

Explanation- The Java byte code looks a lot like machine language. It is a machine instruction for a Java processor chip called Java Virtual Machine.

Q.26 An object that represents some occurrence, is an

a) event source.

b) event listener.

c) event.

d) event driven interface.

Answer:

(c)

Explanation- A software message indicating that something has happened such as a keystroke or mouse click.

Q.27 Java solves the problem of platform-independence by using

a) intermediate code.

b) partial code.

c) virtual code.

d) byte code.

Answer:

(d)

Explanation- Java programs can run on any platform. This is because java code is first converted to byte code, which is platform independent. Then it is translated into the native language of host machine using interpreter.

Q.28 The other name for floating literals is

a) real literals.

b) constant literals.

c) boolean literals.

d) string literals.

Answer:

(a)

Explanation- Real literals are numbers having fractional parts.

Q.29 Classes, arrays and interface are examples of

a) primitive data types.

b) reference data types.

c) fundamental data types.

d) boolean data types.

Answer:

(b)

Explanation- The variables storing memory addresses are known as reference variables and their data type is known as reference data type.

Q.30 A named memory location, which holds a data value of a particular data type is a

a) variable.

b) reference.

c) string.

d) object.

Answer:

(a)

Explanation- Variables represent named storage locations whose values can be manipulated.

Q.31 parse() methods are used to obtain

a) text, i.e., string type of data from a GUI component.

b) boolean type of data from a GUI component.

c) numeric type data from a GUI component.

d) character type of data from a GUI component.

Answer:

(c)

Explanation- parse() methods are used to convert textual data into a numeric type. For example, when we want to read the age of a person through text field.

 

Q.32 If Student is an object, then roll no, name, marks etc. are its

a) classes.

b) behaviour.

c) methods.

d) attributes.

Answer:

(d)

Explanation- These are the characteristics or properties. Its behaviour is: it takes rest, it attends lectures etc.

Q.33 The expression: ! (1 &&0 || !1 evaluates to

a) false.

b) error.

c) run time error.

d) true.

Answer:

(d)

Explanation- In the above expression, first && operator executes, followed by ||. Thus, the result 1 is obtained which corresponds to true.

Q.34 During a program run, literals are

a) constants.

b) varying float numbers.

c) varying integers.

d) string.

Answer:

(a)

Explanation- Literals are data items that never change their value during a program run. They are integer constant, character-constant, floating constant and string–literal.

Q.35 Keywords as normal identifier names

a) cannot be used.

b) can be used.

c) may/ may not be used.

d) can only be used.

Answer:

(a)

Explanation- Keywords are the words that convey a special meaning to a language compiler. They cannot be used as identifier names.

Q.36 The smallest individual unit in a program is

a) token.

b) character.

c) string.

d) unicode.

Answer:

(a)

Explanation: Every unit that makes a sentence in java is a token.

Q.37 The number of tokens available in Java is

a) two.

b) three.

c) four.

d) five.

Answer:

(d)

Explanation- The tokens are: Keywords, Identifiers, Literals, Punctuators and Operators.

Q.38 Java is both compiled and

a) interpreted.

b) run.

c) transferred.

d) accessed.

Answer:

(a)

Explanation- At first, the Java source code (in .java files) is compiled into Bytecode. When the Java application is started, the Bytecode is interpreted by the Java Virtual Machine.

Q.39 The difference between a TextArea and a TextField is

a) TextArea can handle multiple lines of text.

b) TextArea can be used for output.

c) TextArea is not a class.

d) TextAreas are used for displaying graphics.

Answer:

(a)

Explanation- The JTextArea class provides a component that displays multiple lines of text and optionally allows the user to edit the text. If you need to obtain only one line of input from the user, you should use a text field.

Q.40 The value of k after the following code fragment is

int k = 0;

int n = 12

while (k < n)

{

k = k + 1;

}

a) 0.

b) 11.

c) 12.

d) Unknown.

Answer:

(c)

Explanation: The above code takes the value of k less than n, i.e., while k<12, the code executes and add 1 when k=11.

Q.41 The following line of code means

double table[ ];

a) table is a variable to refers to a real number.

b) table is a variable that refers to two numbers.

c) it is not legal Java code.

d) table is a variable that refers to an array.

Answer:

(d)

Explanation: Variables represent named storage locations; they hold a data value of a particular data type. Here, table is a variable that refers to an array type.

Q.42 Control statements that allow the program to choose different paths of execution is

a) Iteration.

b) Selection.

c) Sequence.

d) Looping.

Answer:

(b)

Explanation- Selection statements are used in a program to choose different paths of execution based upon the outcome of an expression or the state of a variable. Java supports two selection statements: if and switch.

Q.43 Control statements enable program execution to repeat one or more statements is

a) Iteration.

b) Selection.

c) Sequence.

d) Looping.

Answer:

(a)

Explanation- Iteration statements enable program execution to repeat one or more statements, i.e., iteration statements form loops. In Java, there are three iteration statements: for, while and do.

Q.44 Control statements that allow the program to execute in a non-linear fashion is

a) switch.

b) if-else.

c) jump.

d) goto.

Answer:

(c)

Explanation- Jump statements are used to unconditionally transfer the program control to another part of the program. Java has three jump statements: break, continue, and return.

Q.45 The statement in which the value of the expression is compared with each of the literal values in case statements is

a) switch.

b) goto.

c) if-else.

d) jump.

Answer:

(a)

Explanation- The switch statement executes by comparing the value of the expression with each of the constants after the case statements. If a match is found, the statements following that case statement are executed. Otherwise the statements following the default statement (if present) are executed. Conventionally, the default label is put after all the case labels but it may appear anywhere in the block.

Q.46 Loop that repeats a set of statements a certain number of times until a condition is matched is

a) goto.

b) if-else.

c) switch.

d) for loop.

Answer:

(d)

Explanation- for loop is the most versatile looping construct. It is used to continuously execute a block of code until a particular condition is satisfied. It comprises three parts: initialization, condition and iteration.

Q.47 Java assignment operator is

a) ==

b) :=

c) =

d) =:

Answer:

(c)

Explanation- Java offers an assignment operator=, to assign one value to another, e.g., int x=10;

Q.48 To assign a value 1 to variable x, we write

a) 1 = x;

b) x = 1;

c) x := 1;

d) 1 := x;

Answer:

(b)

Explanation- Like other programming languages, Java offers an assignment operator =, to assign value to a variable. Example, int x=1;

Q.49 Data type requires the most amount of memory is

a) long.

b) int.

c) short.

d) byte.

Answer:

(a)

Explanation- The long data type is a 64-bit signed two's complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). We Use this data type when we need a range of values wider than those provided by int.

Q.50 To declare an int variable number with initial value 2, we write

a) int number = 2L;

b) int number = 2l;

c) int number = 2;

d) int number = 2.0;

Answer:

(c)

Explanation- The syntax to declare a new variable is to write the specifier of the desired data type (like int,..) followed by a valid variable identifier. For example, int number = 2;

CUET Information practice (IP) Chapter 3 Java Programming Fundamentals (Revision Tour-I) Set-C

Q.51 The result of 45 / 4 is

a) 10.

b) 11.

c) 11.25.

d) 12.

Answer:

(b)

Explanation- 45 / 4 is an integer division, which results in 11.

Q.52 The expression that results a value 1 is

a) 2 % 1.

b) 15 % 4.

c) 25 % 5.

d) 37 % 6.

Answer:

(d)

Explanation- 2 % 1 is 0, 15 % 4 is 3, 25 % 5 is 0 and 37 % 6 is 1.

Q.53 The value of i in following code as output is

public class Test {

public static void main(String[ ] args) {

int j = 0;

int i = ++j + j * 5;

System.out.println("What is i? " + i);

} }

a) 0

b) 1.

c) 5.

d) 6.

Answer:

(d)

Explanation- Operands are evaluated from left to right in Java. The left-hand operand of a binary operator is evaluated before any part of the right-hand operand is evaluated. This rule takes precedence over any other rules that govern expressions. Therefore, ++j is evaluated first, and returns 1. Then j*5 is evaluated, so i=6.

Q.54 The value of y displayed in the following code is

public class Test {

public static void main(String[ ] args) {

int x = 1;

int y = x++ + x;

System.out.println("y is " + y);

} }

a)1.

b) 2.

c) 3.

d) 4.

Answer:

(c)

Explanation- When evaluating x++ + x, x++ is evaluated first, returns 1 since it is post-increment. x becomes 2. Therefore, y is 1 + 2.

Q.55 The value of y displayed in the following code is

public class Test {

public static void main(String[] args) {

int x = 1;

int y = x + x++;

System.out.println("y is " + y);

} }

a)1.

b) 2.

c) 3.

d) 4.

Answer:

(b)

Explanation- When evaluating x + x++, x is evaluated first, which is 1. X++ returns 1 since it is post-increment and 2. Therefore, y is 1 + 1.

Q.56 If we attempt to add an int, a byte, a long and a double, the result will be a

a) byte.

b) int.

c) long.

d) double.

Answer:

(d)

Explanation- The double data type is a double-precision 64-bit floating point. It covers a range from 4.94065645841246544e-324d to 1.79769313486231570e+308d (positive or negative).

Q.57 A Java character is stored in

a) one byte.

b) two bytes.

c) three bytes.

d) four bytes.

Answer:

(b)

Explanation- Java characters use Unicode encoding. Unicode is a two-byte character code set that has characters representing almost all characters.

Q.58 The two parts of a value of type float is

a) significant digits and exponent.

b) mode and numerator.

c) length and exponent.

d) numerator and denominator.

Answer:

(a)

Explanation- Floating point describes a system for representing numbers that would be too large or too small to be represented as integers. Numbers in general are represented approximately to a fixed number of significant digits and scaled using an exponent. The base for the scaling is normally 2, 10 or 16. The typical number that can be represented exactly is of the form:

significant digits × baseexponent

Q.59 An infinite loop is a loop that

a) functions infinitely well.

b) runs forever.

c) never starts.

d) will never function.

Answer:

(b)

Explanation- An infinite loop is a sequence of instructions in a computer program, which loops endlessly either due to the loop having no terminating condition, having one that can never be met or one that causes the loop to start over.

Q.60 A component that displays an icon but that doesn’t react to user clicks is

a) textbox.

b) label.

c) list.

d) table.

Answer:

(b)

Explanation- With the JLabel class, we can display unselectable text and images.

Q.61 A self contained graphic entity that can be customized is

a) Swing component.

b) Swing container.

c) Java Applets.

d) Java Foundation Classes.

Answer:

(a)

Explanation- A Swing component is a self-contained graphic entity that can be customized and inserted into applications. For example, Jlabel, Jbutton etc.

Q.62 JButton, JCheckBox are

a) Interactive Displays.

b) Containers.

c) Abstract Window Toolkit.

d) Basic Controls.

Answer:

(d)

Explanation- Basic Swing Controls are simple components that are used primarily to get input from the user.

Q.63 A component that enables the user to choose a single value or multiple values is a

a) text field.

b) combo box.

c) list.

d) label.

Answer:

(c)

Explanation- A list is a component that performs basically the same function as a combo box but it enables the user to choose a single value or multiple values.

Q. 64 Heavyweight and lightweight components can (with a few exceptions) be grouped as follows

a) Swing and AWT components.

b) Frames and Panels.

c) AWT and Swing components.

d) Panels and Frames.

Answer:

(c)

Explanation- AWT Components are called heavyweight components because of their dependency on native libraries. Swing components are called lightweight due to their independence of native libraries. Hence, Swing operations are much faster.

Q.65 java.swing.JComponent is the parent of almost all Swing components. It is a direct subclass of

a) java.awt.Frame.

b) java.awt.Container.

c) java.lang.Object.

d) SwingUtilities.

Answer:

(b)

Explanation- A container is a component that holds other components. The base class for all containers is java.awt.Container, which is a subclass of java.awt.Component.

Q.66. The program which is written to respond to the button clicks, menu selections and other actions of the user in whatever order the user does them is

a) event-driven.

b) action-driven.

c) user-driven.

d) mouse-driven.

Answer:

(a)

Explanation- Event-driven programs do not have a set sequence of instructions to execute. They also do not have a predetermined finish. The most common example of event-driven programming is found in graphical user interfaces (GUIs).

Q.67. The fundamental classes for GUI programming are contained in the

a) GUI toolkit.

b) Abstract Windowing Toolkit.

c) Graphics Event Toolkit.

d) Java Enhancement Toolkit.

Answer:

(b)

Explanation- The Abstract Window Toolkit (AWT) is a package of JDK classes for creating GUI components such as buttons, menus and scrollbars for applets and standalone applications.

Q.68. The three software parts of a GUI program are

a) Windows, Buttons, Mice.

b) GUI Components, Graphics, Code.

c) GUI Components, Event Listeners, Application Code.

d) Frames, Code, Events.

Answer:

(c)

Explanation- A GUI program consists of three types of software:Graphical components make up the Graphical User Interface. Listener methods receive the events and respond to them. Application methods do useful work for the user.

Q.69. The one component that nearly all GUI programs will have is

a) Window.

b) Mouse.

c) Monitor.

d) Button.

Answer:

(a)

Explanation- Window is a visual area containing some kind of user interface. Windows are primarily associated with graphical displays, where they can be manipulated with a mouse cursor.

Q.70. A containerobject in GUI programming is

a) another name for an array or vector.

b) any class that is made up of other classes.

c) a primitive variable that contains the actual data.

d) a GUI component that has other GUI components placed inside of it.

Answer:

(d)

Explanation- A container is a component, which allows a Container object to be placed inside another Container object. For example, a Panel is a Container and a Frame is a Container. Panel is also a Component so it can be placed inside a Frame.

Q.71. When the user clicks on a button, a/an

a) Event, is generated.

b) Button object is generated.

c) Container is generated.

d) Listener is generated.

Answer:

(a)

Explanation: Every component broadcasts events when a user interacts with it. When a user clicks a Button, e.g., it dispatches a MouseEvent.CLICK event and when a user selects an item in a List, the List dispatches an Event.CHANGE event.

Q.72. The name for a method that responds to events is a

a) container method.

b) snoop method.

c) listener method.

d) application method.

Answer:

(c)

Explanation- A listener is called when the user does something to the user interface that causes an event. Listener methods are a kind of call back; they are triggered when a form is submitted or a link is clicked.

Q.73. The base class of all Swing classes is

a) Object.

b) Component.

c) Swing.

d) JComponent.

Answer:

(d)

Explanation- With the exception of top-level containers, all Swing components whose names begin with "J" descend from the JComponent class. For example, JPanel, JScrollPane, JButton and JTable all inherit from JComponent. The JComponent class extends the Container class, which itself extends Component.

Q.74. The meaning of variable++ is

a) add one to the variable.

b) add one to the variable after its current value has been used.

c) add one to the variable before using its value.

d) double the value in the variable.

Answer:

(b)

Explanation- Increment the variable by one; evaluates to the value of variable before it was incremented.

Q.75. The following program output to the monitor is

int value = 0;

int count = 1;

value = count++;

System.out.println("value:"+value "+count:"+ count);

a) value: 0 count: 0.

b) value: 0 count: 1.

c) value: 1 count: 1.

d) value: 1 count: 2.

Answer:

(d)

Explanation: +value is incremented by 1, before it is evaluated, i.e., value =1 and similarly, count is incremented by 1.

Q.76. The following program output to the monitor is

int value = 0;

int count = 1;

value = ++count ;

System.out.println("value: "+ value " + count: " + count );

a) value: 0 count: 1.

b) value: 1 count: 1.

c) value: 1 count: 2.

d) value: 2 count: 2.

Answer:

(d)

Explanation- ++count is evaluated after it is incremented. Hence, int count becomes 2 and assigned to value.

Q.77. The output of the following code is

int a = 0;

int b = 10;

a = --b ;

System.out.println("a: " + a + " b: " + b );

a) a: 9 b:11.

b) a: 10 b: 9.

c) a: 9 b:9.

d) a: 0 b:9.

Answer:

(c)

Explanation- operator(--op) decrements op by 1. In this case, variable b is decremented by 1 and then assigned to variable a. Hence, a=9 and b=9.

Q.78. The output of the following program is

double w = 12.5 ;

w *= 2 ;

System.out.println( " w is " + w );

a) w is 12.5.

b) w is 13.5.

c) w is 25.0.

d) d) w is 2.

Answer:

(c)

Explanation- A double variable usually uses 64 bits to store its value. This primitive type store fractional number.

Q.79. An operator having the HIGHEST precedence is

a) (unary)- !

b) * /

c) + -

d) < <= > >=

Answer:

(a)

Explanation- Java has well-defined rules for specifying the order in which the operators in an expression are evaluated when the expression has several operators. Operator precedence determines the order in which expressions are evaluated.

Q.80. An operators having the LOWEST precedence is

a) == !=

b) && ||

c) < <= > >=

d) * /

Answer:

(b)

Explanation- Java has well-defined rules for specifying the order in which the operators in an expression are evaluated when the expression has several operators. For example, multiplication and division have a higher precedence than addition and subtraction. Precedence rules can be overridden by explicit parentheses.

Q.81. The three general types of looping structures are

a) counting loop, sentinel-controlled loop and result-controlled loop.

b) infinite loop, counting loop and nested loop.

c) while loop, for loop and do loop.

d) count up loop, count down loop and infinite loop.

Answer:

(a)

Explanation- In a program, statements may be executed sequentially, selectively or iteratively. A common type of program loop that is controlled by an integer that counts up from an initial value to an upper limit. Such a loop is called a counting loop. In a Sentinel-Controlled loop, a special value called a sentinel value is used to change the loop control expression from true to false. Example while loop. A result-controlled loop keeps looping until the computation has reached a particular goal.

Q.82. The output of the following program fragment is

for ( int j = 0; j < 5; j++ )

{

System.out.print( j + " " );

}

System.out.println( );

a) 0 1 2 3 4 5.

b) 0 1 2 3 4.

c) 0 1 2 3 4 5.

d) j j j j j.

Answer:

(b)

Explanation- First initialization expression is executed, i.e., j=0 which gives the first value 1 to variable j. Then the test expression is evaluated, i.e., j<5 which results into true. Since the test expression is true, the body of the loop is executed, after executing the loop body, the update expression j++ is executed, which increments the value of j. After the update expression is executed, the test expression is again evaluated and sequence is repeated otherwise the loop is terminated (when j=5.

Q.83. The output of the following code fragment is

for ( int j = 10; j > 5; j-- )

{

System.out.print( j + " " );

}

System.out.println( );

a) 10 11 12 13 14 15.

b) 9 8 7 6 5 4 3 2 1 0.

c) 10 9 8 7 6 5.

d) 10 9 8 7 6.

Answer:

(d)

Explanation- First initialization expression is executed, i.e., j=10 which gives the first value 10 to variable j. Then the test expression is evaluated, i.e., j>5 which results into true. Since the test expression is true, the body of the loop is executed, after executing the loop body, the update expression j-- is executed, which decrements the value of j. After the update expression is executed, the test expression is again evaluated and sequence is repeated, otherwise the loop is terminated (when j=5.

Q.84. The change to be done so that the following fragment prints out the even integers 0 2 4 6 8 10 are

for ( int j = 0; j <= 10; )

System.out.print( j + " " );

System.out.println( );

a) j+2.

b) j = j+2.

c) j++++.

d) ++j++.

Answer:

(b)

Explanation- Update expression is required after the test expression, so that the values of loop variable changes. J=j+2 will increment the value of j by 2 and give the required output.

Q.85. The output of the following code fragment is

for ( int j = 5; j > -5; j-- )

System.out.print( j + " " );

System.out.println( );

a) -5 -4 -3 -2 -1 0.

b) 5 4 3 2 1 0.

c) 5 4 3 2 1 0 -1 -2 -3 -4 -5.

d) 5 4 3 2 1 0 -1 -2 -3 -4.

Answer:

(d)

Explanation- First initialization expression is executed, i.e., j=5 which gives the first value 5 to variable j. Then the test expression is evaluated, i.e., j>-5 which results into true. Since the test expression is true, the body of the loop is executed, after executing the loop body, the update expression j-- is executed, which decrements the value of j. After the update expression is executed, the test expression is again evaluated and sequence is repeated, otherwise the loop is terminated (when j>-5.

Q.86. The value placed in var is

var = 12 > 9 ? 0 : 1;

a) 0.

b) 1.

c) 9.

d) 12.

Answer:

(a)

Explanation- The value placed in var is 0 as 12 is greater than 9; so, first value is placed in var else if the condition has been false than the second value would be placed is var.

Q.87. The value placed in p is

int x = 5, y = 19;

p = y-x > x-y ? y-x : x-y ;

a) 5.

b) 19.

c) 14.

d) -14.

Answer:

(c)

Explanation- (19-5=14 > (5-19=-14 ? 14:-14, results in 14>-14; so, the first value is assigned to p, i.e., p=14.

Q.88. The value placed in choice is

int a=5, b=10, c=15 ;

choice = a>b && a>c ? a : (b > c ? b : c) ;

a) 5.

b) 10.

c) 15.

d) 0.

Answer:

(c)

Explanation-choice=(5>10&&5>15?5:(10>15?10:15

In(10>15?10:15expression, condition is false so the result is 15, similarly in (5>10&&5>15 the condition is false; so, the result is 15.

Q.89. The value placed in sum is

double sum = 10.0, price=100;

sum += price>=100 ? price*1.1 : price;

a) 90.

b) 100.

c) 110.

d) 120.

Answer:

(d)

Explanation- sum += price>=100 results in sum+=100 and price *1.1 = 110:100 since the first condition is true; therefore, sum=10+110, i.e., 120.

Q.90.The following statement print

int count = 10;

do

{

System.out.print( count +" ");

count-- ;

}

while ( count >= 5 );

a) 10 9 8 7 6 5.

b) 10 9 8 7 6 5 4.

c) 9 8 7 6 5.

d) 9 8 7 6 5 4.

Answer:

(a)

Explanation- do-while is an exit controlled loop, it evaluates its test expression at the bottom of the loop. The statement is executed from count 10 and terminates when count is less than 5.

Q.91 The type of loop implemented with a do statement is

a) top-driven loop.

b) bottom-driven loop.

c) off-by-one loop.

d) while loop.

Answer:

(b)

Explanation- Loops implemented with the test at the bottom (a do loop) are called bottom-driven loops.

Q.92. The branching statements in a programming language are

a) statements that affect the execution of loops.

b) statements like if that make choices.

c) statements that evaluate Boolean expressions.

d) statements that are used to build classes.

Answer:

(b)

Explanation- Branching statements allow different sections of code to be executed or not to be executed depending on some condition either being true or false. For example, if, if .. else, while, do, switch and for constructs.

Q.93. A sequence of statements contained within a pair of braces ("{" and "}") is called a

a) block.

b) blob.

c) branch.

d) brick.

Answer:

(a)

Explanation- A block is a sequence of statements, local class declarations and local variable declaration statements within braces.

Q.94. The output of the following code fragment is

for ( int count = 0; count <= 20; count+=2 )

System.out.print( count + " " );

System.out.println( );

a) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20.

b) 0 2 4 6 8 10.

c) 0 2 4 6 8 10 12 14 16 18.

d) 0 2 4 6 8 10 12 14 16 18 20.

Answer:

(d)

Explanation- The above code initializes the variable by 0. Test expression is evaluated, i.e., count<=20, which is true then loop is executed and expression is updated, i.e., incremented by 2. Loop terminates when count =20.

Q.95. An event object

a) represents one specific event, such as a mouse click.

b) is an object that listens for mouse clicks.

c) is a list of all the events that have happened in the system.

d) is what program does in response to an event.

Answer:

(a)

Explanation- An event in Java is represented as an object. When the user generates an event, the Java system creates an event object. The event object is then sent to the listener that has been registered for the GUI component.

Q.96. An object that waits for and responds to an event from a GUI component is a

a) event listener.

b) GUI listener.

c) collection class.

d) click listener.

Answer:

(a)

Explanation- An event listener is an object to which a component has delegated the task of handling a particular kind of event. In other words, if we want an object in the program to respond to another object, which is generating events; we must register object with the event generating object and then handle the generated events when it comes.

Q. 97. The letter with which many Swing class names start with is

a) A.

b) B.

c) J.

d) S.

Answer:

(c)

Explanation- In Swing, classes that represent GUI components have names beginning with the letter J. Some examples are JButton, JLabel and JSlider.

Q.98 The base class of all Swing classes is

a)Object.

b) Component.

c) Swing.

d) JComponent.

Answer:

(d)

Explanation- The JComponent class of the javax.swing package serves as the base class.

Q.99 Number of times is a do while loop guaranteed to loop is

a) 0.

b) Infinitely.

c) 1.

d) Variable.

Answer:

(c)

Explanation- do-while loop is always executed at least once. It evaluates its test-expression at the bottom of the loop after executing its loop-body statements.

Q.100 Statement that is required to avoid falling-through from one case to the next is

a) end;

b) break;

c) stop;

d) semicolon

Answer:

(b)

Explanation- Break is a keyword that breaks out of the code block, usually surrounded by braces, which it is in. Break prevents the program from falling through and executing the code in all the other case statements.