Ian Darwin

author
+ Follow
since Aug 03, 2001
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 Ian Darwin

Not clear what you mean.

Since JavaMail lets you put whatever you want in a message, appending a line with "----" and your signature, for example, should be trivial. Or make it fancier with a multipart MIME message. See the api documentation for example code.
15 years ago
Check out POI from the Apache Software Foundation Jakarta project.

POI is a set of APIs for reading word and excel documents. You could then reformat them into something that javax.print would handle. I do NOT have any sample code for this but I believe the API comes with same.
15 years ago
If you want to pre-install the Jar files, why use JWS at all? Just make a client installer. Then you can write different versions for different JDK locations on MS-Windows, Linux, MacOSX and others. Or, just use Web Start and let it handle the grunt work.
15 years ago
You didn't say much about your CLIENT, which is where more issues arise.

I find that MS-Windows client machines tend to download the Jar files every time, whereas my Linux boxes do not. But I haven't found out why
15 years ago

I come across an information that we can get the decompiled class, that is the source back by using javap with the -c flag passed to it.


Glad you got your CLASSPATH sorted out. But as you've probably found out by now, -c gives you
byte Code, not source code. You need a proper decompiler program for that, which you can find
using a search engine. Javap isn't it.

Ian
15 years ago

First a big thank you to Ian Darwin for hanging out with us this week, answering questions.



Thanks to you, Dirk, and everybody else at JavaRanch.com.

Actually, everybody on the forum is a "Winner" because of all the great information sharing
that goes on.

Ian
15 years ago
In the First Edition of the Java Cookbook, I used one of the free Apache Regular Expression packages to explain regexes. I think any of these would work with Java 1.3. See jakarta.apache.org and look for either ORO or Regular Expressions.

Ian
15 years ago
It's pretty easy to get mislead by reading code fragments, but the code fragment you show doesn't look like anything that will compile or execute, without seeing the surrounding class. For one thing, most implementations of getChar() return the character value, not the integer value.
Here is a brief but complete program that has been run (on Java 5 aka 1.5 aka Tiger) and works:

For more information see Recipe 10.5 of the Java Cookbook, 2nd Edition, page 262.

Ian
[ October 14, 2004: Message edited by: Ian Darwin ]
15 years ago
As has been mentioned, JDO is one of several new persistence mechanisms based on "Object Relational Mapping" (another is Hibernate). The basic idea is to make your life easier: instead of writing a whole blob of SQL, you can just deal in *objects*, and have them stored into and loaded from the database (a bit like Entity EJB, but a lot easier to use). Here's a bit of an example from the book:



Ian
15 years ago

wondering the Data Structuring with Generics, foreach, and Enumerations , would it improve significant performance result ? say for "foreach" , will this feature perform better and faster as compare ordinary "for" loop


These features will make developers perform better, by typing less and getting more reliable code.

They won't do very much for runtime performance; if this is an issue you can now buy 2- and 4-CPU AMD Opteron systems.

Ian
15 years ago
See java.net.URLEncoder.encode(value, "UTF-8"). I'll leave you to guess what the corresponding Decoder class and method are called :-)

Ian
15 years ago
The trick here is that you need some "protocol" that will allow you both to *connect" and
to *authenticate" to the UNIX system.

The most widely used implementation of such protocols used to be rsh and telnet, but these are generally regarded now as hopelessly insecure. The cookbook has examples of connecting to a Telnet server.

These protocols have largely been replaced by the SSH protocol (secure shell), see OpenSSH for a free, open-source implementation of ssh... in the C language.

For a Java implemenation, you want JSch. Download the code; it comes with examples.

Ian
15 years ago
Thanks for writing. Yes, this is the general "Cookbook" style originated with the Perl cookbook,
copied by me and a few others, and then turned into a "franchise" by O'Reilly. So yes, all the
O'Reilly cookbooks are in the same (and might I add very useful and successful :-)) format.

Cheers
Ian
15 years ago
There are several issues here.

I have a Set with the following key/values:


No, you don't :-). Set is like List, it only contains values, not keys/values. Only Map contains keys/values. As well, the values you show as input are not the same as those you show for output.

Set ans = allAnswers.entrySet(); //allAnswers is TreeSet
//Collections.sort( ans , new TreeSort()); //I am getting a ClassCastException here


Actually, the code as shown won't compile if you uncomment it, since Collections.sort() takes a List, not a Set. List and Set are both sub-interfaces of Collection, but they are not interchangeable.

the TreeSort class is incomplete and I dont know how to finish it to swap the values...


A Comparator does not swap values, it simply compares them. Collections.sort or some other client does the swapping.

Note also that TreeMap, an implementation of SortedMap, will keep things in order for you.
You must never try to sort a SortedMap. The problem is that SortedMap keeps things in order by the key values, not the value values.

I'm assuming that the complexity is because you want them sorted by value, not by key as SortedMap does. Otherwise you could just use a SortedMap. Here's an off-the-top-of-my-head, late-at-night implementation that sorts Map-like entries by value. Extra points to somebody who rewrites it to not use an inner class, or better uses the existing API to the same effect.



Does my version sort by values correctly? I ran it and got this:


If you still have questions, please read Chapter 7 before you post them :-)

Cheers
Ian
15 years ago
No problem: use a DateFormat with setTimeZone(). DateFormat is discussed in Chapter 6 of the Java Cookbook.

I just ran that, at 19:52 (7:52 PM) Eastern time, and it prints the current time in both zones
(Eastern time is currently GMT-4):

Of course 11:52PM is 23:52, and 23 - 19 = 4 hours.

Hope this helps
Ian
15 years ago