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. 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

Encode only the user input parameter, not the entire URL. Option C correctly encodes just the dangerous input. Option A uses JavaScript encoding (wrong context). Option B encodes the entire URL including the path, which breaks it.

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 when validation fails. ValidationException (A) is not the standard exception name, and Encoding/Encryption exceptions (C, D) are for different operations.

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

In exception hierarchies, a base exception class provides common properties and methods for all related exceptions. EnterpriseSecurityException serves as the parent class for specific security exceptions, allowing consistent error handling across different security failure scenarios.

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

Path Traversal attacks attempt to access files outside the intended directory using sequences like '../'. isSafeDirectoryPath and isSafeFileName validate that paths don't escape allowed directories and filenames don't contain dangerous sequences, preventing unauthorized file system access.

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

Secure password hashing requires both the password and a unique salt per user. The hashPassword method takes both password and accountName parameters, where accountName serves as the salt, ensuring that even identical passwords produce different hashes for different accounts.

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 performs validation checks on password strength requirements (length, complexity, etc.). Being a void method means it doesn't return a value - it either completes successfully if the password is strong enough, or throws an exception if it fails validation checks.

Multiple choice technology security
  1. String

  2. boolean

  3. Integer

  4. void

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

Authorization checks determine whether a user has permission to access specific data. The isAuthorizedForData() method returns a boolean - true if the user has permission, false otherwise. This simple yes/no result is sufficient for authorization decisions in access control systems.

Multiple choice technology security
  1. Integer

  2. Byte

  3. String

  4. BigInteger

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

CSRF tokens are random, unique strings generated by the server and embedded in forms or AJAX requests. The getCSRFToken() method returns this token as a String, allowing it to be included in requests and validated server-side to ensure requests originate from the legitimate application, not a malicious site.

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 in the security API throws SecurityException to handle cryptographic failures gracefully. Option B lacks exception handling, A throws the wrong exception type, and C is missing the key parameter. Security operations must declare appropriate exceptions for failure scenarios.

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 signature includes a timestamp parameter and throws SecurityException for error handling. Option B uses the wrong exception type (EncryptionException), while options C and D are missing the timestamp parameter which is typically required for temporal validation in sealing operations.

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

The correct approach encodes only the dangerous user input parameter using encodeForURL, not the entire URL. Option A uses JavaScript encoding which is wrong for URL parameters. Option B encodes the entire URL which would break the URL structure. Only the user input needs encoding.

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 common exception thrown by validation methods in security APIs. It serves as the base class for security-related failures, including validation errors. While the option lists specific validation exceptions, SecurityException is the standard runtime exception for such cases.

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 this API. While SecurityException might seem logical, this specific API hierarchy uses EnterpriseSecurityException as the root. EnterpriseException is likely a broader base for all enterprise exceptions.

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

To prevent path traversal attacks, TCS SAPI provides isSafeDirectoryPath() and isSafeFileName(). Both methods take a context, input string, and allowNull flag. The 'isSafe' prefix methods (option C) are the correct API methods for validating path safety.

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 correct signature is String hashPassword(String password, String accountName). The accountName is used as the salt, so it's required. Option A is missing the salt parameter, and option C has incorrect case (hashpassword instead of hashPassword).