Q1. Given the existing destination file, a source file only 1000 bytes long, and the code fragment:
What is the result?
A. Overrides the content of the destination file with the source file content
B. Appends the content of the source file to the destination file after a new line
C. Appends the content of the source file to the destination file without a break in the flow
D. Throws a runtime exception at line***
Answer: A
Explanation:
The whole of the FileInputStream will be read (see ** below).
The content of the FileInputStream will overwrite the destination file (see *** below).
*A FileInputStream obtains input bytes from a file in a file system.
What files are available depends on the host environment.
FileInputStream is meant for reading streams of raw bytes such as image data.
For reading streams of characters, consider using FileReader.
**FileInputStream.read(byte[] b)
Reads up to b.length bytes of data from this input stream into an array of bytes.
Parameters:
b - the buffer into which the data is read.
Returns:the total number of bytes read into the buffer, or -1 if there is no more data
because the end of the file has beenreached.
***FileOutputStream
You can construct a FileOutputStream object by passing a string containing a path name or
a File object.
You can also specify whether you want to append the output to an existing file.
public FileOutputStream (String path)
public FileOutputStream (String path, boolean append)
public FileOutputStream (File file)
public FileOutputStream (File file, boolean append)
With the first and third constructors, if a file by the specified name already exists, the file
will be overwritten.
To append to an existing file, pass true to the second or fourth constructor.
Reference:Class FileInputStream
Reference:Class FileOutputStream
Q2. Given:
What is the result?
A. Pastel Enamel Fresco Gouache B. Pastel *Enamel Fresco *Gouache
C. Pastel Enamel Fresco Gouache
D. Pastel Enamel, Fresco Gouache
Answer: B
Explanation:
regex explanation:
, = ,
\ = masks the following
\s = A whitespace character: [ \t \n \x0B \f \r ]
* = Greedy Quantifier: zero or more times Delimiter: comma + zero or more whitespace characters
Q3. Give: Which is correct?
A. Employee takes advantage of composition.
B. Employee "has-an" Email.
C. Employee "is-a" LetterPrinter.
D. Employee has low cohesion.
Answer: D
Explanation:
The relationship between Employee and e-mail is poorly implemented here.
There is low cohesion.
Note:
Low cohesion is associated with undesirable traits such as being difficult to maintain,
difficult to test, difficult toreuse, and even difficult to understand.
Cohesion is decreased if:
The functionalities embedded in a class, accessed through its methods, have little in
common. Methods carryout many varied activities, often using coarsely-grained or
unrelated sets of data. Disadvantages of lowcohesion (or"weak cohesion") are:
Increased difficulty in understanding modules.
Increased difficulty in maintaining a system, because logical changes in the domain affect
multiple modules,and because changes in one module require changes in related modules.
Increased difficulty in reusing amodule because most applications won't need the random
set of operations provided by a module.Reference:Cohesion (computer science)
Q4. Given:
Which three are true?
A. BasicCar uses composition.
B. SuperCar uses composition.
C. BasicCar is-a Car.
D. SuperCar is-a Car.
E. SuperCar takes advantage of polymorphism
F. BasicCar has-a Car
Answer: B,C,E
Explanation:
B: The relationship modeled by composition is often referred to as the "has-a" relationship. Here SuperCarhas-a Car.
C:The relationship modeled by inheritance is often referred to as the "is-a" relationship. Modeling an is-arelationship is called inheritance because the subclass inherits the interface and, by default, theimplementation of the superclass. Inheritance of interface guarantees that a subclass can accept all the samemessages as its superclass. A subclass object can, in fact, be used anywhere a superclass object is called for.E:The polymorphic method call allows one type to express its distinction from another, similar type, as long asthey're both derived from the same base type. This distinction is expressed through differences in behavior ofthe methods that you can call through the base class.
Q5. Given these facts about Java classes in an application:
-
Class X is-a Class SuperX.
-
Class SuperX has-a public reference to a Class Z.
-
Class Y invokes public methods in Class Util.
-
Class X uses public variables in Class Util.
Which three statements are true?
A. Class X has-a Class Z.
B. Class Util has weak encapsulation.
C. Class Y demonstrates high cohesion.
D. Class X is loosely coupled to Class Util.
E. Class SuperX's level of cohesion CANNOT be determined
Answer: B,D,E
Explanation:
B: Has class Util has both public methods and variables, it is an example of weak
encapsulation.
Note:Inheritance is also sometimes said to provide "weak encapsulation," because if you
have code thatdirectly uses a subclass, such as Apple, that code can be broken by
changes to a superclass, such as Fruit.
One of the ways to look at inheritance is that it allows subclass code to reuse superclass
code. For example, if
Apple doesn't override a method defined in its superclass
Fruit, Apple is in a sense reusing Fruit's implementation of the method. But Apple only
"weakly encapsulates"the Fruit code it is reusing, because changes to Fruit's interface can
break code that directly uses Apple.
D:
Note:Tight coupling is when a group of classes are highly dependent on one another.
This scenario arises when a class assumes too many responsibilities, or when one concern
is spread overmany classes rather than having its own class.
Loose coupling is achieved by means of a design that promotes single-responsibility and
separation ofconcerns.
A loosely-coupled class can be consumed and tested independently of other (concrete)
classes.
Interfaces are a powerful tool to use for decoupling. Classes can communicate through
interfaces rather thanother concrete classes, and any class can be on the other end of that
communication simply by implementingthe interface.
E: Not enough information regarding SuperX' to determine the level of cohesion.
Q6. Which three are true?
A. A setAutoCommit (False) method invocation starts a transaction context.
B. An instance of Savepoint represents a point in the current transaction context.
C. A rollback () method invocation rolls a transaction back to the last savepoint.
D. A rollback () method invocation releases any database locks currently held by this connection object.
E. After calling rollback (mysavepoint), you must close the savepoint object by calling mySavepoint.close() .
Answer: A,B,C
Explanation:
A:The way to allow two or more statements to be grouped into a transaction is to disable the auto-commitmode. After the auto-commit mode is disabled, no SQL statements are committed until you call the methodcommit explicitly. All statements executed after the previous call to the method commit are included in thecurrent transaction and committed together as a unit. Note:When a connection is created, it is in auto-commit mode. This means that each individual SQL statementis treated as a transaction and is automatically committed right after it is executed. (To be more precise, thedefault is for a SQL statement to be committed when it is completed, not when it is executed. A statement iscompleted when all of its result sets and update counts have been retrieved. In almost all cases, however, astatement is completed, and therefore committed, right after it is executed.)
B:The method Connection.setSavepoint, sets a Savepoint object within the current transaction. The Connection.rollback method is overloaded to take a Savepoint argument. When a transaction is rolled back toa savepoint all changes made after that savepoint are undone.
C: calling the method rollback terminates a transaction and returns any values that were modified to theirprevious values. If you are trying to execute one or more statements in a transaction and get a SQLException, call the method rollback to end the transaction and start the transaction all over again.
Q7. Give:
What is the result?
A. There are 27 sports cars and 5 trucks
B. There are 27 convertibles and 5 trucks
C. There are 9 sports cars and 5 trucks
D. There are 9 convertibles and 5 trucks
E. IllegalFormatConversionException is thrown at runtime
Answer: C
Explanation:
Strings are immutable, therefore no change at line: svar.replace(svar,"convertibles");
Format String Syntax:
%[argument_index$][flags][width][.precision]conversion
The optional argument_index is a decimal integer indicating the position of the argument in
the argument list.
The first argument is referenced by "1$", the second by "2$", etc.
The optional flags is a set of characters that modify the output format. The set of valid flags
depends on theconversion.
's', 'S' general
'd' integral The result is formatted as a decimal / integer
Q8. Which concept allows generic collections to interoperate with java code that defines collections that use rawtypes?
A. bytecode manipulation
B. casting
C. autoboxing
D. auto-unboxing
E. type erasure
Answer: E
Explanation:
The type erasure of its leftmost bound, or type Object if no bound was specified. Examples: type parameters type erasure List<String> List Map.Entry<String,Long> Map.Entry <T extends Cloneable & Comparable<T>> Cloneable <T extends Object & Comparable<T>> Object
<T> T[] toArray(T[] a) Object[] toArray(Object[] a)
The type erasure process can be imagined as a translation from generic Java source code
back into regularJava code. In reality the compiler is more efficient and translates directly to
Java byte code. But the byte codecreated is equivalent to the non-generic Java code.
Q9. Given:
What two changes, made independently, will enable the code to compile?
A. Change the signature of Account to: public class Account.
B. Change the signature of CheckingAccount to: public abstract CheckingAccount
C. Implement private methods for deposit and withdraw in CheckingAccount.
D. Implement public methods for deposit and withdraw in CheckingAccount.
E. Change Signature of checkingAccount to: CheckingAccount implements Account.
F. Make Account an interface.
Answer: B,D
Explanation:
Compiler say:
-
Der Typ CheckingAccount muss die übernommene abstrakte Methode Account.deposit(double) implementieren
-
Der Typ CheckingAccount muss die übernommene abstrakte Methode Account.withdraw(double) implementieren ODER Typ CheckingAccount als abstract definieren
Q10. Given the following files in doc directory: -Index.htm
-Service.html
-Logo.gif
-Title.jpg
And the code fragment:
What is the result, if doc is present in the current directory?
A. No output is produced.
B. index.htm
C. index.htm userguide.txt logo.gif
D. index.htm service.html userguide.txt logo.gif
Answer: A
Explanation:
The Glob search expression is defined through "glob:*.htm, html, xml" The correct answer is A The glob is trying to match all the string. The correct way is
glob:*.{htm,html,xml}
and then would be found:
Index.htm
Service.html