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 security
  1. java.lang.String sign(java.lang.String data, java.lang.String key) throws EncryptionException

  2. java.lang.String sign(java.lang.String data, java.lang.String key)

  3. java.lang.String sign(java.lang.String data)

  4. java.lang.String sign(java.lang.String data) throws SecurityException

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

The sign method takes a single String parameter (the data to be signed) and throws SecurityException if signing fails or security constraints are violated. The method does not require an explicit key parameter as the key is managed internally by the security API.

Multiple choice technology security
  1. java.lang.String seal(java.lang.String data,long timestamp) throws SecurityException

  2. java.lang.String seal(java.lang.String data,long timestamp) throws EncryptionException

  3. java.lang.String seal(java.lang.String data)

  4. java.lang.String seal(java.lang.String data) throws EncryptionException

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

The seal method accepts the data to be sealed and a timestamp parameter for time-based validation, returning a sealed String representation. It throws SecurityException when sealing operations fail due to security violations or invalid parameters.

Multiple choice technology security
  1. String safeURIToDisplay= "/admin/findUser.do?name=" + TCSSAPI.encoder().encodeForJavaScript(request.getParameter( "dangerousInput"));

  2. String safeURIToDisplay = TCSSAPI.encoder().encodeForURL( "/admin/findUser.do?name=" + request.getParameter( "dangerousInput" ) );

  3. String safeURIToDisplay= "/admin/findUser.do?name=" + com.tcs.sapi.io.ValidationUtil.encodeForURL(request.getParameter( "dangerousInput"));

  4. None of the above

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

Only the user-supplied parameter needs encoding, not the entire URL structure. Option C correctly encodes just the dangerous input while preserving the URL's query parameter syntax. Option A uses JavaScript encoding which is inappropriate for URL contexts, and Option B incorrectly encodes the entire URL string including the '=' delimiter.

Multiple choice technology security
  1. Validation Exception

  2. SecurityException

  3. Encoding Exception

  4. Encryption Exception

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

SecurityException is the most common exception thrown by validation methods in the security API. This exception occurs when validation checks fail, such as when input data doesn't meet security requirements or when access permissions are insufficient. Other exceptions like Encoding Exception or Encryption Exception are specific to different operations and not typically thrown during general validation.

Multiple choice technology security
  1. SecurityException

  2. EnterpriseException

  3. EnterpriseSecurityException

  4. None of the above

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

EnterpriseSecurityException is the base class for all Security related exceptions in the security API. This class hierarchy allows for structured exception handling, where specific security exceptions can inherit from a common base. It provides a consistent way to catch and handle security-related errors throughout the application.

Multiple choice technology security
  1. isValidDirectory( java.lang.String context, java.lang.String input)

  2. isValidDirectory( java.lang.String context, java.lang.String input) and isValidFileName(java.lang.String context, java.lang.String input)

  3. isSafeDirectoryPath(java.lang.String context, java.lang.String input,boolean allowNull) and isSafeFileName(java.lang.String context, java.lang.String input,boolean allowNull)

  4. ValidateDirectoryPath(java.lang.String context, java.lang.String input,boolean allowNull)

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

The TCS SAPI provides isSafeDirectoryPath() and isSafeFileName() methods to prevent Path Traversal attacks. These methods validate that directory paths and filenames don't contain malicious sequences like '../' that could allow attackers to access files outside the intended directory. The allowNull parameter determines whether null/empty values should be considered valid.

Multiple choice technology enterprise content management
  1. It is deleted if the corresponding properties are set.

  2. It is hidden if the corresponding properties are set.

  3. An end user can delete any Live object within any special properties to be set

  4. It is hidden even if no special properties set.

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

When an end user deletes a Live object, it is hidden (not completely deleted) if the corresponding deletion properties are properly configured. This allows for recovery or controlled deletion behavior. Special properties must be set for this to work - it won't happen automatically.

Multiple choice technology
  1. 0

  2. 1

  3. 2

  4. 4

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

The Exception Handler activity in DataStage is designed to catch and handle exceptions that occur during job execution. It does not require any input links to function - its purpose is to handle errors that might occur in other stages. The minimum number of input links required is zero. Therefore option A (0) is correct.

Multiple choice technology security
  1. String hashPassword(String password)

  2. String hashPassword(String password, String accountName)

  3. String hashpassword(String password)

  4. None of the above

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

The hashPassword method requires both the password and accountName parameters. The accountName is typically used as a salt or to ensure uniqueness of hashes across accounts. Option A only takes the password, which would result in identical passwords producing identical hashes - a security vulnerability. Option C has incorrect capitalization.

Multiple choice technology security
  1. Boolean

  2. String

  3. Integer

  4. void

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

The verifyPasswordStrength() method returns void because it likely throws an exception if the password doesn't meet strength requirements rather than returning a boolean. This pattern is common in security APIs where failure should halt execution. However, this is a specific API design choice that depends on the actual framework being referenced.