Sunteți pe pagina 1din 34

AY001 Which of the following process converts Java programming language code to a set of bytecodes?

1, Bytecode verification 2, Compilation 3, Class loading 4,Execution 2 AY002 Which of the following values is a type of the boolean data type?

1, 'true' 2, "true" 3, true 4, boolean 3 AY003 Your program needs to use the App class present in the foo.bar package. Which of the following statements imports the class to your program? m 1, import App; m 2, imports foo..bar.App; m 3, import foo.bar.*; m 4, import foo.*; 3

AY004 Consider the following statements: Statement A: String is a primitive data type to represent a sequence of characters. Statement B: You can declare a String variable as:String str="I am a String"; Select the correct option for the preceding statements: 1, Stetement A is true while Statement B is false. 2, Both Statement A and Statement B are true. 3, Statement A is false while Statement B is true. 4, Both Statement A and Statement B are false.

AY005 Consider the following statements: Statement A: A constructor must have the same name as that of the class. Statement B: The return type of a constructor must be void. Select the correct option for the preceding statements:

1, Both Statement A and Statement B are true. 2, Both Statement A and Statement B are false. 3, Statement A is true while Statement B is false.4, Statement A is false while Statement B is true. 3

AY006 Select the correct integer length for the int data type. 1, 8 bits 2, 16 bits 3, 32 bits 4, 64 bits 3 AY007 Which of the following is a valid Java identifier? 1, $const 2, const 3, long 4, new 1 AY008 The _____________ option of the compiler enables you to compile class files to a different directory than that of the source files. 1, -cp 2, -source 3, -g 4, -d AY009 Select the correct option that shows the command to execute the MyApp Java class. 1, java class=MyApp 2, javac MyApp.java 3, java MyApp.java 4, java MyApp 4 AY010 To compile and execute Java programs, you need to set the PATH environment variable to ___________________. 1, The working directory that contains the source files of the program. 2, The java_root/lib directory, where java_root is the installation directory of the Java technology software. 3, The java_root/bin directory, where java_root is the installation directory of theJava technology software. 4, The installation directory of the Java technology software. 3 4

AY011 ________ is the default value of the double datatype: 1, 1 2, 0.0D 3, 1.0D 4, null

3 AY012 The _________ variables of a class are created when the class is loaded and continues to exist as long as the class is loaded. 1, static 2, member 3, local 4, instance

1 AY013 All Java classes directly or indirectly extends the _______ class. 1, Main 2, Class 3, String 4, Object

4 AY014 In a Java program, a Manager class extends an Employee super class. Which of the following statement will you use in the Manager class to invoke the default constructor of the Employee class? 1, super(); 2, Employee(); 3, Manager.super(); 4, Employee.super(); 1

AY015 Consider the following code: public class Example { public static void main(String args[]) { String [] direction = {"East","West","North","South"}; System.out.println(direction[4]); } }

What will be the outcome when the preceding code is executed? 1, The code will execute and display South as the output. 2, The code will throw a runtime exception. 3, The code will execute and display North as the output. 4, The code will execute but will not display any output.

AY016 Consider the following code: public class Example { public static void main(String [] args) { for(int i=1; i<5; i++) { System.out.println("Hello"); } } } On execution how many times the above code will display the Hello word? 1, 0 2, 4 4, 6 3, 5

2 AY017 Consider the following code: public class Example{ public static void main (String args []) { String str; str = str+"Hello world"; System.out.println(str); } } What will be the outcome on compiling and executing the preceding code? 1, The code will execute with the output Hello world Hello world 2, The code will execute with theoutput Hello world 3, The code will not compile 4, The code will compel but will not execute.3 AY018 Which of the following options will you use to determine the number of elements that an array contains? 1, size 2, length() 3, length 4, size() m

3 AY019 Which of the following options is a short-circuit logical operator? 1, &&&& 2, && m 3, | m 4, ! m 1 AY020 Consider the following code: public class Example { static int num; public static void main(String args[]) { System.out.println(num); } } What will be the outcome on executing the following code? 1, The code will execute and display null. 2, The code will execute and display 0. 3, The code will execute and display 1. 4, The code will throw an exception as the num variable is not initialized.

2 AY021 Which of the following code will compile, execute, and display the word Hello? 1, public class Example { public static void main(String args[]) { int num1; int num2; if(num1==num2) { System.out.println("Hello"); } } } 2, public class Example { public static void main(String args[]) { String str1=new String("Hello");// correct but cant cmpare String str2=new String("Hello"); if(str1==str2) { System.out.println("Hello"); } } } 3, public class Example

{ public static void main(String args[]) { String str1="Hello"; String str2="Hello"; if(str1==str2) { System.out.println("Hello"); } } } 4, public class Example { public static void main(String args[]) { String str1="hello"; String str2="Hello"; if(str1.equals(str2)) // correct comparing { System.out.println("Hello"); } } }

AY022 Consider the following code: public class Example { public static void main(String args[]) { String [] names = {"Linux","Unix","Windows","Mac OS"}; for(String list : names ) System.out.println(list); } } Select the correct option for the preceding code? 1, The code will execute but will not display any output. 2, The code will not compile. 3, The code will execute and display Linux, Unix, Windows, and Mac OS. 4, The code will compile but will throw an exception on execution. 3 AY023 Consider the following statements: Statement A: When your class extends a super class, your class inherits all the public methods of the super class. Statement B: When your class extends a super class, your class inherits all the constructors of the super class. Select the correct option for the preceding statements: 1, Both Statement A and Statement B are true. 2, Statement A is true while Statement B is false. 3, Statement A is false while Statement B is true. 4, Both Statement A and Statement B are false.

2 AY024 Consider the following class declaration: class Example { /* class body*/ } Which of the following statements is true regarding the preceding class? 1, The Example class is accessible to all classes 2, The Example class is accessible to the classes within the same package 3, The Example class is not accessible to any classes 4, The Example class is accessible to its subclasses.

2 AY025 Consider the following statements: Statement A: Operator || returns true if one of the operands is true. Statement B: Operator || returns false if both operands are false. Select the correct option for the preceding statements: 1, Both Statement A and Statement B are true. 2, Statement A is true while Statement B is false. 3, Statement A is false while Statement B is true. 4, Both Statement A and Statement B are false

1 AY026 In a Java program, numArray is an array initialized with int values. Which of the following statement/statements, will you use to print the last int value stored in the array? 1, int result=numArray.size; System.out.println(result); 2, int result=numArray.length(); System.out.println(result); 3, System.out.println(numArray[numArray.length]); 4, System.out.println(numArray[numArray.length-1]);

4 AY027 Which of the following is NOT a valid switch statement?

1, switch (num) { case 1: System.out.println("Case 1"); break; case 2: System.out.println("Case 2"); break; case 3: System.out.println("Case 3"); break; default: System.out.println("Default Case"); break; } 2, int num = 3; switch (num) { case 3: System.out.println("Case 3"); case 1: System.out.println("Case 1"); case 2: System.out.println("Case 2"); case 4: System.out.println("Case 4"); } 3, int num = 3; switch (num) { case 3: System.out.println("Case 3"); continue; case 1: System.out.println("Case 1"); continue; case 2: System.out.println("Case 2"); continue; case 4: System.out.println("Case 4"); }

4, switch (2) { default: System.out.println("Default Case"); }

AY028 Consider the following code: class Example { public static void main(String[] args) { int num=5; do { System.out.println("The number is: " + num); } while (num < 10); } } Select the correct option for above mentioned code. 1, The output will display the following: The number is: 5 The number is: 6 The number is: 7 The number is: 8 The number is: 9 The number is: 10 2, The output will display the following infinitely: The number is: 5 3, The output will display the following: The number is: 5 4, There will be no output.

2 AY029 Consider the following statements: Statement A: In a switch statement you can use the return keyword instead of the break keyword. Statement B: In the switch <expression> syntax, the <expression> can evaluate to a String value. Select the correct option for the preceding statements: 1, Both Statement A and Statement B are true. 2, Statement A is true while Statement B is false. 3, Statement A is false while Statement B is true. m 4, Both Statement A and Statement B are false.

AY030 Consider the following program: class Example { public static void main(String[] args) { int b = -11; b = b >> 2; System.out.println(b); } } What will be the output of the above program? 1, 4-11 m 2, 2 m 3, -11 m 4, -3 m

4 AY056 Consider the following program: import java.util.*; class Example { public static void main(String[] args) { ArrayList list=getList(); Iterator iter=list.iterator(); while (iter.hasNext()) { iter.next();

System.out.println(list); } } static ArrayList getList() { ArrayList<String> arrList=new ArrayList<String>(); arrList.add("1"); arrList.add("2"); arrList..add("3"); arrList.add("4"); return arrList; } } What will be the output on executing the preceding code? 1, [1] [2] [3] [4] 2, [1, 2, 3, 4] 3, [1][1][1][1] [2][2][2][2] [3][3][3][3] [4][4][4][4] 4, [1, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4]

AY057 Consider the following code developed prior to the introduction of generics and autoboxing: import java.util.*; public class Example { public static void main(String args[]) { ArrayList list=new ArrayList(); Integer num=new Integer(10); list.add(0,num); Integer numObj=(Integer)list.get(0); int num2=numObj.intValue(); System.out.println(num2); } } Which of the following code will you use to replace the preceding code for optimization using generics and autoboxing. Ensure that the code you use select performs the same function and produces the same result as that of the given code. 1, import java.util.*; public class Example { public static void main(String args[]) { ArrayList<Integer> list=new ArrayList<Integer>(); Integer num=new Integer(10); list.add(num);

int numObj=list.get(num); System.out.println(numObj); } } 2, import java.util.*; public class Example { public static void main(String args[]) { ArrayList<Integer> list=new ArrayList<Integer>(); list.add(10); int numObj=list.get(0); System.out.println(numObj); } } 3, import java.util.*; public class Example { public static void main(String args[]) { ArrayList<Integer> list=new ArrayList<Integer>(); list.add(10); System.out.println(list); } } 4, import java.util.*; public class Example { public static void main(String args[]) { ArrayList<Integer> list=new ArrayList<Integer>(); list.add("10"); String num=(String)list.get(0); System.out.println(num); } }

AY058 Consider the following code: public class Example { public Example() { System.out.println("Inside constructor."); } static { System.out.println("Inside static block."); } public static void main(String args[]) { System.out.println("Inside main method."); } } What will be the output on executing the preceding code? 1, Inside main method.Inside constructor.Inside static block.

2, Inside main method.Inside static block. 3, Inside constructor.Inside static blockInside main method. 4, Inside static block.Inside main method. 4 AY059 You must declare methods of an interface as ______________. 1, static m 2, final m 3, public m 4, private m

3 AY060 Which of the following options is the base class of all checked and unchecked exceptions in Java? m 1, Error m 2, Exception m 3, ArithmeticException m 4, RuntimeException 2 AY061 Which of the following keywords ensures that a method cannot be overridden? m 1, final m 2, protected m 3, static m 4, abstract m 1 AY062 Which of the following exceptions is thrown when you try to divide a number by 0? m 1, NumberFormatException m 2, NullPointerException m 3, SecurityException m 4, ArithmeticException m 4 AY063 Which of the following formatting code formats the arguments as a string? 1, %g m 2, %s m 3, %x m

4, %n AY064

Consider the following statements: Statement A: Variables defined with static keyword are called class variable. Statement B: A static variable is available from any instance of a class. Select the correct option for the preceding statements: 1, Statement A is true while Statement B is false. m 2, Statement A is false whileStatement B is true. 3, Both Statement A and Statement B are false. m 4, Both Statement A and Statement B are true.

AY065 Consider the following statements: Statement A: In a Java class, you can extend a class declared as final. Statement B: In a Java class, you can override public methods declared as final. Select the correct option for the preceding statements: m 1, Both Statement A and Statement B are true. m 2, Statement A is true while Statement B is false. m 3, Statement A is false while Statement B is true. m 4, Both Statement A and Statement B are false. 4

AY066 Consider the following statements: Statement A: There can be multiple catch block after a try block. Statement B: The finally clause defines a block of code that is always executed irrespective of an exception being thrown or not. Select the correct option for the preceding statements: 1, Both Statement A and Statement B are true. m 2, Statement A is true while Statement B is false. 3, Statement A is false while Statement B is true. 4, Both Statement A and Statement B are false.

AY067 Consider the following code: public class Example { public static int num1 = 4; public int num2 = 5; } In the preceding code, which one is a class variable? m 1, The num1 variable. m 2, Both the num1 and num1 variables. 3, The num2 variable. m 4, None of the variables

AY068 You can use the FileReader class to read ___________. 1, Characters m 2, Integers m 3, Streams m 4, Files m 1 AY069 Consider the following code: import java.util.*; public class Example { public static void main(String [] args) { <Class Name> obj= new <Class Name>(); obj.add("Alps"); obj.add("Alps"); System..out.println(obj); } } Which of the following class will you use in the place of <Class Name> to execute the program with the following output: [Alps] 1, HashSet m 2, LinkedList m 3, Arraylist m 4, HashSetMap

1 AY070 Consider the following code: public class Example { public static void main(String [] args) { try { String name = args[1]; System.out.println(name); } catch(Exception ex){} } } Select the correct option on executing the code with the following command: java Example James 1, The code executes with the following output: James 2, The code exits with the following exception message: java.lang.ArithmeticException: 1 at Example.main(Example.java:7) m 3, The code exits without any output. 4, The code exits with the following exception message: java.lang.ArrayIndexOutOfBoundsException: 1 at Example.main(Example.java:7) 3 AY071 Consider the following code: public class Example { final int i; public static void main(String[] args) { System.out.println(new Example().i); } } Select the correct option for the preceding code: 1, The compiler will generate an error m 2, The code will compile and run with the following output:0 a runtime error. 4, The code will compile and run with the following output:null

3, The code will compile but generate

1 AY072 Consider the following code: import java.util.*; public class Example { public static void main(String[] args) { ArrayList<Integer> list = new ArrayList<Integer>(); int num1 = 1; int num2 = 2; list.add(num1); list.add(num2); Iterator elements = list.iterator(); while(elements.hasNext()) { System.out.println(elements.next());

} } } What will be the output of the preceding code? 1, The code will not compile as it tries to add int values to an ArrayList of type Integer. 2, The code will compile and execute with the following output:1 2 3, The code will compile but not execute as it tries to add int values to an ArrayList of type Integer. 4, The code will compile and execute with the following output: num1 num2

2 AY073 Consider the following code: public class Example { public static void main(String [] args) { try { System.out.println("1"); System.out.println(1/0); System.out.println("2"); } catch(ArithmeticException ex) { System.out.println("3"); } catch(Exception ex) { System.out.println("4"); } finally { System.out.println("5"); } } } What will be the output on executing the following code? 1, 135 m 2, 145 m 3, 1245 m 4, 345 m 1 AY074 Consider the following code: public class Example { public static void main(String [] args) { int res = 0; int [] arr= new int[] {1,2,3,4,5}; for(int element : arr)

{ res +=element; } System.out.println(res); } } What will be the output of the following code: 1, 0 m 2, 15 m 3, 5 m 4, 10 m

2 AY075 Consider the following Employee class: public class Employee { public String getName() { return "Henry"; } } Consider the following Example class: public class Example { Employee emp; public static void main(String args[]) { System.out.println(emp.getName()); } } What will be the result on executing the Example class? 1, The class will display the following output:Henry 2, The class will throw an exception opf type NullPointerException. 3, The class will execute without any output. 4, The class will throw an exception of type SecurityException. 2 AY076 __________ are those that a programmer is expected to handle in a program. m 1, Checked Exception m 2, Unchecked exception m 3, Runtime exception 4, Objects of the Error class m

1 AY077

You cannot override a ______________ method. 1, public m 2, abstract m 3, static m 4, protected m 3 AY078 Which of the following exception will be thrown if a program tries to read from a file that does not exist? 1, NullPointerException m 2, SecurityException m 3, FileNotFoundException m 4, NumberFormatException m

3 AY079 A method in a Java class contains code that might result in an exception. Which of the following keyword will you use in the method to indicate that the calling method should handle the exception? 1, throw m 2, throws m 3, try m 4, this m 2 AY080 To make a variable constant , you need to define the variable with the _________ keyword m 1, static m 2, private m 3, public m 4 AY081 Consider the following code: abstract class Example1 { abstract void display(); void displayAll() { System.out.println("Hello"); } } Which of the following code on execution will display the following output? Hello 1, class Example2 extends Example1 4, final

{ public static void main(String [] args) { Example1 e1 = new Example1(); e1.displayAll(); } } 2, class Example2 extends Example1 { public static void main(String [] args) { Example1 e2 = new Example2(); e2.displayAll(); } } 3, class Example2 extends Example1 { void display() { } public static void main(String [] args) { Example2 e2 = new Example2(); e2.displayAll(); } } 4, class Example2 extends Example1 { public static void main(String [] args) { Example2.display(); } }

AY082 Consider the following code class Example { public static void main(String [] args) { String var1 = args[0]; int var2 = Integer.parseInt(var1); System.out.println(var2); } } Select the correct option when you execute the preceding code with the following command: java Example a 1, The code on execution will throw an exception of type NumberFormatException. 2, The code on execution will throw an exception of type ArithmeticException. m 3, The code on execution will display var2.

4, The code on execution will display var1. 1 AY083 Consider the following two classes: public class Example1 { public static int num; static { num=5; } } public class Example2 { public static void main(String[] args) { System.out.println(Example1.num); } } Select the correct option regarding the preceding classes. 1, The Example2 class will execute without any output. m 2, The Example2 class will execute with the following output:5 m 3, The Example2 class will not compile as it does not calls the constructor of the Example 1 class. m 4, The Example2 class will not execute as it does not calls the constructor of the Example 1 class.

2 AY084 Consider the following code: import java.util.*; public class Example{ public static void main(String []args) { try { System.out.println("Hello"); } finally { System.out.println("Hello"); } } } Select the correct option regarding the preceding code. 1, The code will not compile and report that a catch block is missing. m 2, The code will compile but will throw a runtime expression. m 3, The code will execute with the following output:Hello 4, The code will execute with the following output:Hello Hello 4 AY085 Consider the following code: public class Example{

public static void main(String []args) { String str1=args[0]; String str2=args[1]; String str3=args[3]; System.out.println(str1+str2+str3); } What will be the output on executing the preceding code with the following command: java Example 1 2 Java Programming Language }1, 12Java m 2, 12Programming m 3, 12Java Programming Language m 4, The code will throw an exception of type ArrayIndexOutOfBoundsException. m 2 AY086 To display a panel you must add it to __________. 1, Another panel m 2, A Frame m 3, A text component m 4, Any component 2 AY087 The default layout manager of a panel is_________. 1, FlowLayout m 2, BorderLayout m 3, GridLayout m 4, NullLayout m 1 AY088 Every AWT component has a ____________method that draws the specified component on a container. m 1, setVisible() m 2, setSize() m 3, paint() m 4, draw() m 3 AY089 Which of the following method does the MouseMotionListener interface contains? 1, mouseDragged(MouseEvent) m 2, mouseExited(MouseEvent) m 3, mouseEntered(MouseEvent) m 4, mouseClicked(MouseEvent) m

1 AY090 Which of the following event is generated when you click a button in a GUI form? 1, MouseEvent m 2, KeyEvent m 3, ItemEvent m 4, ActionEvent m

4 AY091 Consider the following statements: Statement A : When you resize a window containing buttons assigned with BorderLayout, the relative positions of the button changes. Statement B: When you add a component to an empty window assigned with BorderLayout, the window adds the component to the center region by default. Select the correct option for the preceding statements. 1, Statement A is false while Statement B is true. m 2, Statement A is true while statement B is false m 3, Both Statement A and Statement B are true. 4, Both Statement A and Statement B are false. m

1 AY092 Which of the following method will you call to set the size of a Frame? 1, pack() m 2, setVisible() m 3, setSize() m 4, setLayout()

3 AY093 Consider the following statements: Statement A : The code to add a button object to the center region of a frame using border layout is: frame.add(button, "Center"); Statement B: The code to add a button object to the center region of a frame using border layout is: frame.add(button, BordeLayout.CENTER) Select the correct option for the preceding statements. 1, Statement A is true while Statement B is false. m 2, Statement A is false while Statement B is true. 3, Both Statement A and B are true. 4, Both Statement A and B are false.

3 AY094 Which of the following method enables you to disable the layout manager for a container? 1, container.setLayout(0); m 2, container.layout(null); m 3, container.layout(0); m 4, container.setLayout(null);

1 AY095 Which of the following layout manager enables you to assign row and column numbers to arrange components? m 1, BorderLayout m 2, FlowLayout m 3, GridLayout m 4, NullLayout m

3 AY096 What will be the output of the following statement in a GUI program? Frame f = new Frame ("Hello"); 1, The statement will create a new Frame window and display Hello at the center. m 2, The statement will create a new Frame window with a title bar containing the Hello title. m 3, The statement will create a new Frame window with a status bar containing the Hello status. m 4, The statement will create a new Frame window and display Hello at the left. m 2 AY097 Consider the following code: Frame f = new Frame("Frame"); MenuBar mb = new MenuBar(); Which of the following code will you use to add the menu bar to the frame? 1, f.addMenubar(mb); m

2, f.setManubar(mb); m 3, f.add(mb); m 4, f.set(mb); 2

AY098 Consider the following code, where MyListener is a listener class of action events: Frame f = new Frame("Frame"); MenuBar m1 = new MenuBar(); Menu menu1 = new Menu("File"); menu1.addActionListener(new MyListener); m1.add(menu1); f.setMenuBar(m1); Select the correct option regarding the preceding code. 1, The code will add an action listener to both the menu bar and the File menu. m 2, The code will add an action listener to the File menu. m 3, The code will add an action listener to the frame. m 4, The code will add an action listener to the menu bar. 2 AY099 What will be the output of the following code? import java.awt.*; public class Example { private Frame f; private Button b1, b2, b3, b4, b5, b6; public Example() { f=new Frame("GridLayout Demo"); b1=new Button("1"); b2=new Button("2"); b3=new Button("3"); b4=new Button("4"); b5=new Button("5"); b6=new Button("6"); } public void display() { f.setLayout(new GridLayout()); f.add(b1); f.add(b2); f.add(b3); f.add(b4); f.add(b5); f.add(b6); f.pack(); f.setVisible(true); } public static void main(String[] args) { Example examp=new Example(); examp.display(); } } 1, The output will display a window with six buttons arranged in three rows and two columns. m 2, The output will display a window with six buttons arranged in two rows and three columns. m

3, The output will display a window with six buttons arranged in one column. m 4, The output will display a window with six buttons arranged in one row. m 4 AY100 Consider that you are creating a GUI application and you need an action listener to handle events of type ActionEvent. Which of the following listener code will you use? m 1, import java.awt.event.*; public class CustomHandler implements ActionListener{ public void actionPerformed(ActionEvent evt) { /*Process action here*/ } } 2, import java.awt.event.*; public class CustomHandler{ public void actionPerformed(ActionEvent evt) { /*Process action here*/ } } 3, import java.awt.event.*; public class CustomHandler implements ActionListener{ public void actionPerformed() { /*Process action here*/ } } 4, import java.awt.event.*; public class CustomHandler implements ActionListener{ public static void main(String args[]) { /*Process action here*/ } }

1 AY101 Consider the following code: public class Example extends Thread { public void run() { System.out.println ("Hello"); } public static void main (String args[]) { new Example(); } } Select the correct option regarding the preceding code: 1, The code will not compile. 2, The code will compile but will not execute. 3, The code will compile, execute, and display Hello as the output. m

4, The code will compile, execute, but will not display anything.

4 AY102 Which of the following is NOT a valid state of a thread? 1, Running m 2, Blocked m 3, Listening m 4, Dead m 3 AY103 Consider the following statements on threads: Statement A: You can create a new thread by extending the Thread class. Statement B: You can create a new thread by implementing the Runnable interface. Select the correct option for the preceding statements 1, Both Statement A and Statement B are false. m 2, Statement A is true while Statement B is false. m 3, Statement A is false while Statement B is true. m 4, Both Statement A and Statement B are true. m

4 AY104 Select the correct statement that sets the priority of a thread among a group of threads to maximum. m 1, threadObj.getPriority(THREAD.MAX_PRIORITY); m 2, threadObj.setPriority(MAX_PRIORITY); m 3, threadObj.setPriority(THREAD.PRIORITY); m 4, threadObj.setPriority(THREAD.MAX_PRIORITY);

4 AY105 Consider the following code: public class Example extends Thread { public static void main(String args[])

{ for(int i=0;i<3;i++) new Example().start(); } public void run() { System.out.println("Hello"); } } Select the correct option for the preceding code. 1, The code will execute with the following output:Hello m 2, The code will execute without any output. m 3, The code will execute with the following output: Hello Hello Hello 4, The code will not execute. m

3 AY106 In a Java multithreading program, under what circumstances will you call the yield() method of a thread? 1, To give other runnable threads a chance to execute. m 2, To start a new thread. m 3, To terminate the current thread. m 4, To stop the current thread for a specific time. m

1 AY107 Consider the following code: public class Example extends Thread { public static void main(String argv[]) { Example obj = new Example(); obj.run(); } public void start() { for (int i = 0; i <5; i++) { System.out.println("Hello"); } } } What will be the output of the preceding code? 1, The code will display the following outputHello m

2, The code will display the following output:Hello Hello Hello Hello Hello 3, The code will not display any output. m 4, The code will display the following output: Hello Hello Hello Hello

3 AY108 Which of the following classes will you use to communicate between threads? m 1, FileInputStream and FileOutputStream m 2, PipedInputStream and PipedOutputStream m 3, BufferedInputStream and BufferedOutputStream m 4, FilterInputStream and FilterOutputStream m

2 AY109 Which of the following is the immediate superclass of the DataOutputStream, BufferedOutputStream, and PrintStream classes? m 1, FileOutputStream m 2, FilterOutputStream m 3, PipedOutputStream m 4, ByteArrayOutputStream

AY110 Consider the following statements: Statement A: To implement a TCP/IP server, you can use the ServerSocket class of the java.net package. Statement B: a TCP/IP client uses the Socket class of the java.net package. Select the correct option regarding the preceding statements. 1, Both Statement A and Statement B are true. m 2, Statement A is true while Statement B is false. m 3, Statement A is false while Statement B is true. m 4, Both Statement A and Statement B are false. m

1 AY111 Which of the following method enables you to force writes that an output stream accumulates? m 1, close() m 2, write() m 3, flush() m 4, read() 3

AY112 Which of the following will you use to read a stream of bytes in a program? 1, Reader m 2, Writer m 3, InputStream m 4, OutputStream 3 AY113 Which of the following class will you use to read the content of a file as a stream of bytes? 1, FileReader m 2, StringReader m 3, FileInputStream m 4, PipedReader 3

AY114 A___________ stream performs conversion on another stream. 1, Filter m 2, Output m 3, Input m 4, Print m 1 AY115 Which of the following method will you call to start a thread? 1, notify() m 2, yield() m 3, run() m 4, start() m 4 AY116 Which one of the following is a valid TCP/IP port number 1, -8080 m 2, 65535 m 3, 100000 m 4, -7070 m 2 AY117 Consider the following statement: Thread.sleep(x); Select the correct option for the value x. 1, An int value that specifies the number of seconds for which the thread must be made inactive. 2, A long value that specifies the number of milliseconds for which the thread must be made inactive. m 3, A float value that specifies the number of seconds for which the thread must be made inactive. m 4, A float value that specifies the number of milliseconds for which the thread must be made inactive.

2 AY118 Consider the following statements: Statement A: To start a thread you must call the constructor of the Thread class. Statement B: The Thread class implements the Runnable interface. Select the correct options for the preceding statements. 1, Statement A is true while Statement B is false. m 2, Both Statement A and Statement B are true. m

3, Statement A is false while Statement B is true. m 4, Both Statement A and Statement B are false. m

3 AY119 Consider the following statements: Statement A: TCP/IP port numbers are 16 bit numbers. Statement B: TCP/IP classes are implemented using the java.io package. Select the correct options for the preceding statements. 1, Both Statement A and Statement B are true. m 2, Statement A is true while Statement B is false. m 3, Statement A is false while Statement B is true. m 4, Both Statement A and Statement B false.

2 AY120 A TCP/IP server is running on a computer with the IP address 127.168.0.10 and listening to the 5430 port number. Which of the following statement will you use in the TCP/IP client code to establish a connection with the server? 1, ServerSocket s1 = new ServerSocket("127.168.0.10", 5430); m 2, Socket s1 = new Socket("127.168.0.10", 5430); m 3, Socket s1 = new ServerSocket("127.168.0.10", 5430); 4, Socket s1 = new Socket(127.168.0.10, 5430); m

2 AY121 Consider the following code: import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Example { public static void main(String[] args) throws IOException { FileInputStream in = null; FileOutputStream out = null; try { in = new FileInputStream("OutputFile.txt"); out = new FileOutputStream("InputFile.txt"); int c; while ((c = in.read()) != -1) { out.write(c); } } finally { if (in != null) { in.close(); }

if (out != null) { out.close(); } } } } What will be the output of the above code? 1, The code will throw a runtime exception. m 2, The code will copy the content of the OutputFile.txt file to the InputFile.txt file. m 3, The code will copy the content of the InputText.txt file in to OuputText.txt file. 4, The code will execute without any output. m

2 AY122 Consider the following code: import java.io.*; class Example { public static void main(String args[]) { DataInputStream fi = new DataInputStream(System.in); try { fi.readChar(); } catch(IOException e) { System.exit(0); } finally { System.out.println("Doing finally"); } } } Select the correct option for the preceding code. m 1, The code will not compile. m 2, The code will compile, execute, wait for a key press, and then exit. m 3, The code will compile, execute, wait for a key press, prints "Doing finally" on a key press, and then exit.4, The code will execute and exit immediately without output. 3 AY123 Consider the following code: public class Example { public static void main(String args[]) throws InterruptedException { String info[] = { "Java", "C++" }; for (int i = 0; i < info.length; i++) { Thread.sleep(4000); System.out.println(info[i]); } } }

Select the correct option. 1, The code will throw an exception of type InterruptedException. m 2, The code will display Java and C++. 3, The code will display only Java. m 4, The code will display only C++.

2 AY124 Consider an example.txt file saved in your working directory that contains the following content: User Name = Admin Password = Administrator Host = localhost Which of the following code will you use to read the content of the example.txt file and display it on console? 1, import java.io.*; public class Example { public static void main(String[] args) { try { FileReader fr = new FileReader("example.txt"); BufferedReader br = new BufferedWriter(fr); System.out.println(br.display()); } catch (IOException e) { System.out.println(e.getMessage()); } } } 2, import java.io.*; public class Example { public static void main(String[] args) { String str; try { FileReader fr = new FileReader("example.txt"); BufferedReader br = new BufferedReader(fr); while ((str = br.readLine()) !=null) System.out.println(str); } catch (IOException e) { System.out.println(e.getMessage()); } } } 3, import java.io.*; public class Example { public static void main(String[] args) { String str; try

{ FileReader fr = new FileReader(example.txt); BufferedReader br = new BufferedReader(fr); while ((str = br.readLine()) !=null) System.out.println(str); } catch (IOException e) { System.out.println(e.getMessage()); } } } 4, import java.io.*; public class Example { public static void main(String[] args) { try { FileReader fr = new FileReader("example.txt"); BufferedReader br = new BufferedReader(fr); while (br.readLine()!=null) System.out.println(br.readLine()); } catch (IOException e) { System.out.println(e.getMessage()); } }

AY125 A Java multithreading program contains an operation() method. You need to ensure that only a single thread can access the operation() method at a time. Which of the following code will you use? 1, synchronized(this) public void operation(){ /*Method Body*/ } 2, public void operation(){ synchronized(this) /*Method Body*/ } 3, public void synchronized operation(){ /*Method Body*/ } 4, public synchronized void operation(){ /*Method Body*/ } 4

S-ar putea să vă placă și