java

How do I do timers in Java?

I'm implementing the x-modem protocol in Java. If there is a timeout while I'm receiving a packet then I have to send negative acknowledgment. I have to start a timer, and when the time is up then I send a message to the sender requesting file transfer from the begining. But I'm not getting how to do timers in Java; may I see some sampl...

How do I cap my framerate at 60 fps in Java?

I am writting a simple game, and I want to cap my framerate at 60 fps without making the loop eat my cpu. How would I do this? ...

How do I get at the sql statement that caused an SQLException using the Postgres JDBC driver in Java?

Background In my current project - a server product with no GUI front-end, I'm trying to write in better error handling support. Errors currently are outputted to the logs and are typically not read by users. We use PostgreSQL as our database backend and we access it using direct JDBC calls and DAOs via a database pooler. Most database...

What is mutex and semaphore in Java ? What is the main difference ?

What is mutex and semaphore in Java ? What is the main difference ? ...

Is there any way to get a WordprocessingML Clipboard content in java?

I've got a customer who managed it to paste WordprocessingML content into our application. As far as I know it was a direct copy&paste from Word 2000 to our Java application. I tried every Word and Java Version combination, but I can't reproduce this behavior - especially, since our application filters for HTML and text/plain. I'm prett...

Escape analysis in Java

As far as I know the JVM uses escape analysis for some performance optimisations like lock coarsening and lock elision. I'm interested if there is a possibility for the JVM to decide that any particular object can be allocated on stack using escape analysis. Some resources make me think that I am right. Is there JVMs that actually do it...

Java save function doesn't work

hey, I have this code that should save a java.util.Vector of custom serializable classes: if(filename.equals("")){ javax.swing.JFileChooser fc = new javax.swing.JFileChooser(); if(fc.showSaveDialog(this) == javax.swing.JFileChooser.APPROVE_OPTION){ filename = fc.getSelectedFile().toString(); } } try{ java.io.FileOutputStream fos =...

Why SerialEvent.RI doesn't work?

Hi, I have two computers running this code: import java.io.; import java.util.; import gnu.io.*; public class Deb implements SerialPortEventListener, Runnable{ public static final int TIMEOUTSECONDS = 30; public static final int BAUD = 9600; static String telefono; static Boolean llamar = false; CommPortIdentifier cpiModem = null; ...

Java: Why doesn't binary OR work as expected (see code below)?

I don't understand the output from the following code: public static void main(String[] args) { int i1, i2, i3, i4; byte b; i1 = 128; b = (byte) i1; i2 = (int) b; i3 = 0 | b; i4 = 1 << 7; System.out.format("i1: %d b: %d i2: %d i3: %d i4: %d\n", i1, b, i2, i3, i4); } Output: i1: 128 b: -128 ...

Whats the overhead of creating a Log4j Logger

I have some webservices in my application and i want to log them to diferent files, based on the webservice name. For that i am creating loggers with myLogger = Logger.getLogger(logKey); I am wondering if i should cache these loggers to avoid creating them for every call, or can i ignore the overhead. ...

Which job? C or ASP.NET/C#?

Hello, I've got two jobs offerings - C programmer (for middle-sized company) and ASP.NET/C# programmer (for starup company). Salary is the same. Which one would you choose and why? I mean what would be better for future carrer, for future job-hunting, etc. I've been learning java for some months and would like to work as a java develop...

When casting a small integer type to a wider one, is it safe to rely on &ing with a mask to remove the sign?

I have code that stores values in the range 0..255 in a Java byte to save space in large data collections (10^9 records spread over a couple hundred arrays). Without additional measures on recovery, the larger values are interpreted as being negative (because the Java integer types use two's complement representation). I got this helpf...

Problem in printing Jpanel Data

I am working on a swings application I have a Jpanel, I am facing serious problem with printing this JPanel data with "card printer". This is working fine when i using paper color printer but when i am using card printer its printing nothing. I have tested the printer using some Images and it is printing fine when i print any Image direc...

Problem with ring event in serial port communication

Hi, I have a modem in a computer where there is running a program that dials a number or waits for a call. When dialing a number the modem works fine, but I doesn't detect the Ring event when it's the one being called. My program is in java and it works perfectly on my laptop with its modem. When I use the modem to receive a fax, it wor...

Help with really odd Java GC behavior

I have a Java web app running on JBoss behind Apache (via mod_jk) and I'm seeing some really odd GC behavior. I've attached a graph of it to this question. Has anyone seen similar GC behavior before? It's Java 6 running with default GC tuning from ergonomics on a server-class machine. Thanks. NOTE: The above image is a link to the ful...

what is context object design pattern ?

what is context object design pattern ? ...

Handling collections with mixed POJOS, with different handler for each POJO

I'm trying to find an elegant OOP solution for the following problem. Assume we have a collection of POJOS, events in this case, where each POJO is possibly different class. We need to process this collection, using different rules for each POJO class (or type). A basic assumption is that we can't decorate the POJOs with appropriate h...

Best Java web application framework for a PHP developer?

I had been life long PHP developer. But am now forced to write in Java (or at least on JVM) the final version of a prototyped PHP web application. Would like to add that I am not quite unfamiliar with Java. Wrote applets in the old days. Besides, am familiar with most other scripting languages, plus RoR. But web app in Java is making m...

What is the best way of relating relational database tables into Java classes?

Hello I wonder if anyone can advise me here; I have an application which has classes like this: Code: public class Order implements Serializable { private int orderNo; private int customerNo; private date orderDate; public int getOrderNo () { return orderNo; } public int getCustomerNo () ...

How do I view Ant scripts that eclipse uses?

I am having a bit of trouble building my project with Ant. I wanted to take a look at the Ant scripts that eclipse uses to build my project. How can I do this? ...