kirba devi

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

Recent posts by kirba devi

Also for each time when i run the file it is showing different numbers..

ftg34545.tmp

Regards
Kirba
Hi
i have written a java file to test methos in File API.
import java.io.*;


public class TestFile {
// static final transient int maxElements = 100;

public static void main(String[] args) {

System.out.println(System.getProperty("user.dir"));

File f=new File("D:\\ABC.java");
System.out.println(f.exists());
System.out.println(File.pathSeparator);
System.out.println(File.pathSeparatorChar);
System.out.println(File.separator);
System.out.println(File.separatorChar);
System.out.println(f.canRead());
System.out.println(f.canWrite());
//System.out.println(f.delete());
System.out.println(f.exists());
try{
System.out.println(f.createNewFile());
System.out.println(f.getAbsolutePath());
System.out.println(f.getCanonicalPath());
}catch(IOException ioe){
ioe.printStackTrace();
}
System.out.println(f.isHidden());
System.out.println(f.isDirectory());
System.out.println(f.isFile());
System.out.println(f.isAbsolute());
System.out.println(f.getParent());
System.out.println(f.getPath());
System.out.println(f.getName());
f.deleteOnExit();
try {
File f1=File.createTempFile("ftg", null, new File("D:\\") );//Line1
}catch(IOException ioe){
ioe.printStackTrace();
}

Output:ftg43785.tmp.How?
Expected output:ftg.tmp.

Please help

Regards
Kirba




}

}
From K&B book

chpater-3 -Assignment Page NO:244


Regards
Kirba
Hi Wong,
Thanks for identifying the problem.
i have read the rules
2)We can box and widen..//for this can you explain with example.
3)We cannot widen from one wrapper type to another

eg ublic static void go(Long x) {}

Integer x=5;
go(5);
Above example is what rule 3 says? Please correct if iam wrong!!!

4)We cannot widen and box:
eg ublic static void go(Long x) {}

int x=5;
go(5);


Regards
Kirba.
class Dog3 {
static void go(long x) { System.out.print("int "); }
static void go(int x) { System.out.print("double "); }
static void go(double...x) { System.out.print("double "); }
public static void main(String[] args) {
Dog3 d = new Dog3();
double b = 5;
double s = 5;
int l = 5;
float f = 5.0f;
go(b);
go(s);
go(l);
go(f);
}
}

output ouble double double double .How?
my expected output ouble double int double
As per my knowledge,
1)first matching occurs by the use of primitives,it can be widening in some cases.
2)then boxing
3)then var-args

Regards
Kirba

Plase correct me if iam wrong.
i added directory structure wrongly

Here goes,
C:\myproject\source\com\wickdelysmart\Fruits.java
C:\myproject\classes\com\wickdelysmart\Fruits.class

From classes folder i created jar file
C:\myproject\classes>jar cvf myApp.jar .

Finally i place myApp.jar in ...jre\lib\ext directory

then open cmd prompt
c:>java com.wickdelysmart.Fruits

Exception in thread "main" java.lang.NoClassDefFoundError: com/wickdelysmart/Fruits


Regards
Kirba
Hi
i am preparing for scjp 5.
when i tried placing jar file(myApp.jar) in ...jre\lib\ext directory.
and then invoking the java class file it is showing java.lang.NoClassDefFoundError error.

Directory structure
myproject
[LIST]
source
[LIST]
com
[LIST]
wickdelysmart
[LIST]
Fruits.java


From source as current directory i created jar file jar cvf myApp.jar .

Regards
Kirba
Hi Paul
Read the api for containsAll() method,so you are saying list of elements in one collection can be compared with list of elements of another collection with/without using generics.

What is the exact use of wildcard capture?
Please reply as i am prpearing for scjp!!!

Regards
Kirba
Output:
************TestCollection**********
false
Hi
import java.util.*;

class TestCollection {

public static void main(String[] args) {
System.out.println("************TestCollection**********");
List<String> liss1=new ArrayList<String>();
liss1.add("wer");
liss1.add("wera");
liss1.add("er");

List<String> liss=new ArrayList<String>();//Line1
liss.add("wer");
liss.add("w");
liss.add("er");
List<Number> lisint=new ArrayList<Number>();//Line2
lisint.add(1);
lisint.add(1.67);
System.out.println(liss.containsAll(lisint));//Line 3
}
}

generic type in Line1 List<String>-->list of Strings
generic type in Line2 List<Integer>-->list of Integers
At Line3 why it is not thrrowing ClassCastException ?
Please correct if i am wrong!!!

Regards
Kirba
try{
char[] arr={'c','a','b','d','e','f'};
File f=new File("fg.txt");
FileWriter fw=new FileWriter(f);
fw.write('f');
fw.write(97);
fw.write("arath",1,3);
fw.write(arr,1,5);
fw.close();
System.out.println(fw.getEncoding());
FileWriter fw1=new FileWriter(f,true);// Line 1
fw1.write("vana",1,3);
fw1.flush();
fw1.close();


}catch(IOException ioe){
ioe.printStackTrace();
}


not getting my expected output:faratabdefana
Hi Ralph,
Even after removing i am getting the same output,and not the expected outptu.

Please help....

Regards
Kirba.
Hi Dittmer,
But still i am not getting the expected output.
Please correct me if i am wrong.
try{
char[] arr={'c','a','b','d','e','f'};
File f=new File("fg.txt");
FileWriter fw=new FileWriter(f);
fw.write('f');
fw.write(97);
fw.write("arath",1,3);
fw.write(arr,1,5);
fw.close();
System.out.println(fw.getEncoding());
FileWriter fw1=new FileWriter(f,true);// Line 1fw1.write("vana",1,3);
fw1.flush();
fw1.close();


}catch(IOException ioe){
ioe.printStackTrace();
}

See the bold statement ,what i am trying to do is appending some characters to the contents in the file

Regards
Kirba
Hi
i am facing problem in appending characters to the existing file.
Also i need the difference between flush() and close().?
As i read one of the post and i have tried without using flush() characters are written to the file or bytestream . ?
how is that working?then what is the exact of flush method?

import java.io.*;

class TestFileWriter {

public static void main(String[] args) {

try{
char[] arr={'c','a','b','d','e','f'};
File f=new File("fg.txt");
FileWriter fw=new FileWriter(f);
fw.write('f');
fw.write(97);
fw.write("arath",1,3);
fw.write(arr,1,5);
System.out.println(fw.getEncoding());
FileWriter fw1=new FileWriter(f,true);
fw1.write("vana",1,3);
fw1.flush();
fw1.close();
fw.close();

}catch(IOException ioe){
ioe.printStackTrace();
}


}
output:faharabdef

what my expected output:faratabdefana

Regards
Kirba
i forgot to add the code properly.

import java.io.*;
class Directories {
static String [] dirs = {"dir1", "dir2"};
public static void main(String [] args) {
for (String d : dirs) {
// insert code 1 here
File file = new File(path, args[0]);
// insert code 2 here
}
}
}