When I send the jasper report to print, the printer shows the document name as “jasper report-report name” (When there is a printing que, document name is also “jasper report” ). How can I change it to another name? Answer Using JasperReports API If you are using JasperReports API you …
Tag: java
Which is fast URLConnection or Socket
For getting data from remote url which connection type will work fast URLConnection or Socket. Answer Both have different purposes, depending upon your need A socket can implement almost a duplex kind of functionality, whereas a url connection can connect to a given URI and read its content.
What’s the console.log() of java?
I’m working on building an Android app and I’m wondering what the best approach is to debugging like that of console.log in javascript Answer The Log class: API for sending log output. Generally, use the Log.v() Log.d() Log.i() Log.w() and Log.e() methods. The order in terms of verbosity, from lea…
Are static setter/getters allowed?
I am develoing a Web Application, in that there is a utility method named getData() which I made it as a static. Until now its fine, but this static method named getData() needs some data from setters and getters. So now my question is can we make setter/getters as static? Answer If your properties are static…
H2 database error: Database may be already in use: “Locked by another process”
I am trying to use the H2 database from a Java application. I created the database and its tables through the H2 Console and then I try to connect from Java using However I receive the following error: Exception in thread “main” org.h2.jdbc.JdbcSQLException: Database may be already in use: “…
How to convert enum value to int?
I have a function which return a type int. However, I only have a value of the TAX enumeration. How can I cast the TAX enumeration value to an int? Answer You’d need to make the enum expose value somehow, e.g. (I’ve changed the names to be a bit more conventional and readable, btw.) This is assumi…
Split using a bracket
How can I split a string using [ as the delimiter? if I do I get an error Exception in thread “main” java.util.regex.PatternSyntaxException: Unclosed character class near index 1 [ Any help? Answer The [ is a reserved char in regex, you need to escape it,
How to avoid java.util.ConcurrentModificationException when iterating through and removing elements from an ArrayList
I have an ArrayList that I want to iterate over. While iterating over it I have to remove elements at the same time. Obviously this throws a java.util.ConcurrentModificationException. What is the best practice to handle this problem? Should I clone the list first? I remove the elements not in the loop itself …
Using Mockito with multiple calls to the same method with the same arguments
Is there a way to have a stubbed method return different objects on subsequent invocations? I’d like to do this to test nondeterminate responses from an ExecutorCompletionService. i.e. to test that irrespective of the return order of the methods, the outcome remains constant. The code I’m looking …
Android Get Current timestamp?
I want to get the current timestamp like that : 1320917972 Answer The solution is :