java

httpclient 4 how to get bytes

HttpGet httpget = new HttpGet("http://www.google.com/"); System.out.println("executing request " + httpget.getURI()); // Create a response handler ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = httpclient.execute(httpget, responseHandler); this will get responseBody as...

How do I find an enum value given the arguments that were supplied to its constructor?

I have an enum class like this: public enum Position { A1(0,0), A2(1,0), //etc public final int dy, dx; private Position(int dy, int dx) { this.dy = dy; this.dx = dx; } } Now I want a method: public static Position getPosition(int dx, int dy) Can I return Position.A1 or Position.A2 with the gi...

How Do I Minimize a J2ME App?

I need my J2ME app to run in the background and still allow the user to use his mobile without problem. the app still needs to process some events in the background. I would also like to allow the user to stop the app if he wants to. How can I accomplish this? ...

Design a GUI for a J2ME app

How do I create a J2ME app for cellphones with a GUI similar to the menus you see in Java games? I've tried MIDlets with Netbeans but they only show you one GUI element at a time. (textbox, choice, login, etc) And which Java IDE would you typically design these GUIs in? Netbeans or Eclipse? and is IntelliJ IDEA usable for this aswell? ...

How to create a service in windows vista example

Hi all, I am trying to create a new windows vista service through sc utility in command run, from some reason what worked in windows xp doesn't work in vista (surprised?). I am running the following command: sc create rmiregistryService binPath ="C:\Program Files\Java\jre1.6.0_05\bin\rmiregistry.exe" and it doesn't work... does anyone...

Synchronization of ConcurrentHashMap modifiers

I would like to cache some IO with the help of ConcurrentHashMap. The modification on the binary file should be reflected in cache as well. Since the cache is going to be used by multiple threads all IO operations are synchronized. Modifications of map go inside the same synchronized block. Which roughly looks like: synchronized (file) ...

How should I start Java-based web development?

I have been using java as my main language for 3 years while developing college assignments, and now I plan to learn the web programming aspect of it. I see there are lots of different "stuff" going on such as JSP, JSF, Spring, etc. Previous topics suggest that Head First Servlets and JSP is a good book to start with, but what do you th...

EntityManager throws TransactionRequiredException on merge() in JBoss JSF bean

I've set up a JSF application on JBoss 5.0.1GA to present a list of Users in a table and allow deleting of individual users via a button next to each user. When deleteUser is called, the call is passed to a UserDAOBean which gets an EntityManager injected from JBoss. I'm using the code public void delete(E entity) { em.remove(em.merg...

Which Java based PDF rendering library should I use for printing?

I know about PDFRenderer ICEpdf JPedal Ghostscript to convert PDF->PS, then print with javax.print.* My primary concern is printing a PDF file to a printer. The other features like displaying, PDF modifications, ... are nice-to-have. All libraries promise similar features, but I'm afraid that when I choose one I might encounter prob...

A cycle was detected in the build path of project xxx - Build Path Problem

I'm in the process of converting my projects to OSGI bundles using maven and eclipse. Maven builds the stuff just fine, only I get the above error now within Eclipse. How can I find out which project causes this? Is there a special view or something? How can this happen, I would expect that maven can detect cyclic dependencies as well? ...

jCombobox JPA HQL inner join error.

Hi everyone , i am new at Java , i got a problem like this ; i have got a desktop application , there is 2 jComboBox in JFrame.One of this jComboBox is hold Personels from Personel Table and another is take Personel's title.When jComboBox1's selected index changes occurs it will get personelid and fill jComboBox2 with its title.Thats ...

Get Object from GWT ScrollTable

Right now I'm playing with ScrollTable from GWT Incubator. I'm trying to make functionality when user select one row then click on Edit button and then he will be able to edit that particular Object. Right now I have to check what row has been selected Integer secRowPosition = e.getSelectedRows().iterator().next().getRowIndex(); then ...

Programming Java with Vim

I have tested many editors out there, but Vim makes me addictive. I really wish to use Vim in all of my programming. I just tried to start learning the Java programming language and I have a huge book that I'm trying to start to read for that purpose, but the sad thing about it is that I don't have either a Java compiler or a .class file...

How do I discover which classpath entry provided a class?

I am loading several different classes from several different .jars from a custom class loader in Java. I create a custom URLClassLoader, add several .jars to it and pass it on to a ServiceLoader to find the classes I want. My question is: given a class, is there a way to discover which .jar it was loaded from? ...

Java: What are the necessary environment variables one should set after installing JDK on Windows and how?

This may be self evident to power Java programmers, but may not be so for those who are just starting the Java journey. After downloading JDK from Sun and installing it on Windows, what environment variables should one set to use javac etc.. from command line tools like vi? (see Programming Java with Vim) Also, how does one set environm...

How to include default package in Ant javac Task

When I: <javac srcdir="${src}" destdir="${build.classes.dir}" classpathref="classpath"> <include name="ObjectInDefaultPackage"/> <include name="com/mypackage/**"/> </javac> It will no longer add compile and add the class ObjectInDefaultPackage that's in the default package (ie. it's not packaged, it's sitting on the man ${src}...

Best practice: servlet that uses httpclient to post content

i want to write a java servlet that will be called by different users to do httpclient post content to another side via "POST" . i wanted to hear opinion from guru in this case, do my servlet need to use threadpool or something since i want to serve different users at the same time and each user is executing different httpclient post ...

Why is '//' style multiline comment bad (in Java)?

http://java.sun.com/docs/codeconv/html/CodeConventions.doc4.html#286 I was reading the above section of Java coding convention and started to wonder why it says "// comment.....shouldn't be used on consecutive multiple lines for text comments" Copy pasted the relevant section here for convenience: The // comment delimiter can comment ...

Java's socket.localPort() always reports -1

I have some code which needs to know the local port it uses to connect to a server. The Socket.localPort() call always seems to return -1. Also, do a Socket.toString() returns something like "port=33031,localport=-1" - again, with a -1. Does anyone know why this, and how to get the local side port number? I am GNU Classpath 0.97.2 - i...

How to shrink DB Connection Pool?

I am using Apache DBCP with JNDI in my tomcat container to pool connections to a mysql database. Everything works fine but a problem i am seeing is that once a pconnection is pooled it is never released. So after a load spike connection sit their forever sleeping. Is their a way to shrink the pool through context.xml parameters? here...