Is there a simple method to convert any object to JSON in Android? Answer Most people are using gson : check this
Tag: java
How to handle exceptions in Java Web Applications?
i would like to handle my exceptions in a way to warning the user about the errors that occured . What i know is something like: This is the best approach ? If not, what would you suggest ? Best regards, Valter Henrique. Answer An exception can be handled in different ways. In this case, it seems that the exc…
Returning ZipOutputStream to browser
I have an ZipOutputStream that I want to return to the browser. The experience I would like is that the user clicks an anchor tag, and then a file download prompt is displayed for the ZipOutputStream that I have. How do you get the ZipOutputStream back to the browser? Answer Just had to do this exact same thi…
Windows ignores JAVA_HOME: how to set JDK as default?
How do I persuade Windows to use the JDK instead of a JRE? This question has been asked before, here and elsewhere: How do I set the default Java installation/runtime (Windows)? The trouble is that Windows ignores JAVA_HOME and it also ignores the fact that I made the JDK bin directory the first entry in the …
How to use object oriented programming with Hibernate?
While using ORM tools such as Hibernate, I’ve found it is advantageous to keep all business logic out of my business objects and instead keep it in a service layer. The service layer creates the business object POJOs, manipulates them, and uses DAOs to save them. But isn’t this in a way taking a s…
In which case do you use the JPA @JoinTable annotation?
In which case do you use the JPA @JoinTable annotation? Answer EDIT 2017-04-29: As pointed to by some of the commenters, the JoinTable example does not need the mappedBy annotation attribute. In fact, recent versions of Hibernate refuse to start up by printing the following error: Let’s pretend that you…
How to run a class from Jar which is not the Main-Class in its Manifest file
I have a JAR with 4 classes, each one has Main method. I want to be able to run each one of those as per the need. I am trying to run it from command-line on Linux box. It has directory structure for the main classes as follows: I know that I can specify one class as main in my
Load CSV file located in the classpath for H2 Database
For tests purposes, I want to create and fill some tables using SQL scripts as well as CSV files. So I created a SQL script like this one: The foo.csv file exists, and is located in src/test/resources. When this script is run on Eclipse (where src/test/resources is defined as a source directory and thus is in…
Why is Lucene sometimes not matching InChIKeys?
I have indexed my database using Hibernate Search. I use a custom analyzer, both for indexing and for querying. I have a field called inchikey that should not get tokenized. Example values are: BBBAWACESCACAP-UHFFFAOYSA-N KEZLDSPIRVZOKZ-AUWJEWJLSA-N When I look into my index with Luke I can confirm that they …
How do I set an empty list of a certain type
We have Collections.EMPTY_LIST but it is not typed, which shows an eclipse warning. How do I set an empty list of a certain type. Answer Try this See this also Type-safe, generic, empty Collections with static generics