sonia jaswal

Ranch Hand
+ Follow
since Jun 01, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by sonia jaswal

That's because the String Concatenation works in such a way. Once it encounters the first operand as String, then the rest all would be treated as String only.

In your example,







Line 1 and 2 has a string content as one of the operands in the first concatenation. Remember, "" is a string and the method foo() returns a String content. That's why you get the output as 72 for first [7,2 being treated as String only] and "foo425" in next output. Same steps as explained for the 1st output.

In Line 3, the values of x and y are treated as they are (here of type long) and their sum 86 is concatenated with the output of method foo() which is a string "foo". That's why the output is "86foo" and NOT "4244foo".

[ January 29, 2008: Message edited by: sonia jaswal ]

[ January 29, 2008: Message edited by: sonia jaswal ]
[ January 29, 2008: Message edited by: sonia jaswal ]
hey thanks.....
17 years ago
H... where can i post questions related to J2ME...
thanks..
17 years ago
Thanks for the reply....
i will try and let you know... thanks...
17 years ago
code:


class Dog implements Serializable {
private int dogSize;
public Dog(int size)
{
dogSize = size;
}
}
class Collar
{
private int collarSize;

public Collar(int size) { collarSize = size; }
public int getCollarSize() { return collarSize; }
}
public class SerializeDog {
public static void main(String [] args) {
Dog d = new Dog(5);}




// here the Collar class is non serializable, and its private instance variables are not being used by the serializable dog object... and there is no inheritance also and nothing has been declared transient... so after de-serialization the Collar class variables will be reinitialized to their default values.... is this right.. or will there be a compilation error...(as the non serializable class has no link with the serialized object dog and there in no inheritance also)
There is no HAS-A relationship between dog and collar... nor there is a IS-A relationship...
Will it still give a compilation error... or will it run...???
17 years ago
hi..
if it is a javabean property then you can use "get" or "is" as prefix accordingly for non boolean and boolean types.... and if it is javabean listener then "add" can be used as a prefix but the method must end in a 'listener'...
hope this clears your doubt...
yes it not the part of the file i am printing....
This code is from K&B pg 440... i have understood the program but i have not understood the output given in the program...
code:

Assume that we already have a subdirectory called existingDir in which resides an existing file existingDirFile.txt, which contains several lines of text. When you run the following code,


File existingDir = new File("existingDir"); // assign a dir
System.out.println(existingDir.isDirectory());

File existingDirFile = new File(
existingDir, "existingDirFile.txt"); // assign a file
System.out.println (existingDirFile.isFile());

FileReader fr = new FileReader(existingDirFile};
BufferedReader br = new BufferedReader(fr); // make a Reader

String s;
while( (s = br.readLine()) != null) // read data
System.out.printIn(s);

br.close();

the following output will be generated:

true
true
existing sub-dir data
line 2 of text
line 3 of text

// here there is no print command for "existing sub-dir data"... then what is it... is it an explanation??? i just want to confirm....

thanks....
can somebody please tell me whether writer is a class or an object... in K&B pg 436, the tables says the some i/o classes extend from writer.. which means writer is a class.... but on pg 437... the 2nd para says that writer is an object and not a class.. so why is it an object and not a class...

thanks...
Code:

import java.io.*;

class Writer2 {
public static void main(String [] args) {
char[] in = new char[50]; // to store input
int size = 0;
try {
File file = new File( // just an object
"fileWrite2.txt");
FileWriter fw =
new FileWriter(file); // create an actual file
// & a FileWriter obj
fw.write("howdy\nfolks\n"); // write characters to
// the file
fw.flush(); // flush before closing
fw.close(); // close file when done

FileReader fr = =
new FileReader(file); // create a FileReader
// object
size = fr.read(in); // read the whole file!
System.out.print(size + " "); // how many bytes read
for(char c : in) // print the array
System.out.print(c);
fr.close(); // again, always close }
} catch(IOException e) { }
}
}

which produces the output:

12 howdy
folks

//
here, the following para is a limitation for the previous code.... which i did not understand... can someboidy please explain it to me...
"When we were reading data back in, we put it into a character array. It being an array and all, we had to declare its size beforehand, so we'd have been in trouble if we hadn't made it big enough! We could have read the data in one character at a time, looking for the end of file after each read(), but that's pretty painful too."

Apart from this... please tell me what does reading the file's contents back into memory mean....

thank you....
17 years ago
Code:

import java.io.*;

class Writer2 {
public static void main(String [] args) {
char[] in = new char[50]; // to store input
int size = 0;
try {
File file = new File( // just an object
"fileWrite2.txt");
FileWriter fw =
new FileWriter(file); // create an actual file
// & a FileWriter obj
fw.write("howdy\nfolks\n"); // write characters to
// the file
fw.flush(); // flush before closing
fw.close(); // close file when done

FileReader fr = =
new FileReader(file); // create a FileReader
// object
size = fr.read(in); // read the whole file!
System.out.print(size + " "); // how many bytes read
for(char c : in) // print the array
System.out.print(c);
fr.close(); // again, always close }
} catch(IOException e) { }
}
}

which produces the output:

12 howdy
folks

//
here, the following para is a limitation for the previous code.... which i did not understand... can someboidy please explain it to me...
"When we were reading data back in, we put it into a character array. It being an array and all, we had to declare its size beforehand, so we'd have been in trouble if we hadn't made it big enough! We could have read the data in one character at a time, looking for the end of file after each read(), but that's pretty painful too."

Apart from this... please tell me what does reading the file's contents back into memory mean....

thank you....
can anybody please tell me the syntax for setting the classpath?
17 years ago
that is stacktrace will be printed!!! fine i just wanted to confirm..... thank you...
hi raghvan..
in case of a checked exception, if none of the method including the main(), handle the exception, instead they only throw the exception, then what will be the result???
hey thank you soooo much.... i have understood well now... thanks a lot....