Computer Knowledge

Java Core Classes and Threads

1,935 Questions

Java core classes and threads form the foundation of object oriented programming and are crucial for IT officer and programming exams. This includes concepts like string mutability, collections, and multithreading. Solve these questions to test your practical coding and theoretical knowledge.

String and StringBuffer classesThread execution methodsJava collections frameworkCharacter streams input outputVariable serialization rules

Java Core Classes and Threads Questions

Multiple choice technology web technology
  1. 4

  2. 7

  3. 9

  4. 8

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

JSP provides 9 implicit objects: request, response, out, session, application, config, pageContext, page, and exception. These are automatically available in JSP pages without explicit declaration.

Multiple choice technology web technology
  1. $object.method()
  2. $object->$method()
  3. $object:$method()
  4. $object->method()
Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

In PHP, object methods are called using the arrow operator (->), which is the standard syntax for accessing properties and methods of an object. This is distinct from languages like JavaScript or Java that use dot notation.

Multiple choice technology programming languages
  1. The signature of a method is the name of the method the type of its return value.

  2. The signature of a method is the name of the method and the names of its parameters.

  3. The signature of a method is the name of the method and the data types of its parameters.

  4. The signature of a method is the name of the method, its parameter list, and its return type.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

A method's signature consists of the method name and the data types of its parameters (in order). This uniquely identifies overloaded methods. The return type is NOT part of the signature in most languages (Java, C++). Parameter names don't matter for overloading resolution, only their types.

Multiple choice technology programming languages
  1. Visitor

  2. Observer

  3. Builder

  4. Proxy

  5. Iterator

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

The Iterator pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation. This is the exact mechanism used by Java Collections. Patterns like Visitor, Observer, Builder, and Proxy serve entirely different architectural purposes.

Multiple choice technology programming languages
  1. Initialization

  2. Start of Selection.

  3. At Selection-screen output

  4. At Selection-screen.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In ABAP executable programs, if no event keyword is explicitly specified, any processing blocks written before the first event keyword are automatically assigned to the START-OF-SELECTION event. Thus, it acts as the default event block.

Multiple choice technology programming languages
  1. Hashtable

  2. Hashmap

  3. Linked Hashmap

  4. Hashset

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Hashtable is the only inherently synchronized option among these classes, making it thread-safe for concurrent access. HashMap and its variant LinkedHashMap are not synchronized by design, while HashSet cannot store key-value pairs. Hashtable's built-in synchronization makes it suitable for multi-threaded environments without requiring additional synchronization code.

Multiple choice technology programming languages
  1. If the start() method is invoked twice on the same Thread object, an exception is thrown at runtime.

  2. The order in which threads were started might differ from the order in which they actually run.

  3. If the run() method is directly invoked on a Thread object, an exception is thrown at runtime.

  4. If the sleep() method is invoked on a thread while executing synchronized code, the lock is not released.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

To answer this question one needs to know about threads in programming. Threads are the smallest unit of execution that can be scheduled by an operating system. Each thread represents a separate flow of control. Threads are lightweight compared to processes, and they share memory with other threads in the same process.

Now let's go through each option and explain why it is true or false:

A. If the start() method is invoked twice on the same Thread object, an exception is thrown at runtime.

This statement is true. If the start() method is invoked twice on the same Thread object, an exception (IllegalThreadStateException) is thrown at runtime.

B. The order in which threads were started might differ from the order in which they actually run.

This statement is true. The operating system schedules threads based on its own algorithm, which might differ from the order in which the threads were started.

C. If the run() method is directly invoked on a Thread object, an exception is thrown at runtime.

This statement is false. If the run() method is directly invoked on a Thread object, the run() method will execute just like any other method. However, it will not start a new thread of execution, and any other code that is waiting for the thread to complete will not be notified.

D. If the sleep() method is invoked on a thread while executing synchronized code, the lock is not released.

This statement is true. When a thread invokes the sleep() method while executing synchronized code, the lock associated with the synchronized code is not released. This means that other threads that require the same lock will have to wait until the sleeping thread releases the lock.

Therefore, the correct answer is: C. If the run() method is directly invoked on a Thread object, an exception is thrown at runtime.

Multiple choice technology programming languages
  1. abstract

  2. assert

  3. synchronized

  4. strictfp

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The assert keyword was introduced in Java 1.4 as a mechanism for implementing assertions - boolean expressions that test assumptions during development. The other keywords (abstract, synchronized, strictfp) were present in earlier Java versions. Assertions are typically disabled in production but can be enabled at runtime with the -ea or -enableassertions flag.

Multiple choice technology programming languages
  1. getInitParameterNames()

  2. getInitParameter(String name)

  3. getServletName()

  4. getServletContext()

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

getInitParameter(String name) returns null if the requested parameter does not exist. The other methods (getInitParameterNames returns an Enumeration, getServletName returns a String, getServletContext returns a ServletContext) never return null.

Multiple choice technology platforms and products
  1. map.initializeMap("maps","center");

  2. map.createMapContainer(new google.maps.centerLatLng("1","-120"))

  3. GMapApi.static.Initialize();

  4. map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The setCenter method is required immediately after creating a map using the Google Maps constructor to specify the map's center point and zoom level. Without this, the map would not know where to focus. Options A, B, and C either use incorrect method names or improper syntax.

Multiple choice technology testing
  1. A. Value

  2. B. Import

  3. C. GetCell

  4. D. GetValue

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The DataTable.Value property (or shortcut DataTable("ParameterName", dtLocalSheet)) is the standard method to retrieve or set data in a QTP/UFT DataTable during a run. Import imports external sheets, while GetCell or GetValue are not standard DataTable retrieval methods.

Multiple choice technology testing
  1. A. Pop-up window, object state, VBScript event

  2. B. Object State, VBScript event, Application crash

  3. C. Pop-up window, object state, test run error, QTP crash

  4. D. Pop-up win

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

QTP/UFT recovery scenarios support four trigger events: Pop-up window, Object state, Test run error, and Application crash (often referred to as QTP crash). Options A and B are incomplete and include VBScript events, which are not native recovery trigger types.

Multiple choice technology programming languages
  1. Map m = Collection.synchronizeMap(hashMap);

  2. Map m = Collections.synchronizeMap(hashMap);

  3. Map m = hashMap.synchronizeMap();

  4. none

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

HashMap is not thread-safe, but can be wrapped using Collections.synchronizedMap() to obtain a synchronized wrapper. Option B correctly shows the syntax: Map m = Collections.synchronizeMap(hashMap); - note the class is Collections (plural), not Collection. Option A is incorrect because Collection.synchronizeMap doesn't exist.

Multiple choice technology packaged enterprise solutions
  1. Getrecord

  2. Getrow

  3. Getcomponent

  4. Getfield

  5. Getlevel

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In PeopleCode, GetLevel, GetRow, GetRecord, and GetField are standard classes and methods used to traverse the buffer hierarchy. There is no Getcomponent function or method used for buffer traversal; components are accessed via different APIs.