java

What method should I use for making my java GUI?

Hi all. I'm making a AWT GUI for a simulation game. I have only been working with java for 2 years, and so have limited experience with building more complex GUIs. I have done a few simple ones, hard coded, and tried jigloo in eclipse. I am thinking of using MIG Layout, although some say I should really try and use jigloo more, or anothe...

Load java properties inside static intializer block

I have a static util class that does some string manipulation on a bit sensetive data. Prior to use of this class I need to initialize certain static variables with values, such as usernames/password, that I prefer to store in .properties file. I am not very familiar with how loading of .properties file work in Java, especially outside o...

Java: Proper Way of Making Directories

Directories some_folder, some_folder_1, some_folder_2, and some_folder_3 don't exist initially. File folder1 = new File("some_folder/some_folder_1"); File folder2 = new File("some_folder/some_folder_2"); File folder3 = new File("some_folder/some_folder_3"); if(!folder1.exists()) { folder1.mkdirs(); } if(!folder2.exists()) { ...

Hibernate Exception help: TransientObjectException

Hello all, I am getting the following exception when I try to update an object: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: ...... Can anyone help??? The object that I am trying to update has the 'lazy' attribute set to false in the mapping fil...

How to add javax.* dependencies in Maven?

I am getting tired of manually installing javax jar files in Maven and would like to know what is the best solution to include a dependency on javax.cache, javax.transaction, or other JSRs that are not easy to find in Maven repositories. ...

A good Business calendar library in Java?

Does anyone knows a good business calendar library in java? It should handle easy :) date calculations, taking holidays into account. Ideally, besides configuring holidays and company off days, we should also be able to configure 'working hours' on a day basis so we can calculate SLA's and KPI's on working hours. I know something lik...

Java: Can (new Random()).nextInt(5) always return the same number?

Sometimes this piece of code always returns the same number (and sometimes it works fine): (new Random()).nextInt(5) I have suspicions where the problem is - it probably always creates a new Random with the same seed. So what would be the best solution: create a static var for Random() and use it instead. use Math.random() * 5 (loo...

Resources to learn and understand state-of-the-art web development in Java ?

Hi I'm trying to learn web development in Java and, from what I have seen so far, I think it's easy to get lost in the endless numbers of libraries, frameworks, techniques available. Too many books focus on some specific component (Spring, Hibernate, JSP, ...) and give only "hello world" examples. I'm looking for books or web resources...

RegEx in Java not working as I expected

Trying to extract strings that are wrapped in double brackets. For example [[this is one token]] that should be matched. To make things more elegant, there should be an escape sequence so that double bracketed items like \[[this escaped token\]] don't get matched. The pattern [^\\\\]([\\[]{2}.+[^\\\\][\\]]{2}) with "group 1" to extract ...

Java Thread Performance

I am working on a bittorrent client. While communicating with the peers the easiest way for me to communicate with them is to spawn a new thread for each one of them. But if the user wants to keep connections with large number of peers that my cause me to spawn a lot of threads. Another solution i thought of is have one thread to itera...

What is the standard parallel GC called in JVM crash dumps?

When the JVM runs with the -XX:+UseParNewGC we are getting an occasional access violation. When we look at the dump file, we see Heap par new generation total 14784K, used 13689K [0x02bd0000, 0x03bd0000, 0x06950000) eden space 13184K, 100% used [0x02bd0000, 0x038b0000, 0x038b0000) from space 1600K, 31% used [0x03a40000, 0x03abe6...

How to create Fibonacci Sequence in Java

I really suck at math. I mean, I REALLY suck at math. I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this: a = 0 b = 1 while b < 10: print b a, b = b, b+a The problem is that I can't really make this work in any other language. I'd...

Java: Where can I find advanced file manipulation source/libraries?

I'm writing arbitrary byte arrays (mock virus signatures of 32 bytes) into arbitrary files, and I need code to overwrite a specific file given an offset into the file. My specific question is: is there source code/libraries that I can use to perform this particular task? I've had this problem with Python file manipulation as well. I'm l...

How can I display a bitmap image in a Java applet?

I am having a hard time figuring out how to show an Image (or ImageIcon) in a Java applet. The following is my code. The picture (test.bmp) does exist and is on the D drive but when I run this I get the applet window with nothing in it. Can somebody tell me what I am missing to make the ImageIcon show? public class Form1 extends JAppl...

Error trying to use import.jxl... statements.

Hey, I am working on a program using eclipse galileo and jdk 6. The problem is that when I use any import.jxl... statement I get an error in eclipse and it won't compile. So statements like "import jxl.write.Label;" give me an error. I don't understand why that is. It says it doesn't like the jxl statements. If I use any import.java......

JFace question: How do I select all items in a ListSelectionDialog?

I create a JFace ListSelectionDialog as follows. final ListSelectionDialog dialog = new ListSelectionDialog( PlatformUI.getWorkbench().getDisplay().getActiveShell(), List<SomeClass>, new ArrayContentProvider(), new LabelProvider(), ""); //$NON-NLS-1$ dialog.setTitle("Dialog Title"); //$NON-NLS...

Strange Blackberry Issue - New Build Suddenly Requesting Permission Access

During development testing of my app I'm running into a strange issue where new builds (Build 2.0) of the exact same code base suddenly default permissions (carrier internet, gps) to be Prompt rather than Allow on install. Details -- Same code base So there exists two builds, both with the same code base. Build 1.0 was made/signed last ...

Java - Collection base

What is the equivalent of C# CollectionBase in Java? ...

Java JComboBox Custom Renderer and GTK

I have a list of Customer objects that I need to have selectable from a JComboBox. From what I read I need to implement a custom renderer to have the fields I want displayed in the list. I want my JComboBox to have entries formatted as such: +----------------------------------------------+ | Customer Name - Contact - City, State V...

StAX parsing from Java NIO channel

I am attempting to receive a stream of XML events over a Java NIO channel. I am new to both NIO and StAX parsing, so I could very easily be overlooking something :) My search has led me to several SAX and StAX implementations, but they all seem to operate on InputStreams and InputSources--not NIO channels. The two closest attempts I hav...