java

Introducing a Java stats package to an application?

I currently have a web application and wish to add certain statistics to the site. These statistics would be in addition to web statistics. I can easily log certain events to a file via log4j. Is there something I can add that will investigate the data and format it in a human readable way (chart or table)? The application is running i...

Java: Operations with Colors (add, subtract)? - Colors in a constant class

I'm working with java.awt.Color instances. Is there any way to do arithmetic operations on colors? Something like rgb(20, 20, 20) + rgb(10, 200, 170) = rgb(30, 220, 190)? What I'm trying to do: I have a gui that features a table, where if the user clicks on a cell, the other cells change color based on their relationship to the selected...

Java file read problem

Hi - I have a java problem. I am trying to read a txt file which has a variable number of integers per line, and for each line I need to sum every second integer! I am using scanner to read integers, but can't work out when a line is done. Can anyone help pls? ...

java timer - how to scheduletask at a particular time in the future.

Hi Everyone, I have used java.util.Timer to schedule TimerTask to be run every 2 hours . But how do I schedule a task to run say everynight at 2 am ? This might be something easy, I am just overlooking something I guess. Thanks in Advance ...

Gadget Hosting on Google App Engine

I have recently been tasked with working on creating a gadget for a project that is hosted on app engine. I am also hosting the gadget specification on app engine. The gadget specification is generated on the server side as it refers back to the application id that the gadget is hosted on (this project may be hosted on multiple IDs), so...

where should I put my test code for my class?

So I've written a class and I have the code to test it, but where should I put that code? I could make a static method Test() for the class, but that doesn't need to be there during production and clutters up the class declaration. A bit of searching told me to put the test code in a separate project, but what exactly would the format of...

In a java enhanced for loop, is it safe to assume the expression to be looped over will be evaluated only once?

Hi, In Java, a for-each loop. If I have a method that generates an array, called genArray(). In the following code, will the array each time be re-generated by calling genArray()? Or will Java call once the method and store a copy from the array? for (String s : genArray()) { //... } Thanks ...

Use fewer columns on SQL query through Hibernate Projections on Entity with ManyToOne relation

I'm trying to build a smaller SQL, to avoid the "select * from A" that is being build by default for hibernate Criteria. If I use simple fields (no relation), through "Transformers", I have can manage to have this SQL: select description, weight from Dog; Hi, I have this Entity: @Entity public class Dog { Long id; String descr...

Space Efficient Representation of a Graph in Java?

I want to have an undirected graph where the nodes are labelled with a pair (currently using String[] for this) and can be arbitraryly linked to other nodes. I have started with the type Hashtable. It turns out that this is not space efficient enough for me - I intend on having around 60,000 nodes (eventually, well in excess of that nu...

NameNotFoundException when calling a EJB in Weblogic 10.3

I have a EJB defined as this: package com.foo; @Stateless (mappedName="HelloWorld") public class HelloWorldBean implements HelloWorld, HelloWorldLocal .... When it's deployed to Weblogic (WL), it gets the name myBean. I'm not sure if this is important. I try to call the bean with this code: Hashtable ht = new Hashtable(); ht.put(Co...

integrating java with C#.net

Is following thing possible?if yes how? I have some core functionily already implemented in java.Now i want to create a GUI for it. I am finding it difficult to make a GUI in java using swing.I can build a GUI easily in C#.net. So i was thinking if it was possible to create a library in java that i can access frm my C# code. Shorty: my...

Executing a command from the web browser

What is the best way to execute a command on the client computer via the web browser? I know a Java applet is one way, but I really don't want to use Java. Will a firefox plugin work? ...

Why the RetentionPolicy for @deprecated is RUNTIME?

Why at runtime is anyone interested in knowing that a method is deprecated? Can some provide me with some examples? ...

What is the this[''] accessor that shows up in Drools

Just looking for a way to pass parameters into a getter in Drools... I have noticed in Eclipse Ganymede that intellisense is helpful in determining the getters that can be used to select an entity in a Drools WHERE clause. Just type a letter and hit ctrl+Space to see the list. I have another project in Drools.NET that relies on C# Pro...

Limit a ListIterator to the first N elements (optimized)

What is a simple and fast way to get an iterator that returns at most N elements from the start of a List? The simplest versions I could come up with are: #1: import com.google.common.collect.Iterators; // ... public static <E> Iterator<E> lengthLimitedIterator(Iterable<E> source, int maxLen) { return Iterators.partition(source....

Eclipse - Java Heap error while in interface

Hi there, I am pretty new to eclipse and it was working fine but now its giving me Java Heap problems and sometimes outofmemory issues... Can anyone help me with my eclipse.ini ... i have increased some memory values and it got better but not perfect... I am using this java but currently not doing java editing as such i am just in the...

Organize small utilities functions

Hi all. After years of programming, we all have a set of small functions used as helpers utilities that we wish it comes build-in so we can use it in any project and have ti taken care by more people (test and optimized). I have quite a collection of these functions. I wonder how do you guys organize them? Do you have any tips? This is...

Hibernate Exception, what wrong ? [[Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource hibernate/Tbluser.hbm.xml]]

I use netbean 6.7.1 to write "hello world" witch hibernate, but I get some errors, plz help me, thank you very much. my exception init: deps-module-jar: deps-ear-jar: deps-jar: Copying 1 file to F:\Documents and Settings\My Dropbox\DropboxNetBeanProjects\loginspring\build\web\WEB-INF\classes compile-single: run-main: Oct 25, 2009 2:44:...

Java: DRY out these two functions

These two functions have basically the same code. How can I factor it out? public static String[] removeSuffix(String gA, String gB) { String[] results = new String[2]; results[0] = gA; results[1] = gB; if (gA.equals("") || gB.equals("")) { return results; } if (gA.charAt(gA.length() - 1) == gB.cha...

Java: When to make methods static v. instance

I have a Gene class that keeps track of genes. Gene has a method for calculating the distance between two genes. Are there any reasons to make it static? Which is better? public static int geneDistance(Gene g0, Gene g1) or public int geneDistance(Gene other) Arguments for/against making it static? I understand what it means for a me...