I’m trying to have a custom date format in Gson output, but .setDateFormat(DateFormat.FULL) doesn’t seem to work and it the same with .registerTypeAdapter(Date.class, new DateSerializer()). It’s like Gson doesn’t care about the object “Date” and print it in its way. How can…
Tag: java
SLP Java function causing SocketException due to IP_MULTICAST_IF
I’m attempting to use Java to find a SLP service named test, that is running on my network and create a connection to it. I know the service is running and can use the command “slptool findsrvs service:test” to find it. This command returns “service:test://192.168.1.4:12345,65535”…
How netbeans stops a run?
I’m programming with Java in Linux using Netbeans 7 and as my program (sometimes) could not exit (not in this eon, maybe) I create a thread to handle shutdown But when I launch the code with netbeans (F6) and stop it through the “STOP” button the thread is not created; but if I run the progr…
Why does SSL handshake give ‘Could not generate DH keypair’ exception?
When I make an SSL connection with some IRC servers (but not others – presumably due to the server’s preferred encryption method) I get the following exception: Final cause: An example of a server that demonstrates this problem is aperture.esper.net:6697 (this is an IRC server). An example of a se…
Why is subtracting these two times (in 1927) giving a strange result?
If I run the following program, which parses two date strings referencing times 1 second apart and compares them: The output is: Why is ld4-ld3, not 1 (as I would expect from the one-second difference in the times), but 353? If I change the dates to times 1 second later: Then ld4-ld3 will be 1. Java version: …
Java / Hibernate – Write operations are not allowed in read-only mode
I’ve been having an annoying exception a lot lately, and after some research on Google and this forum I still haven’t found an answer that could solve my problem. Here’s the thing – sometimes, I get the following error when trying to update or create a new object with hibernate: What i…
Eclipse – Show generated class files
How can I show the folder (bin) where my class files are placed after I build a project in eclipse? I want this directory to show up in the package explorer. Searched the forums, but can’t seem to find an answer Answer You can view the the bin folders in the Navigator (Window –> Show View ̵…
Generic type as parameter in Java Method
Do you think it is possible to create something similar to this? Answer Yes, you can. Usage example:
How to properly determine whether an “exists” JPA Criteria Query clause returned true or false?
I don’t know how to perform a JPA criteria query that returns with a boolean output. The goal is to have a criteria query that looks like this when rendered on Oracle: The where exists (…) part I performed with a subquery. I’m struggling with the external query. The practical use of this is …
How can I handle precision error with float in Java?
I’m wondering what the best way to fix precision errors is in Java. As you can see in the following example, there are precision errors: The result displayed is: loop value: 11 20.789999 loop value: 22 41.579998 loop value: 44 83.159996 loop value: 88 166.31999 loop value: 176 332.63998 loop value: 352 …