java

How can I associate a console with a Java application?

Since I've been learning Java, I've been able to create GUI programs. However, even simple "Hello World!" programs will not work, if they require a console. My research on the topic has lead me to the conclusion that my Java Runtime Environment does not have a console associated with it. Is it possible to call the Win32 "AllocConsole" ...

Read eclipse installation path using eclipse API

Hi, I opened eclipse 3.3.2. Now i need to get the current eclispe installation path. Is there any eclipse API to get the eclipse installation path? Please help in this regard. Thanks in Advance.. Snehal ...

(String) or .toString()?

Actually, this question has no big meaning, I guess. The situation is: I have a method with an "Object o" parameter. In this method, I exactly know there is a string in "o" which is not null. There is no need to check, or do something else. I have to treat it exactly like a String object. Just curious - what is cheaper - cast it to St...

What does casting do at compiler/machine level?

I have often wondered what exactly does casting do at compiler or machine level. What does it do with the 0 and 1s in memory? Can anyone point me at some good literature. ...

Problem while sending mail in java

My code runs on a windows server on my machine, but as I upload the same class file to the Linux server machine it does not work. As there is no error generation, I can't get the exact problem.. See my code below if you could help me. public static String myemail = "[email protected]", //username mypassword = "*************", //password myh...

Can Java annotations be unit tested?

I've recently started creating my own annotations and to sport TDD/BDD, I'd want to unit test my annotations to create a clear specification for them. However since annotations are basically merely fancy interfaces which to my knowledge can't be really instantiated directly, is there any way short of reflection to unit test an annotation...

What do I return if the return type of a method is Void? (Not void!)

Due to the use of Generics in Java I ended up in having to implement a function having Void as return type: public Void doSomething() { //... } and the compiler demands that I return something. For now I'm just returning null, but I'm wondering if that is good coding practice... I've also tried Void.class, void, Void.TYPE, new Vo...

How can I guarantee a "stay alive" heartbeat is sent?

We have an RMI client application written in Java which needs to send periodic "stay alive" messages to a server application. We have implemented this as a separate heartbeat thread, which sends the stay alive message to the server, then sleeps for 15 seconds using Thread.sleep(). The thread is set to be high priority: Thread heartbeat...

Private Member Access Java

Is the private member access at the class level or at the object level. If it is at the object level, then the following code should not compile class PrivateMember { private int i; public PrivateMember() { i = 2; } public void printI() { System.out.println("i is: "+i); } public void messWithI(PrivateMe...

Most advanced image compression today (not on browser)?

Hi, I am writing an application in Java to view images which contain a lot of text and graphics, like a screenshot of a webpage, actually its a image of a magazine article. Some parts are text, some parts are graphics. My client program is written in Java, I can use any image format, what is the best image compression format I can get m...

How to use regular expressions to parse HTML in Java?

Please can someone tell me a simple way to find href and src tags in an html file using regular expressions in Java? And then, how do I get the URL associated with the tag? Thanks for any suggestion. ...

Grouping Long UTC dates by Day.

Is there a sensible way to group Long UTC dates by Day? I would Mod them by 86400 but that doesn't take leap seconds into account. Does anyone have any other ideas, I'm using java so I could parse them into Date Objects, but I'm a little worried of the performance overhead of using the date class. Also is there a more efficient way th...

How can I open and close a browser window from a Java applet?

I would like to open a new window at Google.com, but then later close that window. My current code is as follows: link="http://www.google.com" try { AppletContext a = getAppletContext(); URL url = new URL(link); a.showDocument(url,"_blank"); } catch (MalformedURLException e) { System.out.println( e.getMessage() ); } ...

Unable to make static reference to generic subclass (Java)

Hi, I have the following code: class SuperClass { public static String getName() { return "super"; } } class SubClass extends SuperClass { public static String getName() { return "sub"; } } public class Dummy<T extends SuperClass> { public void print() { System.out.println("SuperClass: " + SuperClass.getName()); ...

Show Images with name containing special characters

Hi, I am trying to display some images containing special characters like ☻ ☺ ♥ or Chinese or Arabic characters in their names using jsp...but the images are not getting displayed !! <img src = "pipo².jpg" /> <img src = "pip☺☻♥o².jpg" /> What am I doing wrong !! ...

Java Listener not starting Under Tomcat

In my Tomcat logs (catalina) I am getting the following error preventing my application from starting up: SEVERE: Error listenerStart 24-Mar-2009 13:23:10 org.apache.catalina.core.StandardContext start SEVERE: Context [/exampleA] startup failed due to previous errors I do not know why I am getting this. In my web.xml I have the follo...

Can't import java.lang.instrument.Instrumentation

If I try to use import java.lang.instrument.Instrumentation; it says this statement can not be resolved. What could be wrong? I am using jdk1.6. ...

Can ANTLR generate a parser class that is final?

I'm using ANTLR 3.1 and ANTLRWorks to generate a parser class in Java. The parser performs better if I mark the generated class with the Java final keyword. The problem is: I am adding this keyword manually after each time I re-generated the code from the ANTLR grammar. Is there anyway, in the grammar, of telling ANTLR to add the final k...

Restricting a SELECT statement in SQL Server 2005

Hi, I have a situation where before doing a particular task I have to check whether a particular flag is set in DB and if it is not set then rest of the processing is done and the same flag is set. Now, in case of concurrent access from 2 different transactions, if first transaction check the flag and being not set it proceeds further. ...

Is there an existing library method that checks if a String is all upper case or lower case in Java?

I know there are plenty of upper() methods in Java and other frameworks like Apache commons lang, which convert a String to all upper case. Are there any common libraries that provide a method like isUpper(String s) and isLower(String s), to check if all the characters in the String are upper or lower case? EDIT: Many good answers abo...