Studydroid is shutting down on January 1st, 2019



keywords:
Bookmark and Share



Front Back
When embedding argument-specfic formatting data in a string what character must that data begin with?
% (percent sign)
What is the structure of a format string?
%[arg_index$][flags][width][.precision]conversion char
Is the argument index in a printf() formatting string zero based
Nope.
What are the possible flags that can be put in a formatting string?
- left justify + include sign (+ or -) 0 padd this arg with zeros use locale specific separators ( enclose neg #s in paras
What is the width declartion in a formatting string?
The minimum number of charaters to print for the argument
What is the precision declartion in a formatting string?
When using floats indicate number of digits to print after decimal point
What are the conversion character codes in a formatting string?
b boolean c char s string (NOT short) d integer (NOT decimal) f float
System.out.format(""%d"" 12.3); Compiles?
Yes but you get a runtime error! 12.3 is more specific than integer (d)
What is notable about an transient object ivar that has been instantiated to some object by it's constructor then serialized then deserialized?
It's set to null... UNLESS 1) A custom writeObject(ObjectOutputStream os) and custom readObject(ObjectInputStream) have been added to the class and recreate the object or.... 2) The ivar is part of an ancestor of the actual serialized object at which point it will get recreated when the ancestor's constructor is called.
Class A implements Serializable {} Class B extends A{} Class C extends B implements Serializable {} When serializing an object of Class C will the ivars of class A be restored via serializiation or will they be initialized by the A() constructor?
They'll be initialized by the constructor. The key point is that at the very first ancestor that is NOT serializable all ancestors above it will have their constructors called - regardless of whether they're marked Serializable or not. NOTE: Think about the constructor chaining that occurs when an object is instantiated.
Are static variables serialized?
Never.
What characters does the \w metacharacter represent?
\w stands for Word characters. They include: letters numbers underscore
What class is the split() method associated with? What does split() return?
The String class. It returns an array of Strings. The argument to the string() method is a regex expression that serves to define the delimiter. The tokens are then put in the array.
What is the difference between a token and a delimiter?
Delimiters are seperators and the stuff between the separators are the tokens.
BufferedWriter bf = new BufferedWriter(""temp.txt""); Compiles?
No. A BufferedWriter is a decorator class that can only be instantiated by wrapping another Writer object. It cannot take a string and turn that directly into a BufferredWriter. Here is what would work: try { FileWriter fw = new FileWriter(""temp.txt""); BufferedWriter bf = new BufferedWriter(fw); } catch (IOException e) {}
Currency c = new Currency(); Compiles? Runs?
It doesn't compile. Currency does not have a public constructor. Currency objects are created using static mehtod (getInstance). Currency is a singleton.
NumberFormat nf = NumberFormat.getCurrencyInstance(); nf.parse(""1234""); Compiles? What kind of object does parse function produce?
It does not compile. The parse method can throw a CHECKED exception ParseException and needs to be wrapped accordingly. If wrapped so and the string is a valid number then the parse function outputs an object of class Number (NOT class String).
System.out.format(""%b"" 123); What prints?
true the boolean conversion char ""b"" returns true for any non null or non-boolean argument.
System.out.format(""%f"" 123); What prints?
Runtime error. int literals are not automatically promoted to floats.
String a = new String(""hello""); String b = a.toString(); System.out.println(a == b); What prints?
True. toString() called on a String object returns the calling object.
|< < Previous x of y cards