aspose file tools*
The moose likes Mock Exam Errata and the fly likes Please Explain Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Please Explain" Watch "Please Explain" New topic

Please Explain

Vineet Sharma
Ranch Hand

Joined: Dec 30, 2000
Posts: 51
Please explain the following:
1) try{
FileInputStream dis = new FileInputStream("Hello.txt"); //Are we not creating a file here?
}catch(FileNotFoundException fne) {
System.out.println("No Such File Found");
return -1
catch(IOException ioe){
System.out.println("Doing Finally");
return 0;
Ans is :
No Such File Found, Doing Finally , -1
1. I Think We Are Creating File At The Commented Line.
2. Why is the order of output not : No Such File Found, -1, Doing Finally.
(-1 is in returned first)
2). String s1 = new String("Hello");
String s2 = new String("there");
String s3 = new String();
s3 = s1+s2;

The above compiles fine and outputs Hello there. Can We Concatenate two STRING OBJECTS ?

3) Which is correct:
Vector v = new Vector();
Vector v = new Vector();

4) DataInputStream d = new DataInputSream(;

DataInputStream takes a parameter of low lenvel stream, but is an example of high level stream, then why is the above correct ?

Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
Hi Vineet,
-->1) I think you only create files with FileOutputStream.
The constructor throws the exception sun api )(watch constructor details).
The finally is called BEFORE execution is handled back to the caller (the return -1). There is nice sample code in: Mughal, Rasmussen Source CodeName of file:
2)This is normal string concatenation. The binary operator + is internally overloaded for Strings. You cannot Do operator overloading for yourself in Java.
You can even do things like:
String str1 = "its now ";
int1 = 3;
String str2 = " o clock in Germany";
String str3 = str1 + int1 + str2;
---> String3: "its now 3 o clock in Germany"
int1 as operand is implictly converted to String.

sun.api.documentation about: void vector.addElement(Object o):

Adds the specified component to the end of this vector, increasing its size by one. The capacity of this vector is increased if its size becomes greater than its capacity.
This method is identical in functionality to the[boolean] add(Object) method (which is part of the List interface).
Maybee that add(Object) is introduced later in the ListInterface than Vector class was designed (just a guess).
4) Java api-documentation states as only Constructor of DataInputStream:
Constructor Summary
DataInputStream(InputStream in)
Creates a FilterInputStream and saves its argument, the input stream in, for later use.

Vineet Sharma
Ranch Hand

Joined: Dec 30, 2000
Posts: 51
Thank You Axel ! Your concepts seem to be crystal clear!
I agree. Here's the link:
subject: Please Explain