Why have one JVM per application?

(I assume you are talking about applications launched via a public static void main(String[]) method …) In theory you can run multiple applications in a JVM. In practice, they can interfere with each other in various ways. For example: The JVM has one set of System.in/out/err, one default encoding, one default locale, one set of … Read more

Is Java 100% object oriented? [closed]

When Java first appeared (versions 1.x) the JVM was really, really slow. Not implementing primitives as first-class objects was a compromise they had taken for speed purposes, although I think in the long run it was a really bad decision. “Object oriented” also means lots of things for lots of people. You can have class-based … Read more

Reading and Writing out TIFF image in Java

The easiest way to read in a TIFF and output a BMP would be to use the ImageIO class: BufferedImage image = ImageIO.read(inputFile); ImageIO.write(image, “bmp”, new File(outputFile)); The only additional thing you would need to do to get this to work is make sure you’ve added the JAI ImageIO JARs to your classpath, since BMP … Read more

Get actual type of generic type argument on abstract superclass

It’s definitely possible to extract it from Class#getGenericSuperclass() because it’s not defined during runtime, but during compiletime by FooDao extends BaseDao<Foo>. Here’s a kickoff example how you could extract the desired generic super type in the constructor of the abstract class, taking a hierarchy of subclasses into account (along with a real world use case … Read more

how to copy data from file to PostgreSQL using JDBC?

This works… import java.io.FileReader; import java.sql.Connection; import java.sql.DriverManager; import org.postgresql.copy.CopyManager; import org.postgresql.core.BaseConnection; public class PgSqlJdbcCopyStreamsExample { public static void main(String[] args) throws Exception { if(args.length!=4) { System.out.println(“Please specify database URL, user, password and file on the command line.”); System.out.println(“Like this: jdbc:postgresql://localhost:5432/test test password file”); } else { System.err.println(“Loading driver”); Class.forName(“org.postgresql.Driver”); System.err.println(“Connecting to ” + args[0]); … Read more

How can I reliably simulate touch events on Android without root (like Automate and Tasker)?

As suggested, the best way to simulate touch events since Nougat (API 24) is by using an accessibility service and the AccessibilityService#dispatchGesture method. Here is how I did to simulate a single tap event. // (x, y) in screen coordinates private static GestureDescription createClick(float x, float y) { // for a single tap a duration … Read more

Regex that Will Match a Java Method Declaration

(public|protected|private|static|\s) +[\w\<\>\[\]]+\s+(\w+) *\([^\)]*\) *(\{?|[^;]) I think that the above regexp can match almost all possible combinations of Java method declarations, even those including generics and arrays are return arguments, which the regexp provided by the original author did not match.