java

Executor and Daemon in Java

Hi, I have a MyThread object which I instantiate when my app is loaded through the server, I mark it as a Daemon thread and then call start() on it. The thread is meant to sit and wait for information from a queue as long as the application is active. My problem/question is this: Currently MyThread is extending Thread because I mark it a...

java.util.Date is using TimeZone?

I have 2 different computers, each with different TimeZone. In one computer im printing System.currentTimeMillis(), and then prints the following command in both computers: System.out.println(new Date(123456)); --> 123456 stands for the number came in the currentTimeMillis in computer #1. The second print (though typed hardcoded) resul...

Using Swing, I want to draw a couple of points...

... in an image and do some calculation on their [x y] coordinates. My first idea was to use an image as the background of a JPanel and then register the points, but I'm not sure there will be a way to mark these on the JPanel. There is also the Drawing library, which I'm unfamiliar with, but I'm not sure if I can combine these with S...

My problem is how do i make this work

import java.util.Scanner; public class Fraction { private int numerator; private int denominator; private int product; private int sum; public Fraction(int num, int denom) { this.numerator=num; this.denominator=denom; if (this.denominator == 0){ System.out.println("can not divide by zero"); }// end if }// end fraction ...

Google App Engine encoded key in Java

Can someone provide some simple code about how to use an encoded key in Java for the Google app engine. The sample code is a little bit confusing. Suppose I have an employee class and I want the primary key to be manually constructed with a format of "name, email, phone" for example a sample key would be"James Smith,[email protected]...

Data lookup method for small data set with Java?

We have to lookup some data based on three input data fields. The lookup has to be fast. There are only about 20 possible lookup combinations. We've implemented this using a static HashMap instance where we create a key by concatinating the three data fields. Is there a better way to do this or is this the way to go? Code is below. ...

Midlet v/s Phone Browser app pros and cons?

How do you weight the pros and cons between a Midlet and Browser based client/server app for a phone ... What are the pros and cons of both... And based on your experience what will you prefer to go in for and why? I have listed some points based on which we can compare both feel free to add your own... Rapid development. Rich UI. ...

How to set build paths automatically in Eclipse

Whenever I update our project's code from the svn I have to set the build paths of the libraries I import again because the last person who made a commit has a different classpath from mine. Is there a way in Eclipse to automatically put in the imported libraries after updating from the SVN? I have heard of build files (Ant,Maven) but...

Should thread blocked by java NIO Selector.select() be considered waiting or running

The documentation of selectorObj.select() method states This method performs a blocking selection operation. It returns only after at least one channel is selected, this selector's wakeup method is invoked, or the current thread is interrupted, whichever comes first. I understand the documentation The thread that is b...

Mobile phone SDK's Linux binaries

On various mobile phone developer sites like Nokia, Sony Ericsson, Motorola etc... I found Java ME development SDK's for mobile phones but only installable on Windows OS... I have a Ubuntu OS (Jaunty Jackelope) at home and was wondering if Mobile SDK's Linux installable versions are available?.. I have the NetBeans IDE installed on ...

Paint RTF/HTML strings into a custom swing component

In my Swing application, users enter styled text into a JTextPane which uses an RTFEditorKit (HTML is also a possibility). I then need to render many of these styled notes at specific coordinates in a custom component. I would think the View.paint method would be helpful here, but I'm not able to create a usable View object. I have th...

Bad idea to use String key in HashMap?

I understand that the String class' hashCode() method is not guarantied to generate unique hash codes for distinct String-s. I see a lot of usage of putting String keys into HashMap-s (using the default String hashCode() method). A lot of this usage could result in significant application issues if a map put displaced a HashMap entry t...

java: log exception being thrown

In java, I want to log the exception being thrown from a piece of code: try { doRiskyThing(); } catch(Throwable t) { log.warn("too bad"); throw t; } The problem is that now my method must declare it throws throwable. On the other hand, if I log the exception in a finally block, how do I know what exception is being thrown...

how do I configure autowire in spring

how do I configure autowire in spring ...

Java, Object.hashCode() result constant across all JVMs/Systems?

Is the output of Object.hashCode() required to be the same on all JVM implementations for the same Object? For example if "test".hashCode() returns 1 on 1.4, could it potentially return 2 running on 1.6. Or what if the operating systems were different, or there was a different processor architecture between instances? ...

Compound String key in HashMap

We are storing a String key in a HashMap that is a concatenation of three String fields and a boolean field. Problem is duplicate keys can be created if the delimiter appears in the field value. So to get around this, based on advice in another post, I'm planning on creating a key class which will be used as the HashMap key: class The...

Java - Creating a string by selecting certain numbers from within a text file

I have a .txt file that has numbers 1-31 in it called numbers. I've set up a scanner like this: cardCreator = new Scanner (new File ("numbers")); After this, I'm kind of confused on which methods I could use. I want to set up a conditional statement that will go through numbers, evaluate each line (or numbers 1-31), and includ...

Java TreeMap iterator not working correctly for String keys.

I have a TreeMap that maps String keys to a custom City class. Here is how it is instantiated: TreeMap<String, City> nameDictionary = new TreeMap<String, City>(new CityNameComparator()); CityNameComparator implementation: public class CityNameComparator implements Comparator<String> { public int compare (String c1, String c2...

Graphical Sudo for Mac OSX

Hi. I'm designing a little software in java. Don't know the term/definition to what I'm doing, but I'm prompting commands from java to the terminal. Something like this: Process process = Runtime.getRuntime().exec("command"); I've done this before in linux, and I used the gksudo for commands that required root password. Is there any "...

How to get the added, removed or changed chars from DocumentListener?

Hi, I have JTextAreas and need to get chars, which are added, removed or changed to it. How do I do this? ...