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 .net
  1. When the PrintDialog control is displayed.

  2. When an assignment is made to the Document property.

  3. The first time the Print method is called.

  4. Every time a page is printed after the Print method is called.

  5. None of the above.

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

The PrintPage event fires once for each page being printed, triggered after Print() is called. It's not activated by dialog display or property assignment alone. This event handler contains the logic to render each individual page's content and must be called repeatedly for multi-page documents.

Multiple choice java
  1. True

  2. False

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

The statement is True.

The "synchronized" keyword in Java is used to achieve thread synchronization. When a method or a block of code is declared as synchronized, it means that only one thread can access that method or block at a time.

When a thread encounters a synchronized method or block, it first checks if the lock associated with the object is available. If the lock is available, the thread grabs the lock and proceeds with executing the code inside the synchronized method or block. After the execution is complete, the lock is released, allowing other threads to access the synchronized code.

So, the "synchronized" keyword ensures that a thread grabs an object lock before continuing execution, making the statement True.

The answer is: A. True

Multiple choice .net asp
  1. Response.Output.Write() allows you to flush output

  2. Response.Output.Write() allows you to buffer output

  3. Response.Output.Write() allows you to write formatted output

  4. Response.Output.Write() allows you to stream output

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

Response.Output.Write() provides formatted output capabilities using String.Format-style syntax, while Response.Write() only writes raw strings. Response.Output.Write() allows you to write formatted output with parameters like Response.Output.Write("Hello {0}", name), making it more flexible for dynamic content generation. The other options (flush, buffer, stream) are not the key differences.

Multiple choice .net asp
  1. Session.Close( )

  2. Session.Discard( )

  3. Session.Abandon

  4. Session.End

  5. Session.Exit

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

Session.Abandon() is the correct method to explicitly end or destroy a user session in ASP.NET. This method cancels the current session and releases its resources. There is no Session.Close(), Session.Discard(), Session.End, or Session.Exit method in the Session object.

Multiple choice .net asp
  1. ExecuteReader

  2. ExecuteScalar

  3. ExecuteStream

  4. Open

  5. CommandText

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

The Open method is not a member of any Command object (whether ADODB.Command or SqlCommand). Open is a method used with Connection objects to establish a database connection. Command objects have methods like Execute, ExecuteReader, ExecuteScalar, ExecuteNonQuery, and properties like CommandText, CommandType, and CommandTimeout.

Multiple choice .net c-sharp
  1. call

  2. this

  3. do

  4. that

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

In C#, the variable named "this" is used to refer to the current object whose method is being invoked.

Now, let's go through each option and explain why it is right or wrong:

A. call: This option is incorrect because "call" is not the variable used to refer to the current object in C#.

B. this: This option is correct. In C#, "this" is used as a reference to the current object. It allows you to access members of the current instance within a method or constructor.

C. do: This option is incorrect because "do" is not the variable used to refer to the current object in C#.

D. that: This option is incorrect because "that" is not the variable used to refer to the current object in C#.

Therefore, the correct answer is B. this.

Let me know if you have any other questions or if there's anything else I can assist you with!

Multiple choice .net c-sharp
  1. Try

  2. Catch

  3. Exception

  4. Event

  5. System

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

In .NET and Java, the base class for all exceptions is named Exception. Try and Catch are keywords used for handling exceptions, not classes for derivation. Event and System are related to the broader framework but do not serve as the specific base for exception objects.

Multiple choice .net c-sharp
  1. Lock and Unlock methods

  2. Enter and Exit methods

  3. Close and Open methods

  4. Close and Allow methods

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

The Monitor class uses Enter() to acquire a lock and Exit() to release it. In C#, you typically use the lock keyword which compiles to Monitor.Enter and Monitor.Exit. Lock/Unlock and Close/Open are not the correct method names for this purpose.

Multiple choice .net c-sharp
  1. finds the first occurrence of each letter in the string

  2. searches for the first occurrence of any of the characters in the string

  3. will search for the first occurrence of the sequence of characters

  4. generates an error

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

The IndexOfAny method searches a string for the first occurrence of ANY character from a specified character array. It returns the index of the first match found, not separate searches for each character or searching for a sequence.

Multiple choice .net c-sharp
  1. they represent the same meory location

  2. the are two different objects

  3. if one changes, so will the other

  4. None of the above

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

StringBuilder objects are reference types - even if two instances contain the same string content, they are separate objects in memory. Changing one StringBuilder does not affect the other because they point to different memory locations. Only value types or interned strings might share memory.

Multiple choice javascript
  1. Check for the presence of certain characters

  2. Check the position of substrings

  3. Test the length of data

  4. Check the variable type of the strings

  5. Either ABC

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

Form validation using string methods typically involves checking character presence (indexOf/includes), substring positions (indexOf/search), and testing data length (length property). All three techniques are commonly used together for robust validation.

Multiple choice .net vb
  1. Constructors

  2. Interrogative methods

  3. Imperative methods

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

Methods that return values to calling code are called interrogative methods because they 'ask a question' and return an answer. Imperative methods change object state or perform actions and typically return void. Constructors initialize new objects and aren't primarily for returning values.