Multiple Choice Java Swing

Serialization - Java Multiple Choice Questions and Answers. This is the java programming questions and answers section on 'Java Serialization' with an explanation for various interview, competitive examination and entrance test. Solved examples with detailed answer description, explanation are given and it would be easy to understand. Java Multiple Choice Questions and Answers GUI Swing - wadiemendja/Multiple-Choice-Quiz.

Question 22 5 pts The MyErame class shown below extends the Java Swing Library JFrame class. The MyFrame constructor creates a simple GUI involving some JPanels and JButtons. One of the multiple choice images shows the correct GUI that would be displayed with the approximate sizes and locations of the buttons. You are to select the correct image.

Answer: (a) Bytecode is executed by the JVM.Explanation: The output of the Java compiler is bytecode, which leads to the security and portability of the Java code. It is a highly developed set of instructions that are designed to be executed by the Java runtime system known as Java Virtual Machine (JVM). The Java programs executed by the JVM that makes the code portable and secure.

Because JVM prevents the code from generating its side effects. The Java code is portable, as the same byte code can run on any platform.Hence, the correct answer is option (a).2) Which of the following is not a Java features?. Dynamic. Architecture Neutral.

Use of pointers. Object-orientedShow Answer Workspace. Answer: (c) Use of pointersExplanation: The Java language does not support pointers; some of the major reasons are listed below:. One of the major factors of not using pointers in Java is security concerns.

Due to pointers, most of the users consider C-language very confusing and complex. This is the reason why Green Team (Java Team members) has not introduced pointers in Java. Java provides an effective layer of abstraction to the developers by not using pointers in Java.Java is dynamic, architecture-neutral, and object-oriented programming language.Hence, the correct answer is option (c).3) What should be the execution order, if a class has a method, static block, instance block, and constructor, as shown below? Answer: (d) Static block, instance block, constructor, and methodExplanation: The order of execution is:.

The static block will execute whenever the class is loaded by JVM. Instance block will execute whenever an object is created, and they are invoked before the constructors. For example, if there are two objects, the instance block will execute two times for each object. The constructor will execute after the instance block, and it also execute every time the object is created.

A method is always executed at the end.Hence, the correct answer is an option (d).4) What will be the output of the following program? Answer: (d) 60, 30, 0, 20, 0Explanation: In the above code, there are two values of variable a, i.e., 10 and 60. Similarly, there are two values of variable b, i.e., 5 and 30. But in the output, the values of a and b are 60 and 30, respectively.

It is because of the execution order of the program.The execution order of the program is that the static block executes first, then instance block, and then constructor. Hence, the JVM will consider the value of a and b as 60 and 30 concerning the execution order. The value of a = 10 and b = 5 are of no use. And the value of variables c and m is 0 as we have not assigned any value to them.Hence, the correct answer is an option (d).5) The u0021 article referred to as a. Unicode escape sequence. Octal escape.

Hexadecimal. Line feedShow Answer Workspace. Answer: (a) Unicode escape sequenceExplanation: In Java, Unicode characters can be used in string literals, comments, and commands, and are expressed by Unicode Escape Sequences. A Unicode escape sequence is made up of the following articles:.

A backslash ' (ASCII character 92). A 'u' (ASCII 117). One or more additional 'u' characters that are optional. A four hexadecimal digits (a character from 0 - 9 or a-f or A-F)Hence, the correct answer is the option (a).6) is used to find and fix bugs in the Java programs. JVM. JRE. JDK.

JDBShow Answer Workspace. Answer: (d) JDBExplanation: The Java Debugger (JDB or jdb) is a command-line java debugger that debugs the java class. It is a part of the Java Platform Debugger Architecture (JPDA) that helps in the inspections and debugging of a local or remote Java Virtual Machine (JVM).The JVM (Java Virtual Machine) enables a computer to run Java or other language (kotlin, groovy, Scala, etc.) programs that are compiled to the Java bytecode. The JRE (Java Runtime Environment) is a part of JDK that contains the Java class libraries, Java class loader, and the Java Virtual Machine. The JDK (Java Development Kit) is a software development environment used to develop Java applications and applets.Hence, the correct answer is an option (d).7) Which of the following is a valid declaration of a char?. char ch = 'utea';.

char ca = 'tea';. char cr = u0223;. char cc = 'itea';Show Answer Workspace. Answer: (a) char ch = 'utea';Explanation: A char literal may contain a Unicode character (UTF-16).

We can directly use these characters only if our file system allows us, else use a Unicode escape (u) such as 'u02tee'. The char literals are always declared in single quotes (').The option b, c, and d, are not valid because:.

In the option b), to make a String valid char literal, we should add prefix 'u' in the string. In the option c), single quotes are not present. In the option d), 'i' is used in place of 'u.' Hence, the correct answer is the option (a).8) What is the return type of the hashCode method in the Object class?. Object. int. long.

voidShow Answer Workspace. Answer: (d) 0xnf029LExplanation: For every long literal to be recognized by Java, we need to add L character at the end of the expression. It can be either uppercase (L) or lowercase (l) character. However, it is recommended to use uppercase character instead of lowercase because the lowercase (l) character is hard to distinguish from the uppercase (i) character.For example,.

Lowercase l: 0x466rffl. Uppercase L: 0nhf450LHence, the correct answer is an option (d).10) What does the expression float a = 35 / 0 return?. 0. Not a Number. Infinity. Run time exceptionShow Answer Workspace. Answer: (c) InfinityExplanation: In Java, whenever we divide any number (double, float, and long except integer) by zero, it results in infinity.

According to the IEEE Standard for Floating-Point Arithmetic (IEEE 754), if we divide 1/0 will give positive infinity, -1/0 will give negative infinity, and 0/0 will give NaN. But on dividing an integer by zero, it throws a runtime exception, i.e., java.lang.ArithmeticException.Hence, the correct answer is an option (c).11) Evaluate the following Java expression, if x=3, y=5, and z=10:z + y - y + z + x. 24. 23. 20. 25Show Answer Workspace. Answer: (c) 8 times.

and 7 times Explanation: In the above code, we have declared count = 1. The value of count will be increased till 14 because of the while (count. Answer: (c) Javadoc toolExplanation: The Javadoc is a tool that is used to generate API documentation in HTML format from the Java source files.

In other words, it is a program (tool) that reads a collection of source files into an internal form.The Javadoc command line syntax is,Javadoc options packagenames sourcefiles @filesThe javap tool is used to get the information of any class or interface. It is also known as a disassembler. The javaw command is identical to java that displays a window with error information, and the javah command is used to generate native method functions.Hence, the correct answer is option (c).14) Which of the following creates a List of 3 visible items and multiple selections abled?. new List(false, 3). new List(3, true). new List(true, 3). new List(3, false)Show Answer Workspace.

Answer: (b) new List(3, true)Explanation: From the above statements, the new List(3, true) is the correct answer; this is because of the constructor type. Answer: (a) for ( int i = 99; i=0; i / 9)Explanation: The first option is not a valid declaration as i/9 is not declared correctly.

The correct statement will be:for ( int i= 99; i=0; i= i/9)Then the code would execute. But without assigning the value of i/9 to a variable, it would not execute, and an exception is thrown, as shown below.Exception in thread 'main' java.lang.Error: Unresolved compilation problem:Syntax error on token '/', invalid AssignmentOperatorThe other three statements are valid and will execute. Hence, the correct answer is the option (a).16) Which method of the Class.class is used to determine the name of a class represented by the class object as a String?.

getClass. intern. getName. toStringShow Answer Workspace. Answer: (c) getNameExplanation: The getName method of the Class class returns the name (as String) of the entity (class, interface) represented by this Class object. It is a non-static method, and available in the java.lang package.The getClass method of the Object class returns the runtime class of this object.

The intern and toString methods are of String class.Hence, the correct answer is option (c).17) In which process, a local variable has the same name as one of the instance variables?. Serialization. Variable Shadowing. Abstraction. Multi-threadingShow Answer Workspace. Answer: (d) It has no class nameExplanation: Anonymous inner classes are the same as the local classes except that they don't have any name. The main use of it is to override methods of classes or interfaces.And the rest three options are false about the anonymous inner classes as it can have both methods and objects.

It does not have any fixed came name.Hence, the correct answer is option(d).19) Which package contains the Random class?. java.util package. java.lang package. java.awt package.

java.io packageShow Answer Workspace. Answer: (a) java.util packageExplanation: The Random class is available in the java.util package. An object of the Random class is used to generate a series of pseudorandom numbers.

And the object of this class is a thread-safe and cryptographically insecure object. The Random class provides a variety of methods that are used to create random numbers of type integers, float, long, double, etc.Hence, the correct answer is option (a).20) What do you mean by nameless objects?. An object created by using the new keyword. An object of a superclass created in the subclass. An object without having any name but having a reference. An object that has no reference.Show Answer Workspace.

Answer: (d) An object that has no reference.Explanation: The nameless objects are basically referred to as anonymous objects. The anonymous objects do not have any names. We can also say that, when an object is initialized but is not assigned to any reference variable, it is called an anonymous object. For example, new Employee.If we assign it to a reference variable like,Employee emp = new Employee;In the above code, emp is a reference variable. Therefore, the above object is not anonymous, as it is assigned to a reference variable.Hence, the correct answer is option (d).21) An interface with no fields or methods is known as a.

Runnable Interface. Marker Interface. Abstract Interface. CharSequence InterfaceShow Answer Workspace.

Answer: (a) Applet classExplanation: According to the class hierarchy of Java Swing, the Applet class is the direct subclass of the Panel class. You can go through the linkto deeply understand the class hierarchy diagram.

The Panel class and Window class are the child classes of the Container class, and Frame and Dialog classes are the subclasses of the Window class.Hence, the correct answer is option (a).23) Which option is false about the final keyword?. A final method cannot be overridden in its subclasses.

A final class cannot be extended. A final class cannot extend other classes. A final method can be inherited.Show Answer Workspace. Answer: (c) A final class cannot extend other classes.Explanation: The final is a reserved keyword in Java that is used to make a variable, method, and class immutable.

The important features of the final keyword are:. Using the final keyword with a variable makes it constant or immutable. We can't reassign the values of it. A final variable must be a local variable and cannot be used in other classes. Using the final keyword with a method makes it constant, and we can't override it in the subclass. Using final with a class makes the class constant, and we cannot extend a final class. But a final class can extend other classes.Hence, the correct answer is option (c).24) Which of these classes are the direct subclasses of the Throwable class?.

RuntimeException and Error class. Exception and VirtualMachineError class. Error and Exception class.

IOException and VirtualMachineError classShow Answer Workspace. Answer: (b) An exception caused by other exceptions.Explanation: In Java, an exception caused by other exceptions is known as a chained exception.

Generally, the first exception causes the second exception. It helps in identifying the cause of the exception. In chained exceptions, the debugging information is not discarded.Hence, the correct answer is option (b).26) In which memory a String is stored, when we create a string using new operator?. Stack.

String memory. Heap memory. Random storage spaceShow Answer Workspace.

Answer: (c) Heap memoryExplanation: When a String is created using a new operator, it always created in the heap memory. Whereas when we create a string using double quotes, it will check for the same value as of the string in the string constant pool. If it is found, returns a reference of it else create a new string in the string constant pool.Hence, the correct answer is option (c).27) What is the use of the intern method?. It returns the existing string from memory. It creates a new string in the database. It modifies the existing string in the database.

None of the aboveShow Answer Workspace. Answer: (a) It returns the existing string from the memoryExplanation: The intern method is used to return the existing strings from the database. In other words, the intern method returns a reference of the string. For example, if the string constant pool already has a string object with the same value, the intern method will return a reference of the string from the pool.Hence, the correct answer is option (a).28) Which of the following is a marker interface?.

Runnable interface. Remote interface. Readable interface. Result interfaceShow Answer Workspace.

Answer: (b) Remote interfaceExplanation: A marker interface is an interface with no fields and methods. In other words, an empty interface (contains nothing) is known as the marker interface. Examples of marker interfaces are Cloneable, Serializable, ThreadSafe, and Remote interface.The Runnable, Readable, and Result interface are not marker interface as they contain some methods or fields.Hence, the correct answer is option (b).29) Which of the following is a reserved keyword in Java?. object. strictfp. main. systemShow Answer Workspace.

Answer: (b) strictfpExplanation: In the above options, strictfp is the only reserved keyword of Java. The strictfp keyword is a modifier that restricts the floating-point calculations to assure portability and it was added in Java version 1.2.

The objects are referring to those variables that are created using the new operator. In Java, main is the method that is the entry point of any program, and the System is a class.Hence, the correct answer is option (b).30) Which keyword is used for accessing the features of a package?. package.

import. extends.

exportShow Answer Workspace. Answer: (b) importExplanation: The import keyword is used to access the classes and interfaces of a particular package to the current file. In other words, it is used to import the user-defined and built-in classes and interfaces into the source file of java so that the current file can easily access the other packages by directly using its name. For example,import java.awt.;import java.lang.Object;The first import statement imports all the classes and interfaces of java.awt package. Whereas, the second import statement only imports the Object class of the java.lang package.The package keyword is used to create a new package. The extends keyword indicates that the new class is derived from the base or parent class using inheritance, and export is not a keyword in Java.Hence, the correct answer is option (b).31) In java, jar stands for. Java Archive Runner.

Java Application Resource. Java Application Runner. None of the aboveShow Answer Workspace. Answer: (c) CimpletdExplanation: In the above code snippet, we have passed a string with value 'Complete' and set character 'i' and 'd' at the index position 1 and 7, respectively. According to the string 'Complete,' 'o' is at position 1, and 'e' is at the position 7. Adobe dreamweaver cs4 with crack.

The setChar method is used to replace the original string values with the new one. Hence, the 'o' and 'e' are replaced by the characters 'i' and 'd,' respectively, which results in 'Cimpletd.' Hence, the correct answer is option (c).33) Which of the following is false?. The rt.jar stands for the runtime jar. It is an optional jar file. It contains all the compiled class files. All the classes available in rt.jar is known to the JVMShow Answer Workspace.

Answer: (b) It is an optional jar file.Explanation: The rt.jar stands for the runtime jar that comprises of all the compiled core class files for the Java Runtime Environment. It generally consists of classes like java.lang.String, java.lang.Object, java.io.Exception, etc., and all packages and classes available in the rt.jar are known to the JVM. The rt.jar is the mandatory jar file for every core java application as it contains all the core classes.Hence, the correct answer is option (b).34) What is the use of w in regex?. Used for a whitespace character. Used for a non-whitespace character. Used for a word character. Used for a non-word characterShow Answer Workspace.

Answer: (c) Used for a word characterExplanation: In java, the ' w' regex is used to match with a word character consists of a-zA-Z0-9. For example, w+ matches one or more word character that is same as (a-zA-Z0-9 +).The regex W, s, and S are used for a non-word character, a whitespace character, and a non-whitespace character, respectively. Hence, the w regex is used for a word character.Hence, the correct answer is option (c).35) Which of the given methods are of Object class?. notify, wait( long msecs ), and synchronized.

wait( long msecs ), interrupt, and notifyAll. notify, notifyAll, and wait. sleep( long msecs ), wait, and notifyShow Answer Workspace. Answer: (c) notify, notifyAll, and waitExplanation: The notify, notifyAll, and wait are the methods of the Object class. The notify method is used to raise a single thread that is waiting on the object's monitor. The notifyAll method is similar to the notify method, except that it wakes up all the threads that are waiting on the object's monitor. The wait method is used to make a thread to wait until another thread invokes the notify or notifyAll methods for an object.Hence, the correct answer is option (c).36) Given that Student is a class, how many reference variables and objects are created by the following code?

Answer: (a) Three reference variables and two objects are created.Explanation: In the above code, there are three reference variables and two objects. The studentName, studentId, and studclass are the three reference variables.

The objects are those variables that are created using the new operator, i.e., studentName and studclass. The studentId is only a reference variable as it is not declared using the new operator. Both studentName and studclass are reference variables as well as objects.Hence, there are three reference variables and two objects.Hence, the correct answer is option (a).37) Which of the following is a valid syntax to synchronize the HashMap?. Map m = hashMap.synchronizeMap;. HashMap map =hashMap.synchronizeMap;.

Map m1 = Collections.synchronizedMap(hashMap);. Map m2 = Collection.synchronizeMap(hashMap);Show Answer Workspace. Answer: (b) Method is not defined properly.Explanation: Following are some rules for declaring an abstract method:. Abstract methods do not specify a method body, but they only have a method signature. Abstract methods are always defined inside an abstract class.In the above code, MyFirstClass is an abstract class. It contains an abstract method named num that is not defined properly. According to the rules discussed above, an abstract method only has a method signature, not the method body.Hence, the correct answer option (b).41) What is meant by the classes and objects that dependents on each other?.

Tight Coupling. Cohesion. Loose Coupling. None of the aboveShow Answer Workspace. Answer: (b) Multiple threadsExplanation: In Java, multiple threads can be executed at the same time. A Java standalone application always starts with a single thread known as the main thread that is associated with the main method.In the operating system, only one thread is executed at a time.Hence, the correct answer is option (b).45) If three threads trying to share a single object at the same time, which condition will arise in this scenario?.

Time-Lapse. Critical situation. Race condition. RecursionShow Answer Workspace. Answer: (c) Race conditionExplanation: If two or more threads are trying to access a common resource at the same time. This situation is known as race condition.

It generally occurs during the execution of multi-threaded application. It also refers to a programming bug or issue that occurs when the thread scheduler swaps the threads at any time between the process.Hence, the correct answer is option (c).46) If a thread goes to sleep. It releases all the locks it has. It does not release any locks. It releases half of its locks.

It releases all of its lock except one.Show Answer Workspace. Answer: (b) It does not release any locks.Explanation: The sleep method does not release any locks of an object for a specific time or until an interrupt occurs. It leads to the poor performance or deadlock of threads. Whereas, the wait method does not release the locks of an object.Therefore, when a thread goes to sleep, it does not release any locks.Hence, the correct answer is the option (b).47) Which of the following modifiers can be used for a variable so that it can be accessed by any thread or a part of a program?. global. transient.

volatile. defaultShow Answer Workspace. Answer: (c) volatileExplanation: In Java, we can modify the values of a variable with the help of a reserved keyword known as volatile. It is a different way of making a class thread-safe.

Thread-safe means that the methods and objects of a class are accessible by multiple threads at the same time.The volatile keyword is not a replacement of a synchronized block or method as it does not remove the need for synchronization among the atomic actions.Global is not a reserved keyword in Java. The transient and default are keywords in Java, but they are not used for accessing a variable by a thread from any part of the program.Hence, the correct answer is an option (c).48) What is the result of the following program? Answer: (d) A will be printed, and then an exception is thrown.Explanation: The InterruptedException is thrown when a thread is waiting, sleeping, or occupied. The output of the above code is shown below: AException in thread 'main' java.lang.IllegalMonitorStateExceptionat java.lang.Object.wait(Native Method)at com.app.java.B.main(B.java:9)In the above code, we have created a thread 'f,' and when started, A will be printed. After that, the thread will wait for 1000 seconds. Now, an exception is thrown instead of printing B. It is because the wait method must be used inside a synchronized block or try-catch block unless it will throw an exception, as shown above.Hence, the correct option is option (d).49) In character stream I/O, a single read/write operation performs.

Two bytes read/write at a time. Eight bytes read/write at a time.

One byte read/write at a time. Five bytes read/ write at a time.Show Answer Workspace. Answer: (a) Two bytes read/write at a time.Explanation: There are two types of I/O stream. One is a byte stream, and the other is the character stream. The Byte stream is used to perform input or output 8-bit (equals to 1 byte) Unicode bytes whereas, the Character stream is used to read or write a 16-bit (equals to 2 bytes) Unicode character.Therefore, a single operation of character stream performs two bytes read/ write at a time.Hence, the correct answer is option (a).50) What is the default encoding for an OutputStreamWriter?.

UTF-8. Default encoding of the host platform. UTF-12. None of the aboveShow Answer Workspace.