Vishal Dharod

Greenhorn
+ Follow
since Jan 21, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vishal Dharod

Hello,

I am trying to copy an image from a html page to the system clipboard and then giving the user an option of saving it locally. Is there a way I can do this?
Thank you

Vishal Dharod
19 years ago
Thanx a lot Darin, you code worked!
19 years ago
I am having a rounding issue when using BigDecimal. When i try to round a number to one decimal place, i.e. 3.65 to be rounded to one decimal place, I get the result as 3.6 and not 3.7 ... Any ideas?

This is my code:

public String formatData(double value, int decimalPlaces) {

try {
java.math.BigDecimal bd = new java.math.BigDecimal(value);
value = bd.setScale(decimalPlaces, java.math.BigDecimal.ROUND_HALF_UP).doubleValue();
java.text.NumberFormat nf = java.text.NumberFormat.getInstance();
String num = nf.format(value);
int decimalIndex = num.indexOf(".");
int addDecimal = num.length() - decimalIndex;
if(decimalIndex == -1 ) {
num = num.concat(".");
for(int i = 0; i < decimalPlaces; i++)
num = num.concat("0");
}
else if(addDecimal <= decimalPlaces) {
for( int i = addDecimal; i <= decimalPlaces; i++)
num = num.concat("0");
}
return (num);
} catch (java.lang.Exception ge) {}
return ("");
}
19 years ago
I tried using RandomAccesFile class but it appends binary characters to the file i am trying to append to.
This is what I use :
try {
RandomAccessFile out = new RandomAccessFile(filename, "rw");
System.out.println("length of fie = " + out.length());
out.seek(out.length() - 5);
out.writeChars("here i am " );

out.close();
} catch (IOException e) {
}
And after running this, the file is appended with some binary chars
-- Vishal.
20 years ago
Well thats true, 'append = true' would allow appending at the end of file , but i want to append to the middle of the file and so i need a file pointer which would take me there.
20 years ago
Hello,
I am using this piece of code to create a new file and write something to it.
java.io.BufferedWriter out = new java.io.BufferedWriter(new java.io.FileWriter(filename,false));
out.write(_header);
out.write(_package);
out.close();

After this, if i want to open the same file and append the same things to the end of this file then what stream shuld i use. BufferedWriter does not have a seek function which will take me to the end of the file. I want to ues the same function to append to the file so that there is no redundancy.
-- Vishal.
20 years ago
Hello,
I am trying to establish a connection between sun one ide and oracle 9i.
I go to the runtime option and click on databases and then oracle
there it tells me to add JDBC driver ....
when i click on add driver a window pops up with 3 text boxex :
1. Name ... 2. Driver .. and 3. Database URL Prefix ....
What do i need to mention in here , I am stuck here and cannot go any further,
Do i need to download a driver for this task ?? if yes, where can i get the driver . Any answers will be appreciated because i am in desperate need of help and i cant move any further.
Thanks
Vishal.
20 years ago
How do I convert int or double to a string.
thanks
20 years ago
Thanks for ur reply Ernest but I am getting an error that an exception should be declared here.
Here it is how I have tried :-
String myVar = "Student";
Object var;
var = Class.forName(myVar).newInstance();
Here is the error :-
mp3/StudentGroup.java [25:1] unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown
var = Class.forName(myVar).newInstance();
^
mp3/StudentGroup.java [25:1] unreported exception java.lang.InstantiationException; must be caught or declared to be thrown
var = Class.forName(myVar).newInstance();
^
2 errors
Errors compiling StudentGroup.

thanks.
At line 2 of my code var is of type Object. Will it be of type Student after line 3 ?
20 years ago
I have a problem in instantiating an object using
a variable.
It can be done this way :
Student foo = new Student();
but instead of this , I want to be able to store this Student in nother variable like myVar and then instantiate Student like this :
foo = new myVar;
I know this can be done in C using function pointers but was thinking of a way in java,
thanks
Vishal.
20 years ago
The 1.4 exam also includes a short answer alongwith multiple choice questions. Can anyone please tell what is this short answer about ? and what is it going to test ? Does it involve writing code ?
Thanks
Thanks a lot Jessica for a detailed reply. it does help and give encouragent to work harder for the exam.
How much time do you think is ideal in preparing for the 1.4 exam. I am a c++ programmer and have a little expericence in java. ( say about 3 months ) Although topics like threads and inner classes are still unknown to me.
Is about a month long prep good enough which includes most of the practise tests this site recommends ?
Thanks
Vishal.