java

how to organize the code similar to #region/#endregion in .NET?

Hi, While the code is growing big it is getting harder and harder to keep everything well organized. One thing I liked very much the time I developed in .NET was #region/#endregion which enabled to organize the code in logical groups and made further organization much easier. Does anyone know whether there is any similar code organizat...

Java: What is the rough "Cost" of a Thread (CPU Cycles / Memory) ?

Hello, I would be greatfull for help regarding my question. What is the rough "cost" of using threads in java? Are the any rule of thumbs/empirical values, how much memory the creation of one thread costs. (This is my main question). Furthermore is there a rough estimate how many "cpu cycles" the creation of a thread costs? The motiva...

Steps to trouble shoot SSL

Hi, I am trying to trouble shoot a two way SSL handshake mechanism. I get an error Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target This indicates that one of my keystore or my truststo...

Why can you reflect and call a (not so) private method in Java and .Net

In both Java and C# it is possible to invoke a private method via reflection (as shown below). Why is this allowed? What are the ramifications of doing this? Should it be taken away in a future version of the language? Do other languages/platforms allow this?If I have this class in both Java and C# Here is the example public cla...

Easy way of running the same junit test over and over?

Like the title says, I'm looking for some simple way to run JUnit 4.x tests several times in a row automatically using Eclipse. An example would be running the same test 10 times in a row and reporting back the result. We already have a complex way of doing this but I'm looking for a simple way of doing it so that I can be sorta sure t...

in java language, in order to make a text editor like textmate, what widget should i use

hi all, i want to write a text editor in java. i want it have a snippet feature similar to textmate. now i have no idea what to use as the main editor area. should i use some widget in swing? great thanks. ...

unexpected behaviour of setParseIntegerOnly(true).

Following is clearly mentioned in java docs about java.text.NumberFormat class :- setParseIntegerOnly : only affects parsing, e.g. if true, "3456.78" -> 3456 (and leaves the parse position just after index 6) if false, "3456.78" -> 3456.78 (and leaves the parse position just after index 8) This is independent of formatting. Here is an ...

SWT and Java WebStart on Mac OS X 10.5

I am using the most stable SWT Cocoa downloads for Mac OS X and and launching my app via Java WebStart. All jnilib files are within my app jar on its root. The app downloads, verifies, but I cannot get any buttons to respond. I can enter data into all my UI components. My VM arguements are "-d32" and "-XstartOnFirstThread". The app work...

java generics and collection assignment

If I have this class: class Foo<T> implements SomeInterface { final private List<T> list = new ArrayList<T>(); final private Class<? extends T> runtimeClass; public Foo(Class<? extends T> cl) { this.runtimeClass = cl; } // method override from SomeInterface @Override public boolean addChild(Object o) { ...

Sorting List<MyObject>

Which is the quickest way in Java to sort a list List<MyObject> myObjectList based on some numerical property of MyObject? ...

Java OS Process Queue

I'm using the native ProcessBuilder class to create a variably sized list of process objects. Currently, I simply roll through the list calling the start method on each Process instance. I would however like to better control this aspect of the application by limiting the number of my running processes to a custom value (e.g. number of p...

JSF password confimation validation using ADF 11

How can I create a validator that validates if the user inputed the same values in the password field and the password confirmation field? I did it in the managed bean, but I prefer to do it using a JSF validator... The real question is, how to create a validator that access other JSF components other than the component being validated...

Threaded drawing onto a canvas in Java SWT

I've been working quite a bit on something I can only describe as a "threaded canvas" for some time now. In a moment I'll describe what I have, but since I'm really open to new ideas, existing solutions or a completely fresh start, I'll formulate the problem. The canvas is intended to display genetic information (although the specific p...

Is it possible in Springframework 2.5.6 to have scope="session" create the object on session create

I've got a project using Jetspeed portal and Springframework 2.5.6 where I need a Jetspeed level service to be unique for each user logged in. This would be best done using Spring AOP and scope="session". The problem is, that these are behind the scenes beans that need to be running as soon as the session in initiated. It appears that ...

The right way to manage a big matrix in Java

I'm working with a big matrix (not sparse), it contains about 10^10 double. Of course I cannot keep it in memory, and I need just 1 row at time. I thought to split it in files, every file 1 row (it requires a lot of files) and just read a file every time I need a row. do you know any more efficient way? ...

How does one instantiate an array of maps in Java?

I can declare an array of maps using generics to specify the map type: private Map<String, Integer>[] myMaps; However, I can't figure out how to instantiate it properly: myMaps = new HashMap<String, Integer>[count]; // gives "generic array creation" error myMaps = new HashMap[count]; // gives an "unchecked or unsafe operation" warnin...

Running JAI in OSGi

I'm trying to run Java Advanced Imaging (JAI) within an OSGi container (spring-dm). I'm able to access the JAI libraries, but receive the following error when I call JAI for the first time: Error: Could not load mediaLib accelerator wrapper classes. Continuing in pure Java mode. Occurs in: com.sun.media.jai.mlib.MediaLibAccessor com.s...

Java DecimalFormat include all digits to the left

I'm trying to format an arbitrary length decimal so all of the numbers to the left of the decimal point are displayed but a maximum of 2 to the right are displayed (if they are non-zero). How can I specify in a DecimalFormat to display all numbers to the left rather than specifying the number of digits ahead of time? thanks, Jeff ...

Empirical data on the effects of immutability?

In class today, my professor was discussing how to structure a class. The course primarily uses Java and I have more Java experience than the teacher (he comes from a C++ background), so I mentioned that in Java one should favor immutability. My professor asked me to justify my answer, and I gave the reasons that I've heard from the Ja...

Updates to the JVM Specification

JVM Spec 2nd Edition is dated by 1999. Which important updates since then (like dynamicinvoke) should I consider to learn? This is in course to understand internals of the modern JVM implementations (HotSpot particularly). ...