java

in Java, I can't assign values to variables while i'm in the run() function of a thread-extended class.

This is my code. As you see in the run method, I assign values to tStart, tEnd, tAround and wTime. But when the Thread ends, they still have the default values of -1. I try printing out their values while the run() is running, and I have the correct values. But they are not 'writing' those values back to the variables when the thread end...

Which of these pieces of code is faster in Java?

a) for(int i = 100000; i > 0; i--) {} b) for(int i = 1; i < 100001; i++) {} The answer is there on this website (question 3). I just can't figure out why? ...

Help in deleting the messages from inbox folder

Hi, I'm trying to delete the messages which is selected by user by clicking the checkbox and then clicking the delete button, but I don't understand why my code is not performing the desirable result. Here's the code in Javamail: public static boolean deleteMessage(int j) throws Exception { store = session.getStore("pop3"); store.c...

Killer facility or scenario that would make another JVM a better choice than the Sun JVM?

For Java SE there are several JVM's available for running in production on x86: IBM J9 Oracle JRockit - http://www.oracle.com/technology/products/jrockit/index.html Apache Harmony - http://harmony.apache.org/ The one in OS X (if a Mac) which appears to be Sun with Aqua Swing. OpenJDK plus some custom offerings for running on a serve...

writing global listener

I want the active window (i.e JFrame ot JDialog) to receive specific keyEvent so that whereever the focusing this keyevent is handling by the window such as ALT+F4 if you press it wherever the focusing the active window will close,I try to override postprocesskeyEvent but it doesn't work fine ...

mp3 file format

Hi all, I want to know the version of a mp3 file format. What should I do? I am reading file properties with java programs ...

How to read a file into string in java?

I have read a file into a String. The file contains various names, one name perline. Now the problem is that I want those names in a String array. For that I have written the following code: String [] names = fileString.split("\n"); // fileString is the string representation of the file But I am not getting the desired results and th...

Java: varargs and the '...' argument

Hello, Consider the method declaration: String.format(String, Object ...) The Object ... argument is just a reference to an array of Objects. Is there a way to use this method with a reference to an actual Object array? If I pass in an Object array to the ... argument - will the resultant argument value be a two-dimensional array - b...

How can I turn a floating point number into the closest fraction represented by a byte numerator and denominator?

How can I write an algorithm that given a floating point number, and attempts to represent is as accurately as possible using a numerator and a denominator, both restricted to the range of a Java byte? The reason for this is that an I2C device wants a numerator and denominator, while it would make sense to give it a float. For example,...

JDO, GAE: Load object group by child's key

I have owned one-to-many relationship between two objects: @PersistenceCapable(identityType = IdentityType.APPLICATION) public class AccessInfo { @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private com.google.appengine.api.datastore.Key keyInternal; ... @Persistent private PollIn...

Java - regular expression finding comments in code

A little fun with Java this time. I want to write a program that reads a code from standard input (line by line, for example), like: // some comment class Main { /* blah */ // /* foo foo(); // foo */ foo2(); /* // foo2 */ } finds all comments in it and removes them. I'm trying to use regular expressions, and fo...

hibernate: create table with names in lowercase

Hibernate: I want to have hibernate automatically generate my tables with names in lowercase. For example, if my class is called com.myapp.domain.Customer, hibernate will generate a table named Customer. I want it to be called customer. I know I can use the @Table annotation to specify the table name per class. But I want it to happen "...

Java socket streams end unexpectedly

I have an application handling several Java socket connections to different kinds of remote machines (some PCs, others are embedded devices). These sockets and streams should not close indefinitely except for a very good reason (e.g. crash of remote system). I frequently encounter an issue where the input stream ends unexpectedly, witho...

Java code/library for generating slugs (for use in pretty URLs)

Web frameworks such as Rails and Django has built-in support for "slugs" which are used to generate readable and SEO-friendly URLs: Slugs in Rails Slugs in Django A slug string typically contains only of the characters a-z, 0-9 and - and can hence be written without URL-escaping (think "foo%20bar"). I'm looking for a Java slug funct...

Best books on how to optimize and profile Java code

What are Best books on how to optimize and profile Java code? ...

Palm Database (PDB) files in Java?

Has anybody written any classes for reading and writing Palm Database (PDB) files in Java? (I mean on a server, not on the Palm device itself.) I tried to google, but all I got were Protein Data Bank references. I wrote a Perl program that does it using Palm::PDB.pm, but I want to turn it into a servlet for a GWT app. ...

How can I write a Java function to return the standard name for a Unicode point?

I want to write a function String getName(int codePoint) { // ???? } which will return the standard name given to the character that the given code point represents. For example getName(0); would return the String "NULL" and getName(33); would return the String "EXCLAMATION POINT". Is there anything in the JDK for this? ...

Grouping objects by date: am I an idiot?

I have a list of objects called Activity: class Activity { public Date activityDate; public double amount; } I want to iterate through List, group them by date and return a new list . Here's what I currently do: private List<Activity> groupToList(List<Activity> activityList) { SimpleDateFormatter sdf = new SimpleDateFormatt...

About the Sun Certified Java Programmer "Plus" Certification

I read this and was left wondering: a) When is the new exam going to be released? Google search hasn't helped at all. b) How different it is from the old exam? Does anyone knows where to find the impressions of the beta testers? Is there any beta tester around? c) What should I study to pass this thing? I suppose it would be more li...

Checking a file for a certain string in Java.

I'm trying to have my application read through a text file and look for a string. If the string does not exist, it makes it using println. The only problem I'm having is that it doesn't seem to read the text file. What I have so far is: PrintWriter itemwriter = new PrintWriter(new FileOutputStream(items)); FileInputStream fstream = new ...