java

Are annotations mainly about documenting code or are they enforced by the compiler?

@Deprecated public class Betamax { ... } In the above example, what effect does the @Deprecated have? Is it purely documentation? Or does it change something about how the compiler treats this class? ...

2d arrays, input files... Error: empty String (?)

This is my assignment: link Here are my questions: How can I fix this error: Exception in thread "main" java.lang.NumberFormatException: empty String at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1012) at java.lang.Double.parseDouble(Double.java:527) at extracredit.Main.read...

Javabat catDog Help

public boolean catDog(String str) { int count = 0; for (int i = 0; i < str.length(); i++) { String sub = str.substring(i, i+1); if (sub.equals("cat") && sub.equals("dog")) count++; } return count == 0; } There's my code for catDog, have been working on it for a while and just cannot find out what'...

What Java Data Structure/Solution would best fit these requirements?

I need a java data structure/solution that meets these requirements. What best fits these? 1) Object's insertion order must be kept 2) Object's must be unique (These are database objects that are uniquely identified by a UUID). 3) If a newer object with the same ID is added, the older version of the object should be over-written/r...

I'm looking for a solution to the excessive verboseness of Java without using Groovy

I like how Groovy makes all of your instance variables and class variables public and writes getters and setters on your behalf. This saves a lot of unnecessary coding. On the other hand, my boss hates it, making me very sad :( Is there a way to achieve the conciseness of Groovy in Java without having to use Groovy or some other framewo...

Most efficient way to scan the windows process list?

So I'm currently working on a project that needs to time when certain processes are running. I'm trying to figure out the most efficient way to scan the process list, then check the process list executable names against the list of supported programs. Essentially the problem is two parts: 1) Most efficient way to get the process execut...

Automatic generation of wrappers to prevent "malicious downcast"?

If you implement an interface in Java, there is nothing to prevent the caller from looking at what concrete implementation you have supplied, casting to that class and calling methods that are not in the interface. I believe this is called "malicious downcasting". A way to prevent this is to create a wrapper that only has the interface'...

How safe would it be to use functional-java to add closures to a Java production project?

I would love to use closures in Java. I have read that they may or may not make it into Java 7. But an open-source project called functional-java has implemented functional features including closures. How safe would it be to use such a library in an enterprise production app? Is there a better way to add closures to Java currently? ...

What are your experiences using the functional java project?

I was reading the following question - How safe would it be to use functional-java to add closures to a Java production project? and I had been thinking of using the Functional Java project as well in my current project. I was wondering what are Stack Overflow's users experiences with using the Functional Java project? In particular, I'm...

read a file using Scanner: Why am I getting an error when using Scanner for read files in java ?

This example demonstrates using Scanner to read a file line by line (it does not perform a write operation) I don't know why I get an error when I try to compile. Could somebody explain the reason to me?. I'm using jcreatorLE and JDK 1.6 to run my program: import java.io.*; import java.util.Scanner; public final class File_read { pu...

How to programmatically adjust the disable directive in the mod_jk load balancer configuration?

We have a setup where we have one httpd (apache) with mod_jk talking in a load balance setup to three tomcat servers. We have to recycle each tomcat instance envery three hours. So tomcat1 will restart at 1, and tomcat2 at 2 and ... until tomcat1 recycles again at 4. We want to configure a script or a type of program to disable the ...

How do I create a right click context menu in Java Swing?

I'm working on a school project and we want to implement a right click pop-up menu in the gui. Currently we are doing something like creating a JMenu on right click and setting its location to that of the mouse's position... This seems really ugly and is very buggy, is there any better way of doing this? I'm sure there must be. ...

Is there any way to modify the value of a `private static final` field in java from outside the class? (Or, I need to monkey patch an external library).

I know this is normally rather stupid, but don't shoot me before reading the question. I promise I have a good reason for needing to do this :) It's possible to modify regular private fields in java using reflection, however Java throws a security exception when trying to do the same for final fields. I'd assume this is strictly enforc...

Wrapping up a C++ API in Java or .NET

Has anyone successfully "wrapped up" a C++ API in Java or .NET? I have an application that provides a C++ API for writing plug-ins. What I'd like to do is access that API from .NET or Java. Would I need to use COM, or are there simpler/better alternatives? ...

How do I configure custom node definitions in Apache Jackrabbit?

Is there a way that I can configure custom node types for Apache Jackrabbit to be registered when a new repository is instantiated? I am automating my build using Apache Maven and have some unit tests to run with JUnit and integration tests to run with Jetty and want to be able to easily set-up and tear-down a test repository. ...

How do I set an <env-entry/> in JBoss as part of the server context?

I want to configure connections to a JCR repository at the application server level JBoss and retrieve those settings from within my web application using JNDI. I managed to configure the JCR repository using a typical data source. Can somebody tell me how to configure the username and password settings? Or point me to some samples? I m...

How do I close a port in a case of program termination?

I am using Socket communication in one of my Java applications.As I know if the program meets any abnormal termination the listening ports does not get closed and the program cannot be started back because it reports "Port already open.." Do I have anyway to handle this problem? What is the general way used to handle this matter? ...

Is there a difference between setting JAVA_HOME through cmd line or GUI

This is a real noob question. When I set up JAVA_HOME using the command line interface I used set JAVA_HOME = C:\Program Files\Java\jdk1.6.0_13 However when I open the JAVA_HOME variable from System>Advanced>Environment Variables the change is not visible. Are these two different settings? I have this question every time I set up a n...

How should server push data to rich client

I'm writing a simple accounting program consists of several C# winform clients and a java server app that read/write data into a database. One of the requirement is that all C# clients should receive updates from the server. For example, if user a create a new invoice from his C# client, other users should see this new invoice from their...

Java String.equals versus ==

This code separates a string into tokens and stores them in an array of strings, and then compares a variable with the first home ... why isn't it working? public static void main (String... aArguments) throws IOException { String usuario = "Jorman"; String password = "14988611"; String strDatos="Jorman 14988611"; StringTokenizer toke...