java

Ant: Referencing dynamic properties

I want to use the same ant script to do a build in either my local windows environment or on our redhat build server. I have a variable 'buildDirectory' in two files (build_unix.properties & build_windows). I want to set variables depending on the environment. <osfamily property="os.family"/> <property file="./build_${os.family}.pro...

Algorithm for Determining Tic Tac Toe Game Over (Java)

I've written a game of tic-tac-toe in Java, and my current method of determining the end of the game accounts for the following possible scenarios for the game being over: The board is full, and no winner has yet been declared: Game is a draw. Cross has won. Circle has won. Unfortunately, to do so, it reads through a predefined set o...

How to improve this enumeration type ?

I will often need to translate from the string code into its Enum type. See snippet below. I think this is highly inefficient. How can I improve the method deref so that: It will be threadsafe. It is faster. Code: public enum SigninErrorCodes { InvalidUser("a0"), InvalidPassword("b5"), NoServerResponse("s2"); SigninErrorCod...

Java Swing GUIs on Mac OS X

Have you ever attempted using Swing only to end up changing courses because it just couldn't do what you wanted? I'm pretty new to Swing, having only used it for school projects over 5 years ago, but it seems Swing has come a long way in providing a more native look and feel, so much so that I'm considering using it to develop the GUI f...

Ice Faces Query parameters

How to pass query parameters through URL in ice faces or tomahawk? ...

Java AppDomain like abstraction?

I'm curious if there are any Java abstractions that are similar to .Net's AppDomain. In particular, I'm curious because I've found that with our Coldfusion/J2EE server we need to restart it every few days due to a slow memory leak that we haven't been able to easily track down yet. This can wreck our long-running processes and we'd rea...

Should we use type cast for the object.toArray()???

String[] a = c.toArray(new String[0]); First: Do I need type cast here? (I think we should write like (String[])c.toArray(); BUT I have seen it as just c.toArray() without using type cast. Is this valid? Second: Also why we write new String[0]? ...

Why is the Bigdecimal(double d) construction still around?

I've noticed substantial pain over this constructor (even on this forum). People use it even though the documentation clearly states: The results of this constructor can be somewhat unpredictable http://java.sun.com/javase/6/docs/api/java/math/BigDecimal.html#BigDecimal(double) I've even seen a JSR-13 being APPROVED with a recomm...

JTextField

how to set the focus in the JTextField?? ...

Java Time Savers

I find the nature of this question to be quite suited for the practical-minded people on Stackoverflow. I'm setting out on making a rather large-scale project in Java. I'm not going to go into specifics, but it is going to involve data management, parsing of heterogenous formats, and need to have an appealing interface with editor seman...

What does <E> mean in Collection<E>?

What meaning has <E> on the code Collection<E>? ...

Calling the overridden protected method of a class higher up in the hierarchy

Consider the following classes in Java class A { protected void methodA() { System.out.println("methodA() in A"); } } class B extends A { protected void methodA() // overrides methodA() { System.out.println("methodA() in B"); } protected void methodB() { } } public class C extends B // ...

How to check how much resources a java program uses?

Hi How do I check how much resources a java program uses? In java it is quite easy to create a big nice program that does practically everything you want it to, but a little side effect is that is also very easy to indirectly allocate to much memory and cpu cycles by mistake (i.e. let's just use "new" a couple of times in the wrong pl...

How to use garbage collection to delete files ?

Hi I am using a lot of temporary files in java and my problem is that they do not get deleted. Without having to implement my own handling of temporary file management (not hard I grant you but I am lazy plus with so many things to do If I can save reinventing the wheel for this all the better) is there a way to ensure the temp files on...

The **equals** in Set interface.

As we know two Set instances are equal iff they contain the same elements, BUT is it possible to have the same element in two different sets (Set interface can not contain duplicate element)? ...

Difference between Java and php5 MD5 Hash

Hi everybody, I'm facing kind of a strange issue which is related MD5-Hashes in Java and php5. I figured that unter certain circumstances the following code does not generate correct MD5 hashes: public static String getMD5Hash(String string) { try { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(string.getBytes...

serialport exception java

hi, i'm reading data from serialport using javax.comm API but when i run the code 2-3 times it is showing port currently own by this,but i have closed the port what's the problem i'm not getting plz help me this is expetion: javax.comm.PortInUseException: Port currently owned by flashhandler.TwoWaySerialComm Thanks for reply ...

Calculating Digital Root, is there a better way ?

Hello This is how i calculated the digital root of an integer. import acm.program.*; public class Problem7 extends ConsoleProgram { public void run() { println("This program calculates the digital root of an interger."); int num = readInt("Enter the number: "); int sum = 0; while (true) ...

OCL Syntax Checker

Hello, I have been looking for an existing open-source syntax-checker for the Object Constraint Language (OCL). I intend to extend the syntax-checker with additional functionality not present in the OCL standard to be more applicable to my usage with entity-relationship diagrams. However, most of the projects I have found are based on t...

Drawing chart using amcharts

Can anyone tell how to use amcharts to display the details of a particular column in a pie/donut chart.I know that it uses an XML but what I have is a CSV file and I have to group them based on a particular column status whose value can be one of the four namely "open" "Close" "In Progress" "Dropped".The CSV looks like this 12345,Harish...