Skip to content
Advertisement

Tag: java

Thread is interrupted by calling interrupt(), but Thread.isInterrupted() returns false

I am testing InterruptedException with the following test code: In run() , I interrupt() current working thread, and caught a InterruptedException. In main thread, my last line of code is a System.out.println(…) which prints out the interrupt status of working thread. Since I have caught InterruptedException in run(), I though I should get the message that workingThread.isInterrupted() is true, but

Remove hardcoded file path from java program

I have created a simple java program in which I create a text file and read the data written in it. The problem is that I don’t want to hardcode the path of the file because after developing the application I created a installer package for my program which allows users to install it on their systems. Now the problem

Play framework, Different constraints for different requests

How to implement different constraints for different requests? For example, there is User class: When I create a new user, all constraints are required. But when I update user information, I don’t need the password constraint. Should I create separate classes for createUser() and updateUser() actions? Is there any way I can use just one class? Answer As Play’s validation

javax.transaction.Transactional vs org.springframework.transaction.annotation.Transactional

I don’t understand what is the actual difference between annotations javax.transaction.Transactional and org.springframework.transaction.annotation.Transactional? Is org.springframework.transaction.annotation.Transactional an extension of javax.transaction.Transactional or they have totally different meaning? When should each of them be used? Spring @Transactinal in service layer and javax in DAO? Thanks for answering. Answer Spring has defined its own Transactional annotation to make Spring bean methods transactional, years ago.

Why write Try-With-Resources without Catch or Finally?

Why write Try without a Catch or Finally as in the following example? Answer As explained above this is a feature in Java 7 and beyond. try with resources allows to skip writing the finally and closes all the resources being used in try-block itself. As stated in Docs Any object that implements java.lang.AutoCloseable, which includes all objects which implement

Do you need a database transaction for reading data?

When I try to read data from the database, at least using ((Session)em.getDelegate()).createCriteria() an exception is throws saying that a transaction is not present. When I add the annotation: it works fine. However, since reading will happen million of times per second to access and read data, I want to make sure that our environment is not clogged up unnecessarily.

SQLite 64bit integers recognized as ints in jooq

I have an SQLite database that I am using with jOOQ. When I use jOOQ’s code generation tool, it builds all of the table and record classes as expected. However, all of the SQLite INTEGER columns turn into java.lang.Integer fields in the generated code. The problem is that SQLite INTEGER’s can store up to a 64 bit signed integer, where

Basic Java Hangman

I am just starting to learn Java as my first programming language. In class we were assigned to make a basic Hangman game with the use of a while and for loops. What I have so far When the user inputs the first guess it does recognize that that characters that he/she guessed was corrected but just continues on and

Advertisement