aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Deprecated Methods ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Deprecated Methods ?" Watch "Deprecated Methods ?" New topic
Author

Deprecated Methods ?

Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hello reader,
What does it mean to fix deprecated methods ?. Meaning candidate has to fix the deprecated methods supplied in assignment ?. Please connote it .
Thank you
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
It means that you need to replace the code that produces the "deprecated" warning when compiled.
Eugene.
Qusay Jaafar
Ranch Hand

Joined: May 06, 2002
Posts: 127
Hi,
When you compile your code, suppose no deprecated methods, otherwise, compiler gives you warning to compile by using -deprecation. You need to fix that. Instruction is clear.
Will you tell me which methods was deprecated? and in which class?
thanks
Q. Jaafar


Qusay
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi there,
I have two deprecated areas, One is constructor and other is method. Both of them belong to String class. I had fixed constructor but the method getBytes(.. ..). I don't know how to fix can you help me ?.
Thank you,
:roll:
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Try a search in the forum
/Rene


Regards, Rene Larsen
Dropbox Invite
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Since this question has now been asked in a bunch of other forums as well, and others have already chosen to redirect it to Java in General (Beginner), I'll close this now. Followups can go here. Thanks.


"I'm not back." - Bill Harding, Twister
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Jim I reopened this because the original question is specific to the SCJD. While one of the repliers here has posted the same question elsewhere, closing this thread would deprive Gurpreet of his answer.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
I am re-closing this thread to make a point that with the forum search facility (which is not available anymore), the answer to the question in this thread would have been found in 5 seconds.
Eugene.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Eugene have you tried the Google search at the bottom of the page, I can find that answer in 1 second, which is faster than the UBB search facility, and it also does not bring JavaRanch servers down, like the UBB search did.
Mark
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi reader,
My deprecated problem is coming in String class.
The constructor is as follows:
rv[i] = new String(buffer,0,offset,description[i].getLength());
offset += description[i].getLength();
and second place is in writeRecord() method:
newData[i].getBytes(0,toCopy,buffer,offset);
Let me know how can I help my code in fixing the deprecated methods. And it would be nice of you if you briefly suggest the technical details.
Thank you,
BJ Grau
Ranch Hand

Joined: Jul 10, 2001
Posts: 234
Gurpreet -
You should look at the Java API and see what methods it suggests you use instead of the deprecated methods.
-BJ
Qusay Jaafar
Ranch Hand

Joined: May 06, 2002
Posts: 127
Dear Gurpeet
I asked the same Question and put it in 3 or 4 groups here in javaranch, but what happended that many people upset of putting that Question in different places. I don't know it will affect the others and instead of answering the Question they start to say that they are Gurus and no place for beginners to ask anything.(that's what I felt). anyway, below are two answers. one from java beginners and the other from another group in Yahoo. I hope will answer your Question,( and mine).
first answer
If the value of hibyte used was 0, then the simplest solution is to use the String(byte[], int, int, int) constructor instead:
new String(ascii, offset, count, "ISO-8859-1")
since ISO-8859-1 directly Unicode encoding for values 0-0xFF. Also worth trying is
new String(ascii, offset, count)
since it's reasonably possible the original code simply meant to use the platform default encoding, but didn't get it quite right. This typically makes little difference for "normal" ascii values - but look for funny chars like � and � (if they are used anywhere) to see if they're coming out OK or not.
If the value of hibyte is anything other than 0, read the code very carefully and try to determine the author's actual intent. Consider the possibility that they were on crack at the time, and their decoding method may simply be fundamentally wrong. Was there some standard named encoding scheme they were trying to replicate? If so, it might be better to learn the name of the encoding, and use one of the String constructors that accepts a named encoding. If it's really necessary to replicate the original functionality exactly, you can read the description for the deprecated method carefully, and write your own code which creates a char[] array and populates it with chars created from the byte[] array as described (taking hibyte into account). Then use one of the non-deprecated constructors to make a String from the char[].
2. Generally, the answer to this question is probably based on the answer to 1. Whichever constructor/encoding combination turns out to work best above, there's a corresponging getBytes() method which can reverse the process.
==================================================
Another Answer
Basically the question is how Strings are converted into bytes, and how
bytes are interpreted into Strings. There are several ways to perform this
transformation, and you must choose one. By choosing a Charset you are
deciding the format of the byte array, and thus how bytes are
converted/interpreted from/into Strings.
You can think of a Charset as a table with chars and their byte[]
equivalent. Popular Charsets are ASCII, UTF8, UTF16, but there are a lot
more.
When choosing a Charset you must take into account the range of characters
their support (English, European, Asian, ...) and the amount of space they
require (in byte array length).
It is not advisable to use the system's default charset because if you
change of OS or you copy your database to another machine with a different
language then the bytes in your database are not likely to be well
interpreted into Strings.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Are you guys not familiar with how to make a search?
If you in the search field enter 'getBytes deprecated' and press return - then you will get the answer.
If you in the search field enter 'new String deprecated' and press return - then you will get the answer.
How hard can it be
/Rene
[ July 21, 2002: Message edited by: Rene Larsen ]
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi reader,
If you guys around here could have probably answered my post called Local / Remote Database then it would had been very nice time.
Thank you,
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
Hi jaafar,
In My String class constructor hiByte is 0. So, I would be using what you had suggested. But what about getBytes() method ?.
Thank you,

Qusay Jaafar
Ranch Hand

Joined: May 06, 2002
Posts: 127
Hi,
I think as long as the deprecated constructor is changed to the new one, then getBytes() will only return the desired bytes. that's all. That's what was also mentioned above earlier. try it and let me know.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Deprecated Methods ?