java

Java Utility Class vs. Service

What's the difference in Java between a utility class (a class with static methods) and a Service class (a class with public methods that provides a "service"). For example, one can argue that a cryptographic object (providing methods to encrypt, decrypt, hash or get a salt value) is a Service provider, but many group this functionality...

Java Generics putting on Map<String, ? extends List<String>>

Is there a way to make the following implementation in a type safe manner? public void myMethod( Map<String, ? extends List<String>> map ) { map.put("foo", Collections.singletonList("bar"); } The above implementation doesn't work. It requires a Map<String, ? super List<String>> to compile the method map.put() correctly. But myMetho...

Java synchronization and performance in an aspect

I just realized that I need to synchronize a significant amount of data collection code in an aspect but performance is a real concern. If performance degrades too much my tool will be thrown out. I will be writing ints and longs individually and to various arrays, ArrayLists and Maps. There will be multiple threads of an application tha...

Is it possible to use more than one persistence unit in a transaction, without it being XA?.

Our application needs to use (read-only) a couple different persistence units pointing to different databases (different, commercial vendors as well). We do not have the budget to enable 2pc on one of them (Sybase). Is there a way to use these in a transaction without it having to be an XA transaction? We're using Websphere 6.1, Sybas...

Free Video podcasts/Tutorials for Java beginner

Can someone list a few Video tutorials/podcasts for Java and J2ME? Thanks ...

Simple List of All Java Standard Classes and Methods?

Hello, I'm building a very simple Java parser, to look for some specific usage models. This is in no way lex/yacc or any other form of interpreter/compiler for puposes of running the code. When I encounter a word or a set of two words separated by a dot ("word.word"), I would like to know if that's a standard Java class (and method), ...

how to write data to socket channel

is there any small working program for recieving from and sending data to client using java nio. Actually i am unable to write to socket channel but i am able to read the incoming data how to write data to socket channel Thanks Deepak ...

Threading in Java

I am trying to have my main thread spawn off a new thread and, after some time, raise the interrupt flag. When it does so, the spawned thread should see that flag and terminate itself. The main thread looks something like this: final Thread t = new Thread() { @Override public void run() { f(); } }; t.start(); try { t.join(time);...

Why is my catch blocking saying this....

public void populateNotesFromFile() { try{ BufferedReader reader = new BufferedReader(new FileReader(DEFAULT_NOTES_SAVED)); String fileNotes = reader.readLine(); while(fileNotes != null){ notes.add(fileNotes); fileNotes = reader.readLine(); } reader.close(); } c...

How to build a java web application

Hi, Soon I will have to start a web project for a company, and I now need to choose a technology to build the app. I'm thinking about using Java, hence I'd like to find a framework that will help me building the app (I'm used to PHP framework such as CakePHP & CodeIgniter). What I don't understand is that it seems to exist a lot of fra...

In-memory Java database that I can persist (as a single huge blob of memory)

I am looking for an in-memory relational (SQL) database for Java (something like HSQLDB), whose whole state I can serialise. wholeDatabase.serialize(outputStream); newCopyOftheDatabase.loadFrom(inputStream); Or maybe the DB only uses a byte[] that I give it on initialization: byte[] memory = new byte[10 *1024*1024]; new InMemoryDatab...

Java .properties file, how to reference already defined property later, dir.default=/home/data/in/

define a default directory for Input files dir.default=/home/data/in/ dir.proj1=dir.default /p1 dir.proj2=dir.default /p2 dir.proj3=dir.default /p3 is this possible? ...

Is it wrong to have static and non-static methods in the same class?

Is it wrong to have static and non-static methods in the same class? ...

Struts2: Adding parameters from a map to a URL tag

I want to add a variable list of parameters to a Struts2 URL tag. I have a map of the parameters (name value pairs) in an object in the session. I'm struggling to find a good approach to this. Here is the relevant JSP code: <s:iterator value="%{#session['com.strutsschool.interceptors.breadcrumbs']}" status="status"> <s:if test=...

Java read file at a certain rate

Can someone point me to an article/algorithm on how can a read a long file at a certain rate? Say i do not want to pass 10 kb/sec while issuing reads. ...

How to use Open Type Fonts in Java ?

Is there a way to read Open Type Fonts in Java the same way as i do it with TrueType Fonts ? This works perfectly for TTF but i did not figure out yet how to do the same with Open Type Fonts. Font f = Font.createFont( Font.TRUETYPE_FONT, new FileInputStream("f.ttf") ); Please note i cannot relay on installed fonts. I provide the font...

Which HTML tags are supported in Swing components?

Many Swing components support embedded HTML, but I cannot find any official documentation on that subject. (Everything on Sun's pages about HTML seems to be targeted at JEditorPane) So: Which HTML tags are supported in Swing components? EDIT: Although I said that I'm missing "official documentation", I'd also like any "unofficial" doc...

Applet class loader cannot find a class in the applet's jar

I started to ask this question and then figured out the answer before submitting it. I've decided to post the question anyway so that other people who run into the same problem will be able to learn from my mistakes. I'm having a problem with an applet (a JApplet actually) unable to instantiate another class which is included in the s...

Good practice to include XML config in Java classpath?

My application is configured by some Spring XML configuration files. Is it good practice in Java to include the XML files in the classpath, and reference them in my application using the classpath? ...

Dynamic coloring

Hi, any experience in changing a Widget's (background-) color dynamically? afaik I can only change the CSS style name but as the color is computed, I don't have a chance here? I found something like DOM.setStyleAttribute(mywidget.getElement(), "background", "#FF0000"); but that rather looks nasty. any ideas? ...