Skip to content

Tag: java

Use jsf as template engine on EAR

Thinking about html e-mails for our e-commerce site I thought about reusing jsf and other 3rd party libraries as a template engine to create the e-mails on our application server (Glassfish 3, EAR). Is it possible to manually run jsf with a local file and initialize the necessary bean to capture the html outp…

java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject Error

I am getting following error Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject at OrderBook.WriteToExcelSheet.CreateOutPutFile(WriteToExcelSheet.java:20) at OrderBook.MainMethod.main(MainMethod.java:71) I looked for the reasons for this error online but could…

Volatile variable explanation in Java docs

when a thread reads a volatile variable, it sees not just the latest change to the volatile, but also the side effects of the code that led up the change This is mentioned at http://docs.oracle.com/javase/tutorial/essential/concurrency/atomic.html Can someone please provide an example of this? This first gave…

How to exit a while loop after a certain time?

I have a while loop and I want it to exit after some time has elapsed. For example: Answer Thus the statement Checks if it has been 10 seconds or 10,000 milliseconds since the loop started. EDIT As @Julien pointed out, this may fail if your code block inside the while loop takes a lot of time.Thus using Execu…

Open CSV to export resultset to string type

I want to export the result set of the SQL query to a CSV file. I am using opencsv to export to CSV file. I am using below code to achieve it. But the problem I face is, it automatically exports to the datatype of the database column which is from resultset. Example: if I a column with datatype as

Java – Counting numbers in array

I’ve written a java prog that stores some values: which generate such output: 0:2 1:3 2:4 3:5 4:4 5:4 6:3 and now I need to count numbers in this output #1. Output #2 should be this: 1: 0 2: 1 3: 2 4: 3 5: 1 It means it counts ONE 2, TWO 3, THREE 4, and only One 5.

Test Coverage: How to cover assertions?

EDIT: So It looks like JeffStorey link to the bug is correct. With assertions enabled the compiler will generate extra code. There ends up being 1 extra unreachable branch created. One of my methods constructor has these asserts I’m trying to cover it by doing this And again with values Board (-4 , 2) a…

How to pass an object from front-end to Struts 2

I am trying to send value of a field to Struts2 back-end through JavaScript but it returns NullpointerException. Once form is submitted the request will be sent to the following JavaScript method to be sent to back-end. the request will be created and sent as following But in back-end when I try to show the v…