GSSP-Java

GSSP-Java practice questions, page 3 of 11, with answer review and explanations.

Question 11

Given a code of a class named PrintString that prints a string. 1. public class PrintString{ 2. public static void main(String args[]){ 3. /*insert code here */ 4. /* insert code here */ 5. System.out.println(str); 6. } 7. } Which of the following code fragments can be inserted in the class PrintString to print the output "4247"? Each correct answer represents a complete solution. Choose all that apply.

  1. StringBuilder str= new StringBuilder("123456789"); str.delete(0,3).replace(1,3,"24").delete(4,6);
  2. StringBuffer str= new StringBuffer("123456789"); str.delete(0,3).replace(1,3,"24").delete(4,6);
  3. StringBuffer str=new StringBuffer("123456789"); str.substring(3,6).delete(1,2).insert(1,"24");
  4. StringBuilder str= new StringBuilder("123456789"); str.deleteCharAt(6).replace(1,3,"24").delete(0,3);
  5. String str="123456789"; str=(str-"123").replace(1,3,"24")-"89";

Question 12

Mark writes a class Practice.java. This class needs to access the com.bar.Test class that is stored in the Test.jar file in the directory /practice. How would you compile your code?

  1. javac -classpath /practice/Test.jar Practice.java
  2. javac -classpath /practice/ Practice.java
  3. javac -classpath /practice/Test.jar/com/bar Practice.java
  4. javac -classpath /practice Practice.java

Question 13

Which of the following statements is true?

  1. All UTF characters are eight bits long.
  2. All UTF characters are all sixteen bits long.
  3. All UTF characters are twenty four bits long.
  4. All bytecode characters are sixteen bits long.
  5. All unicode characters are sixteen bits long.

Question 14

John works as a Programmer for Technostar Inc. He writes the following code using Java. 1. class WrapperClass{ 2. public static void main(String[] argv){ 3. String str2 = Double.toString(12); 4. String str1 = Double.toHexString(12); 5. System.out.println(str1+str2); 6. } 7. } What will happen when John attempts to compile and execute the code?

  1. It will not compile because the Double class does not contain the toHexString() method.
  2. It will compile and execute successfully and will display 8p312 as the output.
  3. It will compile and execute successfully and will display 0x1.8p312.0 as the output.
  4. It will not compile because the Double class does not contain the toString() method.

Question 15

Mark works as a Programmer for InfoTech Inc. He develops a Website that uses HTML and processes HTML validation. Which of the following are the advantages of the HTML application? Each correct answer represents a complete solution. Choose all that apply.

  1. It provides password protection for a Web page or directory
  2. It can be accessed by more visitors.
  3. It provides faster loading.
  4. It is easier to update and maintain the site.
  5. It protects the source or images of a HTML Web page.
  6. It puts less load on the server.