Java

49
1.Which of the following process converts Java programming language code to a set of bytecodes? m 1, Bytecode verification m 2, Compilation m 3, Class loading m 4, Execution m SOLUTION ----2 Which of the following values is a type of the boolean data type? m 1, 'true' m 2, "true" m 3, true m 4, boolean m SOLUTION---3 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, import foo.bar.App; m 3, import foo.bar.*; m 4, import foo.*; m SOLUTION---2 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 t 1, Stetement 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 SOLUTION-----3

description

8

Transcript of Java

1.Which of the following process converts Java programming language code to a set of bytecodes? m1, Bytecode verification m2, Compilation m3, Class loading m4, Execution mSOLUTION ----2Which of the following values is a type of the boolean data type? m

1, 'true' m2, "true" m3, true m4, boolean mSOLUTION---3

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? m1, import App; m2, import foo.bar.App; m3, import foo.bar.*; m4, import foo.*; mSOLUTION---2

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 t1, Stetement A is true while Statement B is false. m2, Both Statement A and Statement B are true. m3, Statement A is false while Statement B is true. m4, Both Statement A and Statement B are false. mSOLUTION-----3

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: m1, Both Statement A and Statement B are true. m2, Both Statement A and Statement B are false. m3, Statement A is true while Statement B is false. m4, Statement A is false while Statement B is true. m

SOLUTION---3

Select the correct integer length for the int data type. m1, 8 bits m2, 16 bits m3, 32 bits m4, 64 bits mSOLUTION----3

Which of the following is a valid Java identifier? M1, $const m2, const m3, long m4, new mSOLUTION---1

The _____________ option of the compiler enables you to compile class files to a different directory than that of the source files. m1, -cp m2, -source m3, -g m4, -d mSOLUTION------4

Select the correct option that shows the command to execute the MyApp Java class. m1, java class=MyApp m2, javac MyApp.java m3, java MyApp.java m4, java MyApp mSOLUTION---4

To compile and execute Java programs, you need to set the PATH environment variable to ___________________. m1, The working directory that contains the source files of the program. m2, The java_root/lib directory, where java_root is the installation directory of the Java technology software. m3, The java_root/bin directory, where java_root is the installation directory of the Java technology software. m4, The installation directory of the Java technology software. mSOLUTION---3

________ is the default value of the double datatype: m1, 1 m2, 0.0D m3, 1.0D mSOLUTION---2

The _________ variables of a class are created when the class is loaded and continues to exist as long as the class is loaded. m1, static m2, member m3, local m4, instance mSOLUTION--1

All Java classes directly or indirectly extends the _______ class. m1, Main m2, Class m3, String m4, Object mSOLUTION---4In 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? m1, super(); m2, Employee(); m3, Manager.super(); m4, Employee.super(); mSOLUTION---1

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 th1, The code will execute and display South as the output. m2, The code will throw a runtime exception. m3, The code will execute and display North as the output. m4, The code will execute but will not display any output. mSOLUTION---- 2

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 c1, 0 m2, 4 m3, 5 m4, 6 mSOLUTION--- 2

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? m1, The code will execute with the output Hello world Hello world m2, The code will execute with the output Hello world m3, The code will not compile m4, The code will compel but will not execute. mSOLUTION------ 3

Which of the following options will you use to determine the number of elements that an array contains? m1, size m2, length() m3, length m4, size() mSOLUTION------ 3

Which of the following options is a short-circuit logical operator? m1, &&&& m2, && m3, | m4, ! m

SOLUTION---2Consider 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 exe1, The code will execute and display null. m2, The code will execute and display 0. m3, The code will execute and display 1. m4, The code will throw an exception as the num variable is not initialized. mSOLUTION---- 2

Which of the following code will compile, execute, and display the word Hello? m1, public class Example { public static void main(String args[]) { int num1; int num2; if(num1==num2) {

System.out.prin2, public class Example { public static void main(String args[]) { String str1=new String("Hello"); String str2=new String("Hello");

if(str1==str2) 3, public class Example { public static void main(String args[]) { String str1="Hello";

String str2="Hello";

if(str1==str2) {

4, public class Example { public static void main(String args[]) { String str1="hello"; String str2="Hello";

if(str1.equals(str2)) {

SOLUTION---- 3

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); } 1, The code will execute but will not display any output. m2, The code will not compile. m3, The code will execute and display Linux, Unix, Windows, and Mac OS. m4, The code will compile but will throw an exception on execution. mSOLUTION—3

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 1, Both Statement A and Statement B are true. m2, Statement A is true while Statement B is false. m3, Statement A is false while Statement B is true. m

4, Both Statement A and Statement B are false. mSOLUTION---- 2

Consider the following class declaration:

class Example { /* class body*/}

Which of the following statements is true regarding the preceding class? m1, The Example class is accessible to all classes m2, The Example class is accessible to the classes within the same package m3, The Example class is not accessible to any classes m4, The Example class is accessible to its subclasses. mSOLUTION---- 2

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: m1, Both Statement A and Statement B are true. m2, Statement A is true while Statement B is false. m3, Statement A is false while Statement B is true. m4, Both Statement A and Statement B are false mSOLUTION--- 1

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? m1, int result=numArray.size;System.out.println(result); m2, int result=numArray.length();System.out.println(result); m3, System.out.println(numArray[numArray.length]); m4, System.out.println(numArray[numArray.length-1]); mSOLUTION---- 4

Which of the following is NOT a valid switch statement? m1, 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; 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"); 3, int num = 3; switch (num) { case 3: System.out.println("Case 3"); continue; case 1: System.out.println("Case 1"); continue; 4, switch (2) { default: System.out.println("Default Case"); } mSOLUTION---- 3

Consider the following code:

class Example { public static void main(String[] args) { int num=5; do { System.out.println("The number is: " + num); } wh1, The output will display the following:

The number is: 5The number is: 6The number is: 7The number is: 8The number is: 9

The number is: 10 m2, The output will display the following infinitely:

The number is: 5 m3, The output will display the following:

The number is: 5 m4, There will be no output. mSOLUTION---- 2

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 correc1, Both Statement A and Statement B are true. m2, Statement A is true while Statement B is false. m3, Statement A is false while Statement B is true. m4, Both Statement A and Statement B are false. mSOLUTION--- 2

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 output1, 4-11 m2, 2 m3, -11 m4, -3 mSOLUTION---- 4

____________________________________________________________________________________

Techunique Solutions is designing a website for a Goodways travels. One of the requirements given to the design team is that the website should handle the requirements of the employees of Techunique, travel agents and direct customers separately. Apart

1, Splash home page m2, Menu home page m3, Path-based home page m4, News-oriented home page mSOLUTION----- 3

Joycee have developed a website that allows the user to view news of current affairs, entertainment, sports, and weather. Joycee kept the text style and text size consistent throughout the website. The website will be accessed from mobile phones. While1, Using white as background color will make the links identifiable. m2, Using black for background color and blue for visited links will make the links identifiable. m3, Removing blue as text color and purple as the color for visited links will make the links identifiable. m4, Removing light green as background color will make the links identifiable. mSOLUTION----- 3

Newways software is designing an e-learning website for young students in the age group of 10 to 12 years. Apart from providing free learning opportunity, the website will give information related to the new tutorials being launched by the website. As the1, Menu home page m2, News-oriented home page m3, Path-based home page m4, Splash screen home page mSOLUTION------ 4

John is designing a website for AT Services. The company management wants the home page to display the links of all the 20 partner companies in the home page. In addition, the management does not want John to create an attractive home page because it will1, News-oriented Home page m2, Menu Home page m3, Path-based Home page m4, Splash screen Home page mSOLUTION------ 2

Real software is developing a speech-based user interface for blind people. However, speech based interface are difficult to design and time given by the client is short. To develop a functional interface without any errors, the company wants to first ev1, The design team of Real software should have used the Sketching technique because storyboard technique would only provide the flow and features of the interface. m2, The design team of Real software should have used the Horizontal Prototyping because storyboard technique would only provide the flow of the interface. m3, The design team of Real software should have used the Wizard of Oz technique because storyboard technique would only provide the flow and features of the interface. m4, The design team of Real software should have used the Vertical Prototyping because storyboard technique would only provide the flow of the interface. mSOLUTION----- 3

Drivetech is in the process of developing a speech-based navigation system for the cars. To check the functionality of the product, the company uses the manipulating and navigating type of conceptual model. However, using this model the various features o1, Conversing should be used to clearly show the interaction of the product with the system m2, Tangible User Interface should be used to clearly show the interaction of the product with the system m3, Direct Manipulation should be used to clearly show the functionality of the product m4, Ubiquitous Computing should be used to show the various ways of interacting with the product mSOLUTION—1

New Generation softwares is creating an application for the library management process. To demonstrate the various features and functionality of the application, the company used horizontal prototyping. However, this technique did not give detailed descri1, Scenario prototyping m2, Vertical prototyping m3, Sketching m4, Wizard of Oz mSOLUTION------- 1

Red Sky IT Systems is designing a website for a news channel. To verify the requirements, Red Sky IT Systems has to develop a prototype. The prototype must show the navigation and flow of each news category, such as breaking news, sports,

and weather. F1, Scenario prototyping because it covers both the features and the associated functionalities of the application. m2, Vertical prototyping because it covers a set of features with in-depth functionality. m3, Horizontal Prototyping because it covers all the features of the application without their underlying functionality. m4, Vertical Prototyping because it covers all the features of the application without their underlying functionality. mSOLUTION----- 1

WebBizz got an offer to design a website for an entertainment channel Znn. To verify the requirements, WebBizz has to develop a prototype but they are running out of time. Due to less manpower they could not start developing the prototype on time. Now, qu1,Storyboarding because it describes each action of the application sequentially. m2, Wizard of Oz because it is used to test an application without the existence of the application. m3, Sketching because it explore the design of the entire application through visual brainstorming. m4, Horizontal prototyping because it covers all the features of the proposed application. mSOLUTION--- 3

Which type of data gathering technique can be used to collect quantitive data? m1, Questionnaires m2, Naturalistic observation m3, Focus group m4, Interviews mSOLUTION --- 1

Which type of requirement captures the system goals with respect to effectiveness and safety of a product? m1, Usablity requirements m2, Data requirements m3, Functional requirements m4, Non-functional requirements mSOLUTION -- 1

Which of the following methods is used to collect and interpret data from end users to design an application? m1, Coherence m2, Contextual design m3, Participatory design m4, Ethnography mSOLUTION-- 2

Which of the following requirements define the constraints on the system and the conditions under which the system must be developed? m1, Non-functional requirements m2, Functional requirements m3, Data requirements m4, User requirements mSOLUTION----- 1

Which type of environmental requirements addresses questions related to the hierarchy of the organization? m1, Physical environment m2, Organizational environment m3, Social environment m4, Technical environment mSOLUTION-- 2

Which of the following should be used for easy navigation when the Web page is long? m1, Links m2, Signature graphics m3, Header and footer m4, Jump to top buttons mSOLUTION--- 4

Which guideline of graphics design is considered when graphics are used for communicating better than text. m1, Resemblance m2, Simplicity m3, Relevance m4, Size mSOLUTION-- 3

One of the guidelines for creating Web pages states that if a graphic theme is used it should be repeated in all the Web pages throughout the website. This guideline is related to __________. m1,Web page layout m2, Web page dimension m3, Visual hierarchy m4, Web page content mSOLUTION-- 1

Which of the following is the best practice for delivering the web content to mobile phones? m1, The website should be simple and shallow. m

2, Use cookies because most of the mobile phones do support them. m3, Cascading Style Sheets (CSS) and frames should be used for Web pages developed for mobile phones. m4, The use of drop-down lists should be used for navigation. mSOLUTION--- 1

Which home page design strategy should be followed while designing a home page for a large website? m1, News-oriented Home page m2, Menu Home page m3, Path-based Home page m4, Splash screen Home page mSOLUTION---- 3

Ann is designing a website and he added a Web page on frequently asked questions (FAQs). This Web page displays a set of questions and answers related to the website, which will help the users to browse and identify the features of the website. Identify1, Effectiveness m2, Efficiency m3, Learnability m4, Utility mSOLUTION---- 3

Joe is designing a website for Johnson garments. One of the design considerations that Joe considered while designing is that the search facility should display the results with less than 60 seconds. Identify by considering which usability goal, Joe impl1, Effectiveness m2, Efficiency m3, Memorability m4, Utility mSOLUTION---- 2

Christine is designing a computer-based tutorial for kids. To attract the kids, she designed a visual impressive interface. Identify by considering which user experience goal Christine designed the computer-based tutorial. m1, Supports Creativity m2, Aesthetically Pleasing m3, Helpful m4, Enjoyable mSOLUTION--- 2

Sally is designing a reporting tool. She added a preview feature in the tool, which allows the users to view all the formatting options, while formatting the report. Identify by considering which principles of interaction design Sally incorporated this o1,Visibility m2, Feedback m

3, Constraints m4, Mapping mSOLUTION--- 1

Rebecca is designing an application to maintain student records. While designing the fees record form, she incorporates a feature that the user will not be allowed to enter more than four digits for the student id field. Identify the interaction design pr1, Visibility m2, Feedback m3, Constraints m4, Mapping mSOLUTION--- 2

IT Tech Solutions has designed a online game for teenagers. After a month of launch of the game, users started complaining that when they start the download process, they are unable to make out how long it will take to download the application. It takes 1, A progress bar should be used to inform the user about the download time. m2, Download time should be specified in the help file of the application. m3, An hourglass should be used to inform the user about the download time. m4, A message box with the message "Download complete!!" after the application has been downloaded. mSOLUTION-- 1

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()) { it1, [1][2][3][4] m2, [1, 2, 3, 4] m3, [1][1][1][1][2][2][2][2][3][3][3][3][4][4][4][4] m

4, [1, 2, 3, 4][1, 2, 3, 4][1, 2, 3, 4][1, 2, 3, 4] mSOLUTION-----4

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); l1, 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);

}} m3, 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);

}} m4, 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);

}} mSOLUTION---- 2

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[]) { S1, Inside main method.Inside constructor.Inside static block. m2, Inside main method.Inside static block. m

3, Inside constructor.Inside static block.Inside main method. m4, Inside static block.Inside main method. mSOLUTION---- 4

You must declare methods of an interface as ______________.

m1, static m2, final m3, public m4, private mSOLUTION -- 3

Which of the following options is the base class of all checked and unchecked exceptions in Java? m1, Error m2, Exception m3, ArithmeticException m4, RuntimeException mSOLUTION--- 2

Which of the following keywords ensures that a method cannot be overridden? m1, final m2, protected m3, static m4, abstract mSOLUTION--1

Which of the following exceptions is thrown when you try to divide a number by 0? m1, NumberFormatException m2, NullPointerException m3, SecurityException m4, ArithmeticException mSOLUTION------4

Which of the following formatting code formats the arguments as a string?

m1, %g m

2, %s m3, %x m4, %n mSOLUTION--2

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: m1, Statement A is true while Statement B is false. m2, Statement A is false while Statement B is true. m3, Both Statement A and Statement B are false. m4, Both Statement A and Statement B are true. mSOLUTION---4

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: m1, Both Statement A and Statement B are true. m2, Statement A is true while Statement B is false. m3, Statement A is false while Statement B is true. m4, Both Statement A and Statement B are false. mSOLUTION--4

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 corre1, Both Statement A and Statement B are true. m2, Statement A is true while Statement B is false. m3, Statement A is false while Statement B is true. m4, Both Statement A and Statement B are false. mSOLUTION--1

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? m1, The num1 variable. m2, Both the num1 and num1 variables. m3, The num2 variable. m4, None of the variables mSOLUTION--1

You can use the FileReader class to read ___________.

m1, Characters m2, Integers m3, Streams m4, Files mSOLUTION--1

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.add1, HashSet m2, LinkedList m3, Arraylist m4, HashSetMap mSOLUTION—1

Consider the following code:

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

String name = args[1]; System.out.println(name); } 1, The code executes with the following output:

James m2, The code exits with the following exception message:

java.lang.ArithmeticException: 1 at Example.main(Example.java:7) m3, The code exits without any output. m4, The code exits with the following exception message:

java.lang.ArrayIndexOutOfBoundsException: 1 at Example.main(Example.java:7) mSOLUTION--3

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 preced1, The compiler will generate an error m2, The code will compile and run with the following output:

0 m3, The code will compile but generate a runtime error. m4, The code will compile and run with the following output:

null mSOLUTION--1

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; 1, The code will not compile as it tries to add int values to an ArrayList of type Integer. m2, The code will compile and execute with the following output:

12 m3, The code will compile but not execute as it tries to add int values to an ArrayList of type Integer. m4, The code will compile and execute with the following output:

num1num2 mSOLUTION--2

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 e){ System.out.println("3");}Catch(ArithmeticException e){ System.out.println("3");}Finally {System.out.println("5");}}}

1, 1 3 5 m

2, 1 4 5 m3, 1 2 4 5 m4, 3 4 5 mSILUTION--1

Consider the following Employee class:

public class Employee

{ public String getName() { return "Henry"; } }

Consider the following Example class:

public class Example {Employee emp; public sta1, The class will display the following output:

Henry m2, The class will throw an exception opf type NullPointerException. m3, The class will execute without any output. m4, The class will throw an exception of type SecurityException. mSOLUTION--2

__________ are those that a programmer is expected to handle in a program. m1, Checked Exception m2, Unchecked exception m3, Runtime exception m4, Objects of the Error class mSOLUTION--1

You cannot override a ______________ method.

m1, public m2, abstract m3, static m4, protected mSOLUTION--3

Which of the following exception will be thrown if a program tries to read from a file that does not exist?

m1, NullPointerException m2, SecurityException m3, FileNotFoundException m4, NumberFormatException mSOLUTION--3

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?

m1, throw m2, throws m3, try m4, this mSOLUTION-2

To make a variable constant , you need to define the variable with the _________ keyword m1, static m2, private m3, public m4, final mSOLUTION--4

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 m1, class Example2 extends Example1{ public static void main(String [] args){ Example1 e1 = new Example1(); e1.displayAll(); }} m2, class Example2 extends Example1{ public static void main(String [] args){ Example1 e2 = new Example2(); e2.displayAll(); }} m3, class Example2 extends Example1{ void display(){} public static void main(String [] args) { Example2 e2 = new Example2(); e2.displayAll(); }} m4, class Example2 extends Example1{ public static void main(String [] args) { Example2.display(); }

} mSOLUTION--3

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 op1, The code on execution will throw an exception of type NumberFormatException. m2, The code on execution will throw an exception of type ArithmeticException. m3, The code on execution will display var2. m4, The code on execution will display var1. mSOLUTION—1

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 cor1, The Example2 class will execute without any output. m

2, The Example2 class will execute with the following output:

5 m3, The Example2 class will not compile as it does not calls the constructor of the Example 1 class. m3, The Example2 class will not compile as it does not calls the constructor of the Example 1 class. m4, The Example2 class will not execute as it does not calls the constructor of the Example 1 class. mSOLUTION-2

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");1, The code will not compile and report that a catch block is missing. m2, The code will compile but will throw a runtime expression. m3, The code will execute with the following output:

Hello m4, The code will execute with the following output:

HelloHello mSOLUTION---4

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 the1, 12Java m2, 12Programming m3, 12Java Programming Language m4, The code will throw an exception of type ArrayIndexOutOfBoundsException. mSOLUTION--2

To display a panel you must add it to __________.

m1, Another panel m2, A Frame m3, A text component m4, Any component mSOLUTION--2

The default layout manager of a panel is_________.

m1, FlowLayout m2, BorderLayout m3, GridLayout m4, NullLayout mSOLUTION--1

Every AWT component has a ____________method that draws the specified component on a container. m1, setVisible() m2, setSize() m3, paint() m4, draw() mSOLUTION--3

Which of the following method does the MouseMotionListener interface contains?

m1, mouseDragged(MouseEvent) m2, mouseExited(MouseEvent) m3, mouseEntered(MouseEvent) m4, mouseClicked(MouseEvent) mSOLUTION--1

Which of the following event is generated when you click a button in a GUI form?

m1, MouseEvent m2, KeyEvent m3, ItemEvent m4, ActionEvent mSOLUTION--4

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 BorderLayou1, Statement A is false while Statement B is true. m2, Statement A is true while statement B is false m3, Both Statement A and Statement B are true. m4, Both Statement A and Statement B are false. mSOLUTION--1

Which of the following method will you call to set the size of a Frame?

m1, pack() m2, setVisible() m3, setSize() m4, setLayout() mSOLUTION---3

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 u1, Statement A is true while Statement B is false. m2, Statement A is false while Statement B is true. m3, Both Statement A and B are true. m4, Both Statement A and B are false. mSOLUTION---3

Which of the following method enables you to disable the layout manager for a container?

m1, container.setLayout(0); m2, container.layout(null); m3, container.layout(0); m4, container.setLayout(null); mSOLUTION---1

Which of the following layout manager enables you to assign row and column numbers to arrange components? m1, BorderLayout m2, FlowLayout m3, GridLayout m4, NullLayout mSOLUTION-3

What will be the output of the following statement in a GUI program?

Frame f = new Frame ("Hello"); m1, The statement will create a new Frame window and display Hello at the center. m2, The statement will create a new Frame window with a title bar containing the Hello title. m3, The statement will create a new Frame window with a status bar containing the Hello status. m4, The statement will create a new Frame window and display Hello at the left. mSOLUTION--2

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?

m1, f.addMenubar(mb); m2, f.setManubar(mb); m3, f.add(mb); m4, f.set(mb); mSOLUTION--2

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);1, The code will add an action listener to both the menu bar and the File menu. m2, The code will add an action listener to the File menu. m3, The code will add an action listener to the frame. m4, The code will add an action listener to the menu bar. mSOLUTION--2

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");1, The output will display a window with six buttons arranged in three rows and two columns. m2, The output will display a window with six buttons arranged in two rows and three columns. m3, The output will display a window with six buttons arranged in one column. m4, The output will display a window with six buttons arranged in one row. mSOLUTION----4

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? m1, import java.awt.event.*;

public class CustomHandler implements ActionListener{ public void actionPerformed(ActionEvent evt) { /*Process action here*/ }} m2, import java.awt.event.*;

public class CustomHandler{ public void actionPerformed(ActionEvent evt) {

/*Process action here*/ }} m3, import java.awt.event.*;

public class CustomHandler implements ActionListener{ public void actionPerformed() { /*Process action here*/ }} m4, import java.awt.event.*;

public class CustomHandler implements ActionListener{ public static void main(String args[]) { /*Process action here*/ }} mSOLUTION--1

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 regard1, The code will not compile. m2, The code will compile but will not execute. m3, The code will compile, execute, and display Hello as the output. m4, The code will compile, execute, but will not display anything. mSolution--4

Which of the following is NOT a valid state of a thread? m

1, Running m2, Blocked m3, Listening m4, Dead m solution---------------------3Consider 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 state1, Both Statement A and Statement B are false. m2, Statement A is true while Statement B is false. m3, Statement A is false while Statement B is true. m4, Both Statement A and Statement B are true. mSolution--4

Select the correct statement that sets the priority of a thread among a group of threads to maximum. m1, threadObj.getPriority(THREAD.MAX_PRIORITY); m2, threadObj.setPriority(MAX_PRIORITY); m3, threadObj.setPriority(THREAD.PRIORITY); m4, threadObj.setPriority(THREAD.MAX_PRIORITY); mSolution--4

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 th1, The code will execute with the following output:

Hello m2, The code will execute without any output. m

3, The code will execute with the following output:

HelloHelloHello m4, The code will not execute. mSolution--3

In a Java multithreading program, under what circumstances will you call the yield() method of a thread?

m1, To give other runnable threads a chance to execute. m2, To start a new thread. m3, To terminate the current thread. m4, To stop the current thread for a specific time. M

Solution----1

Consider the following code:

public class Example extends Thread { public static void main(String argv[]) { Example obj = new Example(); 1, The code will display the following output:

Hello m2, The code will display the following output:

HelloHelloHelloHelloHello m3, The code will not display any output. m4, The code will display the following output:

HelloHelloHelloHello mSolution--- 3

Which of the following classes will you use to communicate between threads? m1, FileInputStream and FileOutputStream m2, PipedInputStream and PipedOutputStream m3, BufferedInputStream and BufferedOutputStream m4, FilterInputStream and FilterOutputStream mSOLUTION--- 2

Which of the following is the immediate superclass of the DataOutputStream, BufferedOutputStream, and PrintStream classes? m1, FileOutputStream m2, FilterOutputStream m3, PipedOutputStream m4, ByteArrayOutputStream mSOLUTION-- 2

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 regardin1, Both Statement A and Statement B are true. m2, Statement A is true while Statement B is false. m3, Statement A is false while Statement B is true. m4, Both Statement A and Statement B are false. mSOLUTION-- 1

Which of the following method enables you to force writes that an output stream accumulates? m1, close() m2, write() m3, flush() m4, read() mSOLUTION---- 3

Which of the following will you use to read a stream of bytes in a program?

m1, Reader m2, Writer m3, InputStream m4, OutputStream mSOLUTION--- 3

Which of the following class will you use to read the content of a file as a stream of bytes?

m1, FileReader m2, StringReader m A 3, FileInputStream m

4, PipedReader m

SOLUTION ---- 3

A___________ stream performs conversion on another stream.

m1, Filter m2, Output m3, Input m4, Print mSOLUTION-- 1

Which of the following method will you call to start a thread?

m1, notify() m2, yield() m3, run() m4, start() mSOLUTION---- 4

Which one of the following is a valid TCP/IP port number?

m1, -8080 m2, 65535 m3, 100000 m4, -7070 mSOLUTION-- 2

Consider the following statement:

Thread.sleep(x);

Select the correct option for the value x.

m1, An int value that specifies the number of seconds for which the thread must be made inactive. m2, A long value that specifies the number of milliseconds for which the thread must be made inactive. m3, A float value that specifies the number of seconds for which the thread must be made inactive. m4, A float value that specifies the number of milliseconds for which the thread must be made inactive. mSOLUTION-- 2

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. m1, Statement A is true while Statement B is false. m2, Both Statement A and Statement B are true. m3, Statement A is false while Statement B is true. m4, Both Statement A and Statement B are false. mSOLUTION---- 3

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.

m1, Both Statement A and Statement B are true. m2, Statement A is true while Statement B is false. m3, Statement A is false while Statement B is true. m4, Both Statement A and Statement B are false. mSOLUTION-- 2

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? m

1, ServerSocket s1 = new ServerSocket("127.168.0.10", 5430); m2, The code will compile, execute, wait for a key press, and then exit. m3, The code will compile, execute, wait for a key press, prints "Doing finally" on a key press, and then exit.

m4, The code will execute and exit immediately without output. mSOLUTION--- 3

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.l1, The code will throw an exception of type InterruptedException. m2, The code will display Java and C++. m3, The code will display only Java. m4, The code will display only C++. mSOLUTION--- 2

Consider an example.txt file saved in your working directory that contains the following content:User Name = AdminPassword = AdministratorHost = localhost

Which of the following code will you use to read the content of the example.txt file and di1, 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.display2, 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 ((str3, 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 =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()!=nuSOLUTION-- 2

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? m1, synchronized(this)public void operation(){/*Method Body*/} m2, public void operation(){synchronized(this)/*Method Body*/} m

3, public void synchronized operation(){/*Method Body*/} m4, public synchronized void operation(){/*Method Body*/} mSOLUTION----- 4