java

Good source for AWT and Swing principles

Hi. I am starting to work with AWT and Swing in Java. I get some trouble sometimes, with things I don't understand. Latest example: JPanel.getGraphics() returns null in some cases. I would like a source where I can learn the principles and design of these API's, instead of just solving each problem at a time. Any recommendations? Tha...

Explaining .NET or Java to a client

At my company we develop applications that run on the JVM (JEE and Grails) as well as .NET applications (ASP.NET and client/server Forms apps). In your experience, when have you recommended one over the other to a customer? I asked this question incorrectly here but I think the fact that I put an initial list got it closed. I'm looking ...

Detect windows logout in Java

Is there a library that I can use with Java to listen for user logout and possibly other Windows events? (Even better if it supports multiple platforms!) I remember reading about a library of this sort a number of years ago, but can't seem to find it now. I've seen other threads to do essentially the same thing using Python with win32...

What name do you use for the parameter in a static variable setter method?

When I write setters for instance methods, I use this to disambiguate between the instance variable and the parameter: public void setValue(int value) { this.value = value; } So, what do I do when value is a class variable (static) instead of a member of an instance? private static int value = 7; public static void setValue(int val...

Best performing way to guarantee data consistency between concurrent web service calls?

Multiple clients are concurrently accessing a JAX-JWS webservice running on Glassfish or some other application server. Persistence is provided by something like Hibernate or OpenJPA. Database is Microsoft SQL Server 2005. The service takes a few input parameters, some "magic" occurs, and then returns what is basically a transformed ver...

try-catch block in Java - execution statements in catch code

Hello, I have a question about the order of the execution of statements in a catch block in Java. when I run the following class Test1 (see below), I expect to have as output first Hi!, then the result of the e.printStackTrace(); statement, and then Bye!. However, I never get this order. Please, look at the outputs, which I have pasted ...

How is Java's notion of static different from C#'s?

I am reading Josh Bloch's book Effective Java and he suggests using a builder design pattern when building objects that have large amounts of members. From what I can see it isn't the vanilla design pattern but looks like his variation. I rather like the look of it and was trying to use it in a C# web application that I am writting. This...

List<Map<String,Object>> to org.json.JSONObject?

List<Map<String,Object>> list = new ArrayList<Map<String,Object>>(); Map<String, Object> map = new HashMap<String, Object>(); map.put("abc", "123456"); map.put("def", "hmm"); list.add(map); JSONObject json = new JSONObject(list); try { System.err.println(json.toString(2)); } catch (JSONExce...

Ordering unit tests in Eclipse's JUnit view

The JUnit view in Eclipse seems to order the tests randomly. How can I order them by class name? ...

2-D (concurrent) HashMap: 2-property key type? hashmap of hashmaps? [update]

So I need a 2-dimensional ConcurrentHashMap. It has to be as blazing fast as possible, as I'm going to be adding to and updating its values extremely frequently. It's in a multithreaded application, hence the choice to use ConcurrentHashMap instead of just HashMap. Both the "x" and "y" indices are integers with a known range (0 throug...

Why can't I define a static method in a Java interface?

Here's the example: public interface IXMLizable<T> { public static T newInstanceFromXML(Element e); public Element toXMLElement(); } Of course this won't work. But why not? One of the possible issues would be, what happens when you call: IXMLizable.newInstanceFromXML(e); In this case, I think it should just call an empty meth...

C# equivalent of Java 'implements' keyword?

In Java if you were to have the statement: public class MyClass implements LargerClass { Would you be extending the LargerClass with more methods? What would be the equivalent of this class definition in C#? I ask because I am not very familiar with Java and am currently converting some Java code to C# code and this one is giving me...

Best way to save data in a Java application?

Hi. I'm trying to find the best way to save the state of a simple application. From a DB point-of-view there are 4/5 tables with date fields and relationships off course. Because the app is simple, and I want the user to have the option of moving the data around (usb pen, dropbox, etc), I wanted to put all data in a single file. What ...

How long does it take to become proficient in Java if you are new to programming?

I am a 25 year old new to programming. My ultimate goal is to get into mobile programming in the near future. My questions are as follows: About how long would it take a newbie such as myself to get up to speed with the java language? Is it a hard language for someone new to programming? If so any alternatives? ...

SAX Parser In Applet Failure

I have a very simple line of code in my source: XMLReader xmlReaderFactory = XMLReaderFactory.createXMLReader(); This works flawlessly from an application, however, from an applet, it attempts to load a ".class" file from the server (no classname, just the extension just as you see) and then fails to give me a parser. Exception in th...

Should I use Java's String.format() if performance is important?

We have to build Strings all the time for log output and so on. Over the JDK versions we have learned when to use StringBuffer (many appends, thread safe) and StringBuilder (many appends, non-thread-safe). What's the advice on using String.format? Is it efficient, or are we forced to stick with concatenation for one-liners where perform...

How to set up multiple source folders within a single Eclipse project?

I have several somewhat separate programs, that conceptually can fit into a single project. However, I'm having trouble telling Eclipse to make several folders inside a project folder. A simple form of the structure would be: /UberProject /UberProject/ProgramA/ /UberProject/ProgramA/com/pkg/NiftyReader.java /UberProject/ProgramB/ /Ube...

Flex/LCDS Server-to-data-source Paging

I’m trying to set up a server to data-source paged service. I’ve got everything set up so that I’m getting my assembler called and am returning values, but I’m not getting “paged” calls. Specifically: public Collection fill(List fillArgs, int begin, int rows) is always called with begin == -1 and rows == -1, instead of getting real ...

How do you configure JBOSS to use the xml lib in the web app?

JBOSS is throwing a: java.lang.NoSuchMethodError: org.w3c.dom.Document.getDocumentURI()Ljava/lang/String; Error when loading a wsdl. Can I configure it to prefer the library in my WAR instead of the system or app server lib? ...

What tool can suggest index and covering indexes for dynamicly created queries?

Our web application basically dynamically generates tables and relations. It also generate indexes on the basic level. We are looking for a MySQL profiler that will be able to suggest indexes. We have come across this two profilers : MYSQL JET PROFILER : will not tell use what index or covering index will do the job. ROT : will not ...