I need to format the date into a specific string. I used SimpleDateFormat class to format the date using the pattern “yyyy-MM-dd’T’HH:mm:ssZ” it returns current date as “2013-01-04T15:51:45+0530” but I need as “2013-01-04T15:51:45+05:30”. Below is the coding use…
Tag: java
how to test Comparator at junit test
I need to test this method – compare(). Can You get advice? How better I can do this(all part if, else-if, else). After this recomendations – we have next picture (Thank YOU guys a lot!): All is normal testing now. Answer Just instantiate your comparator class and pass in objects:
How to create entity classes using database for all the existing tables?
I am having tables created by a DBA and I intend to have entity classes for each table for further querying. Can any one suggest how to automatically create the entity classes using Eclipse? Answer If you use JPA for persistence, you can use “JPA tools” provided by Eclipse to generate java entity …
Java division by zero doesnt throw an ArithmeticException – why?
Why doesn’t this code throw an ArithmeticException? Take a look: I have no idea! Answer Why can’t you just check it yourself and throw an exception if that is what you want.
MySQL Batchupdate() with ON DUPLICATE KEY UPDATE
I am using batchUpdate() to insert multiple records in a table. As per the requirement, if there is a duplicate value for a primary key while inserting it should be updated with the latest received data, hence I was trying to use ON DUPLICATE KEY UPDATE in INSERT statement. The ON DUPLICATE KEY UPDATE works g…
Why can I not use “super” variable from a static context, even though “super” refers to the parent class and NOT a class instance, unlike “this”?
I’m talking java language. Variable “this”, when used inside a class, refers to the current instance of that class, which means you cannot use “this” inside a static method. But “super”, when used inside a class, refers to the superclass of that class, not an instance…
Error occurred during initialization of VM (java/lang/NoClassDefFoundError: java/lang/Object)
I’m trying to install Java to use Eclipse (I followed all instructions to install Java and Eclipse) but my Eclipse is not starting due to some bad configuration I guess. I can’t figure out why it’s not working for me. Eclipse Installation: Extracted Eclipse at C:eclipse Created a shortcut to…
How to prevent SQL Injection with JPA and Hibernate?
I am developing an application using hibernate. When I try to create a Login page, The problem of Sql Injection arises. I have the following code: How will i prevent Sql Injection in this scenario ?The create table syntax of loginInfo table is as follows: Answer You have other options too, see this nice artic…
Eclipse autogenerated toString() method
As par as I know concatinate String using + sign is not a good practice when you have large number of String. But when I check on eclipse generated toString() method (Write click on source file -> Source -> Generate toString() ) it has the same. Is there any place to configure like my expected toString(…
Setting file permissions returns FALSE always
The code: On Ubuntu all 3 calls return false. On my Windows only the 3rd call to setWritable returns false. The target is to create the file/dir so the user (tomcat) and the group will be able to read/write. BUT the file created on Ubuntu without permissions for the group to write. Answer I found the solution…