java

java basics static method

can a static method be invoked before even a single instances of the class is constructed? ...

Java abstract modifier

Can the abstract modifier appear before a class, a method or a variable? ...

Getting an in-memory representation of the JPEG rendering of an Image.

Hi, I need to know how to get an array of bytes from a loaded image, in java. BufferedImage seems not to supply any methods that produce an array of bytes, so what do I use? ...

AdaptRecursive StackOverflowError

While compiling my project I get: The system is out of resources. Consult the following stack trace for details. java.lang.StackOverflowError at com.sun.tools.javac.code.Type$WildcardType.isSuperBound(Type.java:435) at com.sun.tools.javac.code.Types$1.visitWildcardType(Types.java:102) at com.sun.tools.javac.code.Types$1.visi...

How can I code Java to allow SSE use and bounds-check elimination (or other advanced optimizations)?

The Situation: I'm optimizing a pure-java implementation of the LZF compression algorithm, which involves a lot of byte[] access and basic int mathematics for hashing and comparison. Performance really matters, because the goal of the compression is to reduce I/O requirements. I am not posting code because it isn't cleaned up yet, and...

How can I use MATLAB arrays as keys to the HashMap java objects?

The put function works fine but the get function does not. Apparently I don't know the trick. >> X = [ 1, 2, 3]; >> M = java.util.HashMap; >> M.put(X,1); >> M.get([1,2,3]) ans = [] I have searched and read many posts but could not find a solution to this problem. It would be great if someone can let me know the trick. ...

Naming convention for a variable that works like a constant

I have a variable that I'm using like a constant (it will never change). I can't declare it as a constant because the value gets added at runtime. Would you capitalize the variable name to help yourself understand that data's meaning? Or would you not because this defies convention and make things more confusing? The larger question: ...

Global context menu for Cut/Copy/Paste with JTextField in Swing App?

What is the best way to implement a global default context menu for a Swing app that has the Windows-standard cut/copy/paste/etc. popup menu for things like JTextField? Tim Boudreau suggested installing a custom UI delegate in this javalobby thread but that was written with Java 5 in mind, so I'm wondering if there's a better way today. ...

Hibernate or JDBC

I have a thick client, java swing application with a schema of 25 tables and ~15 JInternalFrames (data entry forms for the tables). I need to make a design choice of straight JDBC or ORM (hibernate with spring framework in this case) for DBMS interaction. Build out of the application will occur in the future. Would hibernate be overki...

DOM parser for non xml

i want to parse the following type of text. Example1 <root>my name is <j> <b> mike</b> </j> </root> example 2 <root> my name is <mytag1 attribute="val" >mike</mytag1> and yours is <mytag2> john</mytag2> </root> can i parse it using a DOM parser?I will not have the same format evry time .I can have different formats in which the ...

java basics garbage collection

is garbage collection algorithm in java "vendor implemented?" ...

java basics about String

To what value is a variable of the String type automatically initialized? ...

Java: Static vs non static inner class

What is the difference between static and non static inner class? ...

J2EE deploy ear with source code

What are the (dis)advantages of deploying ear with source file? Is that the right way to deliver/deploy code ? Apart from making the ear bulky does this have any advantage? ...

java: activating a mouse click event

I have a java method activated by a mouse click on a button private void backButtonMouseClicked(java.awt.event.MouseEvent evt) { do stuff } is there some way to virtually use this method from another method without clicking the mouse on the button? ...

Has the JavaBean spec been updated to reflect the existence of annotations

I thought this should be obvious but I can't find it. Now that fields can have annotations, I thought this should be reflected in the JavaBean spec, but I can't find it. What I mean: JavaBean is a specification that allows you to treat objects in an uniform way by discovering their properties, and then reading and writing them. As PO...

JMenuItem.getRootPane() workaround ?

It seems to be well-known there is a bug when using JMenuItem.getRootPane(). I read the bug description but i cannot figure out a workaround. Do you know work-around code for this in an Action.actionPerformed() method ? Thank you. Update: I get this now but that don't work with sub-menus :-( public void actionPerformed(ActionEvent e)...

how to set SimpleDateFormat "W" use the MONDAY is first day of Week?

SimpleDateFormat "W" default set SUNDAY is first day of week,ex: SimpleDateFormat f = new SimpleDateFormat("W"); format.f(new Date()); i want to set "W" first day is MONDAY,i try: SimpleDateFormat f = new SimpleDateFormat("W"); Calendar c=Calendar.getInstance(); c.setTimeInMillis(input); c.setFirstDayOfWeek(Calendar.MONDAY); for...

While making a call to a method, with a refrence of parent class which is refering to an object of child class, why is it mandatory to have that method in Parent class too ?

public class A { } public class B extends A { public void add() { System.out.println("add in B"); } } Now here if we call add in following way hen it gives an error: A a1 = new B; a1.add(); But when we add the add() method in class A and then call in the similar fashion then add() method of child class is called. i.e. p...

Is there a way to find the type of a template (generic) parameter in Java?

I'm trying to do something like this in Java: public static <T> T foo() { return (T) bar(T); } public static Object bar(Class<?> klaz) { return klaz.newInstance(); } But the code doesn't compile since I can't substitute T for a Class<?>. With a concrete class, I can call bar like: bar(ConcreteClass.class); But the same does no...