java

Date as double digit

Hi All I've a code to get year, month and day for one of my application. package com.cera.hyperionUtils; import java.util.*; public class HypDate { public static int curdate(int field) { //1. Specify integer 1 for YEAR, 2 for MONTH, 5 DAY_OF_MONTH Calendar c = new GregorianCalendar(); c.setLenient(true); //Allow overflow ...

i could not find org.codehaus.staxmate.dom package

Hi, I use netbeans 6.9 I want to use org.codehaus.staxmate.dom package but in does not exist. How can I add this package? ...

An example implementation of shift-reduce parsing

hello, i tried to implement shift reduce parser my code is below import java.util.*; public class shift { public static void main(String args[]) { String speech = "Sentence:NounPhrase VerbPhrase:NounPhrase :Art " + "Noun:VerbPhrase : Verb | Adverb Verb: Art : the | " + "...

Getting my Java program to display images through drag and drop

I am trying to get my program to display an image after it is dragged over, but I dont really have a good idea of how to do this. Example: There is an image on your desktop, photo.jpg . You would take that, drag it over into a java JFrame, and the contents of that image (the photo iteself) would display. From there I would like to be...

Fix app engine types

I recently made a change to one of my app engine models. I changed a Key field to a String. I forgot to remove all the old records. I have already added new records that have strings in the key fields. If I do a query for all the records I get an error, can not cast Key to String. If I try and change the class back to the old way I ...

How do I catch a java.io.PrintStream place its output in a JEditorPane?

I am attempting to make a Java program in which a user can select any .class or .jar file from their computer. My program will then pop up a JInternalFrame with a JEditorPane in it as the console, capturing any console output from the user's program. Note that I do not want to capture just System.err or System.out calls, but ALL PrintStr...

Invoking methods using expression language

Hi! In my spring's config I need invoke method "get" (java.lang.ThreadLocal's instance object). How I can do it without creating new class with "correct" method's naming (smt like "getValue" instead of "get")? Thanks. ...

Reading Remote MP3 File's ID3 Tags using Java

I am looking for a way to read the ID3 tags from an MP3 file on a remote server without actually downloading the file. I have seen libraries like JAudioTagger and Entagged, but both seem to require a file object and not a URL or InputStream, which I know how to get with a remote file. Is there another library that can do this? Or is ther...

Problem Sending Server Side Messages from BlazeDS to All Browsers

Hi, I've run into a bit of a wall with sending messages from BlazeDS on the server to Flex clients. I have my adapters and destinations set properly (I think) messaging-config.xml and my streaming channel setup in my services-config.xml files. The messages work beautifully in Safari (Mac and PC) but no other browsers. relevant Bits f...

Looking for simple recipe for Java Annotation

I've never written an annotation in Java. I've got a simple Java class for performance measurement. I call it PerfLog. Here's an example of its use: public class MyClassToTest { public String MyMethod() { PerfLog p = new PerfLog("MyClassToTest", "MyMethod"); try { // All the code that I want to time. return wh...

Java code for wrapping text lines to a max line width

Before I re-invent the wheel (poorly), I'd like to know if there is a some existing Java code for wrapping text lines to a given maximum width. Ideally it would: respect existing linebreaks break up lines that exceed a maximum length on word boundaries break up words whose length exceeds the maximum line width by inserting hyphens Ed...

Is it possible make all JFrames the internal program uses into JInternalFrames and place them in a JDesktopPane?

The goal is to have the user select a java program, then my program opens up a JInternalFrame with a JEditorPane inside it as the console and places said JInternalFrame in a JDeskopPane. Is it possible to change all the Windows the user's program may open into JInternalFrames and place them in said JDesktopPane, as well? (individual qu...

redirecting System.out/System.err to log4j for some jars only

In our product we use a number of external libraries. We do our logging with log4j, and most libraries do so as well, so we get most of the messages in our appenders fine. But there are several libraries that just use System.out and System.err. So I am looking for a way to redirect System.out and System.err to our log4j appenders for a ...

Simple Java Question

Can same class exist in multiple packages ? In other words, can I have dummy.java class in com.test.package1 and com.test.package2? Update Now I copied class from package1 and placed in to package 2 and now I am creating an instance of that class, I want this instance to point to class present in package 1 but currently it points to p...

How do I make a java.io.File into a java.lang.Class to run it?

I have a program that lets a user select any .class or .jar file and run it. The problem is that, to run it, I need to use something other than a java.io.File, which is what a JFileChooser returns. How can I make a java.io.File into a java.lang.Class or java.util.jar.JarFile? ...

For HashMap, would implementing hashCode() for the value help if I only search by key?

I'm using Java 6. For simplicity, everything will be public. Suppose I have this simple class. public class A{ public String name; public String data; } I want to put my class A objects into a HashMap. I will use the field name as the key, and the whole object as the value. I will only search for an object in this map by na...

How do I make my app look like a standard Android app?

Hi, I notice that most android apps have some sort of standard in that they all look similar. Most of them have some sort of list of Text that are click-able. It's somewhat hard to explain but they look really nice and I was wondering is there some sort of tool or api that allows me to change the look of an app to make it similar? Or ...

How can I call jstack programmatically on a 64-bit process?

I've got a little tool to help debug client problems with our Java application. Basically it runs jps.exe to get all the Java processes running on the machine, and then calls jstack and jmap on each of them in turn. Finally, it zips everything up and FTP's it to us for forensic analysis. To run any of the commands it uses the ProcessB...

HashSet with two equals object?

I created an object HashSet, and the value is an object (Triple) which is my own class. But I get a strange thing, when there are two equal objects on my HashSet, is it possible? Here is my overriding method for the equals in the class Triple @Override public boolean equals(Object other){ if (other == null) return false; if (other =...

res/ directory tree

I'm going through some book which tries to teach android development. In the book, the author outlines some of the directories found under res/. He mentions res/menu which holds XML based menu specifications. He also makes mention of res/raw which holds "general-purpose files." These folders were not created when I created a new android ...