Harald Kirsch

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

Recent posts by Harald Kirsch

For those who want to learn more about Java than they thought they could:

"Programming in Scala" by Odersky, Spoon, Venners

Learning what Scala can do on the JVM provides a whole new look on the features and some of the shortcomings of Java. I particularly liked the full chapter on equals/hashcode/compare and how easily you can make mistakes here.

Then the one book I think every Java develper should have read:

"Clean Code" by Robert C. Martin

There is no way around interpreting and adapting his straight advices in concrete situations, but all in all the book gave me a lot of hints about coding habits to reconsider.

Harald.
13 years ago

Patel Chintan wrote:Hi I am having one problem while converting date format.
I am getting date as "2010-01-27 06:43:34" string in XML. I need to store it into UTC format.



Forgive my slightly off topic answer, but I ran into date strings lacking a time zone indicator recently one too often: if possibly at all, make sure to get a time zone indicator into the XML. Otherwise it has at least 24 different interpretations, depending on which time zone it actually is. You may currently know from context, but tomorrow someone changes his/her mind and switches from UTC to localtime or vice versa.
14 years ago
What does this have to do with regular expressions?
18 years ago
Would "Thursday" be a date or a word. How about 20060130? Looks like a huge number to me, but could as well denote the 30th January 2006.

As you see there no way to prescribe a solution without a more detailed specification. But before posting the spec here, I suggest to have a look at regular expressions.
18 years ago
I am surprised you get a response at all. After printing a command towards the server, I would at least perform a flush() to make sure things get really out of the door.

Depending on the server, a socket.shutdownOutput() (don't use close()) may get things going. This, however, is of course only an option if there is only one command to send.
First hit when googling for: java sun tutorial nested class

The individual thread elapsed times start to approach the times I have observed if I run each individual test on the same thread.



Multithreading only pays if there is CPU power to spare. When you run each individual test in the same thread, how much idle time does the CPU have? Put another way: Lets call cpuuse:=(100%-idle). If cpuuse is >50%, a 2nd thread would want to increase it to >100%, which is not possible. Consequently the duration to finish two jobs will increase beyond 2x(one job).

If cpuuse is close to 100% for one thread already, there is no point in starting several threads, because it only creates overhead. (In all cases, cpuuse includes cycles burned by the database.)
19 years ago

Originally posted by Nidhi Singhal:

I want to convert java.nio.ByteBuffer object to a StringBuffer.



I once wondered why this does not exit. Could not believe it. Finally I did it myself.

monq.stuff.Coder

Emma test coverage reports 41.2/42 lines code coverage for my junit tests. This does not mean it must be free of bugs, but I made at least an effort to get it right.

Download link at the bottom of the page mentioned above.
19 years ago

Originally posted by David Weitzman:

The need for flip() comes from the different ways a buffer's position and limit values are interpretted in the two different contexts buffers are typically used: as places to insert data and as sources from which data is read.



So flip() was introduced to save two methods: instead of having getReadPosition(), getReadLimit(), getWritePosition(), getWriteLimit(), we only have to deal with position() and limit(), but the semantics of both being state dependent.

An explanation, but not very convincing.
19 years ago
If the files have some unique key, merge them into one file and sort them by this key. You may need to add an additional column that tells you from which file a certain row is.

Now read through the combined file linearly. Records that relate to each other are on neighbouring lines. Perform the update, delete the additional column and write out the new export file.

If necessary, sort the export file into its original order.

This takes two sorts and one linear run through the combined file. Should finish faster than you can read this message.-)

Harald.
19 years ago
Recently I asked a similar question on http://forum.java.sun.com/thread.jspa?threadID=681917&messageID=3974007#3974007, but got no useful answer.

Why does java.nio.Buffer have this (silly) flip() method. To me it seems to be an artefact of the underlying implementation. As a user of a Buffer I just want to read and write, possibly after checking how much data or space is available. Why do I have to call flip() as an announcement like "Hey, wake up, get ready, are you there, everything fine, may I now start reading, after I was writing before?"

Any ideas what the benefit of flip() is?
19 years ago
Create a ByteArrayOutputStream and wrap it into a

GZIPOutpuStream

Then stick this into a PrintStream or PrintWriter and write the string you want to compress into it. Close all streams and fetch the bytes from the ByteArrayOutputStream.
19 years ago
Why use sed?

Assuming you use (ba)sh, try this:


For the details of this percent and hash business see:
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_02
[ November 09, 2005: Message edited by: Harald Kirsch ]
19 years ago