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 programming languages
  1. ProcessRequest and IsReusable

  2. ProcessResponse and IsReusable

  3. GenerateRequest and ProcessResponse

  4. GenerateResponse and ProcessRequest

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

The IHttpHandler interface in ASP.NET defines exactly two methods: ProcessRequest (which handles the HTTP request) and IsReusable (which indicates whether the handler can be pooled for reuse). Other options mention non-existent methods like ProcessResponse or GenerateRequest.

Multiple choice technology programming languages
  1. for (int i = 0; i < 80; i++) { stream1.WriteByte(byteArray[i]); bytesTransferred = i; if (!stream1.CanWrite) { break; }}

  2. bytesTransferred = stream1.Read(byteArray, 0, 80);

  3. while (bytesTransferred < 80) { stream1.Seek(1, SeekOrigin.Current); byteArray[bytesTransferred++] = Convert.ToByte(stream1.ReadByte());}

  4. stream1.Write(byteArray, 0, 80);bytesTransferred = byteArray.Length;

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

The Stream.Read(byte[], offset, count) method reads bytes from the stream into the array and returns the number of bytes actually read. Option B correctly uses this pattern. Option D writes TO the stream instead of reading from it. Options A and C use inefficient manual byte-by-byte loops.

Multiple choice technology embedded technologies
  1. initApp,pauseApp,destroyApp

  2. initApp,pauseApp,closeApp

  3. startApp,pauseApp,destroyApp

  4. startApp,pauseApp,stopApp

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

MIDlet lifecycle is defined by three mandatory methods that must be implemented. The correct methods are startApp() for initialization, pauseApp() for pausing, and destroyApp() for cleanup. Options A and B incorrectly use initApp instead of startApp, while option D incorrectly uses stopApp instead of destroyApp.

Multiple choice technology embedded technologies
  1. initApp,pauseApp,destroyApp

  2. initApp,pauseApp,closeApp

  3. startApp,pauseApp,destroyApp

  4. startApp,pauseApp,stopApp

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

MIDlets (Java ME mobile applications) must implement three lifecycle methods: startApp() (initialization/activation), pauseApp() (when paused/minimized), and destroyApp() (cleanup before termination). These manage the application's lifecycle states.

Multiple choice technology programming languages
  1. Using Only Get..EndGet with in property definition

  2. Using Only Set..EndSet with in property definition

  3. Using both Get and Set

  4. None of these

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

To create a read-only property in VB.NET, you use the ReadOnly modifier and define only the Get block within the property block, omitting the Set block.

Multiple choice technology web technology
  1. Load ( )

  2. Fill( )

  3. DataList

  4. DataBind

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

The DataAdapter's Fill() method is used to populate a DataSet or DataTable with data from a data source. The Fill method executes the query and retrieves the data into the dataset. Load is not a DataAdapter method, DataList is a control, and DataBind is for binding data to controls.

Multiple choice technology web technology
  1. Thread.Interrupt()

  2. Thread.Abort()

  3. Both A) and B)

  4. None of the Above

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

Thread.Interrupt() causes a thread to throw ThreadInterruptedException when it enters a wait state, while Thread.Abort() raises ThreadAbortException to terminate the thread. Both methods can stop thread execution, though Abort() is deprecated in modern .NET due to potential data corruption.

Multiple choice technology programming languages
  1. new and delete are keywords in the Java language

  2. try, catch, and thrown are keywords in the Java language

  3. return, goto, and default are keywords in the Java language

  4. for, while, and next are keywords in the Java language

Reveal answer Fill a bubble to check yourself
D Correct answer
Multiple choice technology
  1. All of these

  2. (C) & (E)

  3. (A), (C) & (E)

  4. (B),(C) & (D)

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

To solve this question, the user needs to have knowledge about the initial version of Java and the keywords that were reserved but not used. The user must then identify which options list the correct keywords.

The correct answer is:

D. (B),(C) & (D)

Explanation:

In the initial version of Java, the keywords "const" and "goto" were reserved but not used. The keyword "inner" was not reserved at all in the initial version of Java. The other options, "union", "boolean", and "synchronized" were not keywords in the initial version of Java.

Therefore, options (A) and (C) are incorrect as they include options that were not reserved in the initial version of Java. Option (B) is incorrect as "boolean" was not a reserved keyword in the initial version of Java. Option (D), on the other hand, correctly lists all the keywords that were reserved but not used in the initial version of Java, which are "const", "goto", and "inner".

The Answer is: D. (B),(C) & (D)

Multiple choice technology web technology
  1. All of these.

  2. b. (C) & (E)

  3. c. (A), (C) & (E)

  4. d. (B),(C) & (D)

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

Java reserves goto and const as keywords but doesn't use them. 'inner' was reserved for potential inner class support but ultimately wasn't used (inner classes use different syntax). Union, boolean, and synchronized are used keywords.

Multiple choice technology programming languages
  1. Clear

  2. Write

  3. Execute

  4. Flush

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

The Response object in ASP.NET includes Clear, Write, Flush, Redirect, and End methods, but Execute is not a member. Execute is actually a method of the Server object (Server.Execute) which transfers execution to another page. The Response object handles sending output to the client, while Server.Execute handles page transfer. This distinction is important for understanding ASP.NET's object model.

Multiple choice technology programming languages
  1. if ( i > 10) { throws new IndexOutOfBoundsException("Index is out of bound!"); }

  2. if ( i > 10) { throw new IndexOutOfBoundsException("The value of index i=" + " is out of bound!" ); }

  3. if ( i > 10) { throw "Index is out of bound!"; }

  4. None of the ABove

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

Java exceptions are objects thrown using the 'throw' keyword with 'new' to instantiate the exception class. Option B shows correct syntax: 'throw new IndexOutOfBoundsException(...)' creates the exception object and throws it. Option A uses 'throws' (a declaration keyword, not for throwing) and has a typo. Option C tries to throw a string literal directly, which isn't valid - only Throwable objects can be thrown.