API Contents QuizS2C Home « API Contents Quiz

The questions in this fifth quiz on Java5 are on the topics covered in the Java5 - API Contents section of the site. The table below lists the lessons, a description of the lesson content and the the quiz question number range.

Lesson Summary

Click on a lesson in the table to go to that lesson for a refresher on the topics for that lesson.

API Contents Lessons Description Question Range
Lesson 1 - The String ClassWe begin our studies of of the Java5 API by looking at the predefined String object and some of the methods available for use with this class.1 - 7
Lesson 2 - The StringBuilder ClassIn this lesson we learn about the predefined StringBuilder object and some of the methods available for use with this class.8 - 12
Lesson 3 - PackagesWe take a closer look at how Java stores predefined classes into namespaces, which Java calls packages, and how we can import these packages into our programs.13 - 18
Lesson 4 - Java I/O OverviewIt is now time to look at Java I/O in much more detail and we start three lessons on the subject with an overview of the various streams available in Java.19 - 24
Lesson 5 - Byte Stream ClassesIn this lesson we take a closer look at some of the byte stream classes that are available in Java and how we use them.25 - 30
Lesson 6 - Character Stream ClassesIn our final lesson on Java I/O we take a closer look at some of the Character stream classes that are available in Java and how we use them.31 - 36
Lesson 7 - Dates, Numbers & CurrenciesIn this lesson we look at the Date, Calendar, Locale, DateFormat and NumberFormat classes that allow us to create and manipulate dates, times, numbers and currencies for different regions of the world.37 - 42
Lesson 8 - Regular ExpressionsFor this lesson we look at regular expressions and how we can use regular expression patterns for matching data.43 - 48
Lesson 9 - Formatting & TokenizingIn our final lesson of the API Contents section we look at formatting and tokenizing our data.49 - 55

Java5 Quiz

The quiz below tests your knowledge of the material learnt in the Java5 - API Contents section of the site.

Question 1 : What do we mean when we say a String object is immutable.
- Once a <code>String</code> object has been constructed its contents can never be changed, so it is in essence a constant.
Question 2 : What is the special area of memory within The Heap where string literal objects are held.
- The special area of memory within <em>The Heap</em> where string literal objects are heldis called the <em>string constant pool</em>.
Question 3 : Assuming no objects exist in the pool how many objects would be created from the following statement snippet?

String str1 = new String("123");
- Two objects would be created. One on <em>The Heap</em> and one in the <em>string constant pool</em>.
Question 4 : Assuming no objects exist in the pool how many objects would be created from the following statement snippets?

String str1 = new String("123");
String str2 = "123";
String str3 = "123";
- Two objects would be created. One on <em>The Heap</em> and one in the <em>string constant pool</em>. Reference variables <code>str2</code> and <code>str3</code> will just be pointed to the object in the <em>string constant pool</em> created with the first statement.
Question 5 : The equals() method of the String class only returns true when two references refer to the same object?
- The <code>equals()</code> method of the <code>String</code> class returns <code>true</code> if the invoking string has the the same character sequence as the argument string.
Question 6 : Which method of the String class is useful as the condition in loop statements?
- The <code>length()</code> method is useful as the condition in loop statements as it will always equal the number of characters in the string.
Question 7 : We need to override the toString() method of the String class to get meaningful output?
- The <code>toString()</code> method of the <code>String</code> class already <em>overrides</em> the <code>Object toString()</code> method.
Question 8 : Which string utility class has thread-safe methods?
- The <code>StringBuffer</code> utility class has thread-safe methods.
Question 9 : What is the main advantage of using the StringBuilder class instead of the String class.
- When doing a lot of string manipulation using the <code>StringBuilder</code> class is a lot more efficient than using the <code>String</code> class.
Question 10 : What method do we use to concatenate strings together in the StringBuilder class?
- We use the <code>append()</code> method to concatenate strings together in the <code>StringBuilder</code> class.
Question 11 : The String and StringBuilder replace() methods are the same apart from immutability?
- The <code>replace()</code> methods of the <code>String</code> and <code>StringBuilder</code> methods work in different ways and have different parameter lists aside from the immutability difference.
Question 12 : The String and StringBuilder substring() methods are the same apart from immutability?
- The <code>substring()</code> methods of the <code>String</code> and <code>StringBuilder</code> methods both return an immutable <code>String</code> object and so regardless of input do exactly the same thing.
Question 13 : What are libraries of related classes known as in Java?
- Libraries of related classes are known as <em>packages</em> in Java.
Question 14 : What does the protected access modifier allow access to?
- The <code>protected</code> <em>access modifier</em> allowa access to subclasses outside the package.
Question 15 : Every class written in Java exists within a package?
- Every class written in Java exists within a package. When no package statements are present within a class, then the default package is used which has no name.
Question 16 : How do we use unqualified classes that are in packages?
- We use unqualified classes that are in packages by importing them using the <code>import</code> keyword.
Question 17 : How can we use unqualified static members of a package within our classes?
- We use unqualified static members of a package within our classes by using the <code>import static</code> keywords.
Question 18 : Where do package statements appear in a source file?
- <em>package</em> statements appear at the start of a source file.
Question 19 : What are the two types of I/O streams supported by Java?
- Java supports byte and character streams.
Question 20 : What is the abstract superclass of character input streams called?
- The <em>abstract superclass</em> of character input streams is called <code>Reader</code>.
Question 21 : We can check that a File object has a file present on a hard disk and if not create that file?
- We can use the <code>exists()</code> method to check if a file phsically exists and if it doesn't we can create the file using the <code>createNewFile()</code> method.
Question 22 : What package(s) contain the byte and characters streams?
- The byte and characters streams are all held within the <code>Java.io</code> package.
Question 23 : What is the abstract superclass of character output streams called?
- The <em>abstract superclass</em> of character output streams is called <code>Writer</code>.
Question 24 : What does a File object represent?
- A <code>File</code> object represents the name and path of a physical file or directory.
Question 25 : How can we write primitive data types to a file?
- We write primitive data types to a file using the <code>DataOutputStream</code>.
Question 26 : What is the abstract superclass of byte input streams called?
- The <em>abstract superclass</em> of byte input streams is called <code>InputStream</code>.
Question 27 : How can we persist object state?
- We can persist <em>object state</em> using the <code>ObjectOutputStream</code> class.
Question 28 : Which class implements all the methods of InputStream with versions that pass all requests to the contained input stream?
- The <code>FilterinputStream</code> implements all the methods of <code>InputStream</code> with versions that pass all requests to the contained input stream.
Question 29 : We can use the read() method of which class to read character input from the keyboard?
- We can use the <code>InputStream</code> class via <code>System.in.read()</code>.
Question 30 : Can we use more than one stream when outputting data to storage?
- We can use more than one stream when outputting data to storage; in fact it's often the case that we want to 'mix and match' our streams.
Question 31 : Character streams operate directly on ASCII characters ?
- Character streams operate on <em>Unicode</em> characters which incorporate <em>ASCII</em> characters.
Question 32 : What is the abstract superclass of character output streams called?
- The <em>abstract superclass</em> of character output streams is called <code>Writer</code>.
Question 33 : Which character output stream allows us to write output to the console?
- The <code>PrintWriter</code> class allows us to write output to the console.
Question 34 : We create a Writer object to output character streams to?
- The <code>Writer</code> object is the <em>abstract superclass</em> of character output streams so we can't instantiate this class.
Question 35 : What is the abstract superclass of character input streams called?
- The <em>abstract superclass</em> of character input streams is called <code>Reader</code>.
Question 36 : Why would we use a stream that buffers input or output?
- We would use a stream that buffers input or output for efficiency.
Question 37 : What is a java.util.Date object meant to represent?
- A <code>java.util.Date</code> object is meant to represent a specific instant in time.
Question 38 : We can convert a Date object to a Calendar and vice versa?
- Yes which is very handy because we need a <code>Date</code> object for formatting dates when using the <code>DateFormat</code> class.
Question 39 : What method do we use to convert Date objects to Calendar objects?
- We use the <code>setTime()</code> method which allows us to convert <code>Date</code> objects to <code>Calendar</code> objects.
Question 40 : What information does the Locale class contain?
- The <code>Locale</code> class contains information about countries, such as name and ISO codes and which language is spoken in that country.
Question 41 : SHORT, MEDIUM , LONG, are three of the styles options you can pass to a DateFormat static factory method. What is the fourth?
- The fourth option we can use is <code>FULL</code> which is also the most descriptive style we can pass to a <code>DateFormat</code> static factory method.
Question 42 : The NumberFormat class allows us to format numbers and?
- The <code>NumberFormat</code> class allows us to format numbers and currencies.
Question 43 : Which method of the Matcher class allows us to look for subsequences of a pattern?
- The <code>find()</code> method of the <code>Matcher</code> class allows us to look for subsequences of a pattern. The <code>lookingAt</code> method tries to match the prefix of the <em>region</em> and the <code>matches</code> method tries to match the full <em>region</em>.
Question 44 : Which metacharacter do we use for whitespaces?
- We use the <code>\s</code> <em>metacharacter</em> for whitespaces. Think of <code>\s</code> for spaces and <code>\w</code> for word characters to remember the difference.
Question 45 : Which convenience method of the Pattern class allows us to compile and match a pattern to a character sequence in one statement?
- The <code>matches()</code> method of the <code>Pattern</code> class allows us to compile and match a pattern to a character sequence in one statement. The other two methods reside in the <code>Matcher</code> class.
Question 46 : Which symbol do we use to represent any character in a regex expression?
- We use the <code>.</code> (dot) symbol to represent any character in a <em>regex</em> expression.
Question 47 : What do we enclose character sets in?
- we enclose character sets in <code>[]</code> (brackets).
Question 48 : Which quantifier do we use to get zero or one occurrences?
- We would use the <code>?</code> <em>quantifier</em> to get zero or one occurrences.
Question 49 : A format string may contain fixed text as well as one or more what?
- A format string may contain fixed text as well as one or more format specifiers.
Question 50 : Which letter do we use to prefix date/time conversions?
- We use the letter <code>t</code> to prefix date/time conversions.
Question 51 : We can format output for specific locales?
- All the formatting methods allow us to format output for specific locales.
Question 52 : Which static method of the String class do we use for formatting?
- We use the <code>format()</code> method of the <code>String</code> class for formatting.
Question 53 : What would be output from the following code snippet?

import java.io.PrintStream;
class TestStringf {
public static void main(String[] args) { int a = 1234;
System.out.printf("%1$d", a);
}
}
- The output is <code>1234</code> as we didn't use a <code>,</code> flag to separate thousands ie. <code>%1$,d</code>
Question 54 : Objects of the java.util.Scanner class use a delimiter to break input into what?
- Objects of the <code>java.util.Scanner</code> class use a delimiter to break input into tokens.
Question 55 : What is used as the delimiter to the split() method?
- We use a <code>regular expression</code> as the delimiter to the <code>split()</code> method.
Quiz Progress Bar Please select an answer

What's Next?

The next quiz is all about concurrency.

go to home page Homepage go to top of page Top