Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Interface [answer] describes methods for writing primitive types to an output

ID: 3740499 • Letter: 1

Question

1. Interface [answer] describes methods for writing primitive types to an output stream.

2. Adding the services of one stream to another is known as ________.

a. Adding

b. Wrapping

c. Sequencing

d. chaining

3.

Which expression(s) are an exact match to the regular expression p*pkk*kk*?

Choose Yes or No for each string of characters

ppp ( y or n)

kkkkk (y or n)

pk (y or n)

pkk (y or n)

ppkk ( y or n)

4. Assume the following statement:

String question = "What is the sound of one hand clapping?";

Executing the statements below with result in which values for i and j?

String i = question.substring (8);
String j = question.substring(26);

a. i=”sound of one hand clapping?” and j=”hand clapping?”

b. i=”the sound of one hand clapping?” and j=”and clapping?”

c. i=”the sound of one hand clapping” and j=”hand clapping”

d. i=”he sound of one hand clapping?” and j=”nd clapping?”

5. Assume that a character named chArray has been initialized with 20 characters. Which statement is a valid call to a String constructor?

a. Byte arrays

b. new String = charArray[0…20];

c. String s = charArray[5, 10];

d. String s = new String (charArray, 5, 10);

6. What happens if a newly specified length of a StringBuilder object is greater than the number of characters currently in the object?

a. A new StringBuilder object is created with the specified length.

b. Null characters are added until the specified length is reached

c. An out of bounds exception is thrown

d. The length of the StringBuilder object remains as is

7. The variable name stores names as last name and first name separated by a comma. For example:  Jones, Sharon

Complete the code to store the first name and last name in separate variables and then print a line with first name and last name separated by a space. Assume all variables are declared and initialized.

commaPosition = name.indexOf();

lastName = name.substring(, );
firstName = name.substring(commaPosition + , name.length());

System.out.println();

8. Assume three String variables named student1, student2, and student3 that have been initialized with students’ last names. A Stringvariable first has also been declared.

Complete the code fragment that will result in first containing the student last name that is first alphabetically.

first = student1;

if(student2.compareTo(first) > 0)
{
  
}
if(student3.compareTo( > 0)
{
  
}

9.

Suppose you have declared a String object “Happy”. Sadly, you know that you’ll never be able to _____ “Happy” because it is ______.

a. Clone; dynamic

b. Instantiate; inherited

c. Modify; immutable

d. Display; private

10. What is one valid way to declare and initialize a StringBuilder object buf with the value “Spring has Sprung!”

str = “Spring has sprung!”;

buf = new StringBuilder(str.copy);

buf = new StringBuilder();

str = “Spring has sprung!”;

buf = new StringBuilder(str 32);

buf = new StringBuilder(“Spring has sprung!”);

11. What will be the value of the variable display after the code below executes?

String basics = "abc_123";
String display = "";

for (int i = basics.length() - 1; i >= 0; i--)
display += basics.charAt(i) + " ";

a. abc_123

b. abc

c. 321_cba

d. 321_

12. A(n) ________ path starts from the directory in which the application began executing.

a. Parallel

b. Absolute

c. Comparative

d. Relative

13. Class ________ provides static methods for common file and directory manipulations, including methods for copying files; creating and deleting files and directories; getting information about files and directories; reading the contents of files; getting objects that allow you to manipulate the contents of files and directories; and more.

a. FilesAndDirectories

b. File

c. FileAndDirectory

d. Files

14. Assume that symbol is a char variable has been declared and already given a value. Write an expression whose value is true if and only if symbol is alphanumeric, that is either a letter or a decimal digit.

(symbol  choose answer<<===>>=&&|| 'A'  choose answer<<===>>=&&|| symbol  choose answer<<===>>=&&|| 'Z')  choose answer<<===>>=&&|| (symbol  choose answer<<===>>=&&|| 'a'  choose answer<<===>>=&&|| symbol  choose answer<<===>>=&&|| 'z') || (symbol  choose answer<<===>>=&&||'0'  choose answer<<===>>=&&|| symbol  choose answer<<===>>=&&|| '9')

15. Assume the following declaration:

String major = “cybersecurity”;

The statements:

Int i = major.indexOf(“y”);

Int j = major.lastIndexOf(“r”);

Will result in which values for i and j?

a. i=1 and j=9

b. i=2 and j=16

c. i=4 and j=16

d. i=2 and j=10

16. The fundamental building blocks of Java source programs are ______.

a. integers

b. characters

c. strings

d. objects

17. StringBuilder objects should be used in place of String objects when the _____.

a. Date values are constants

b. String size may grow

c. Memory is an issue

d. Data is static

18. The ________ abstract classes are Unicode character-based streams.

a. Unicode and UnicodeWrite

b. CharArrayReader and CharArrayWriter

c. BufferedReader and BufferedWriter

d. Reader and Writer

19. Which of the following statements is false?

a. The static method get of class Paths converts a String representing a file's or directory's location into a Path object.

b. Path objects open files and provide file-processing capabilities

c. Class Path is used to get a Path object representing a file or directory location

d. A Path represents the location of a file or directory

20. Which of the following statements is false?

a. Character-based input and output can be performed with classes Scanner and Formatter

b. Every file or directory on a disk drive has he same root directory in its path

c. A relative path contains all the directories, starting with the root directory, that lead to a specific file or directory

d. A DirectoryStream enables a program to iterate through the contents of a directory

21. What interface must a class implement to indicate that objects of the class can be output and input as a stream of bytes?

a. Deserialization

b. Synchronize

c. Serializable

d. ObjectOutput

Explanation / Answer

2)b)Wrapping

3)Given Regular expression produces output

zero (or) more p's-'p'-'k'-zero or more 'k'-'k'-zero or more 'k's

ppp--in this string 'k's are missing so answer NO

kkkkk-in this string 'p' is missing No

pk--in this string also one 'k' is missing

pkk-this string exact match of given regular expression Yes

ppkk-this string exact match of given regular expression

4)substring(start,end) returns string from starting position to end position-1

here we are not providing end index so it returns whole string from given starting position

so,answer is -B

i=the sound of one hand clapping?

j=and clapping?

5) d)String constructor accepts either accepts a string

(or) accepts chararray,offset,length of the string so that from specified offset to length the string is passed to constructor

6) d) The length of the StringBuilder object remains as it is with specifide capacity

7) System.out.println(firstName+" "+lastName)

8) first=student1;

if(student2.compareTo(first)>0)

{

//if student2 greater of student1 no need of checking because student1 is in alphabetically order

}

if(student3.compareTo(first)>0)

{

}

9) C) Modify;immutable

10) buf=new StringBuilder("Spring has sprung!");

11) Given code is for string reversal.so

answer is "321_cba"

12) d)Relative

13) b)File

14) if(Character.isDigit(symbol) || Character.isLetter(symbol))

{

return true;

}

15)i=1 and j=9 becasue index starts from '0'

and also indexOf() returns first occurence of given character in the string

16)d)objects

17)b)String size may grow

18)d) Reader and Writer

21)d)ObjectOutpt