Sunday, October 26, 2014

DIFFERENCE BETWEEN HIBERNATE FLUSH AND COMMIT

Flushing the Session simply makes the data that is currently in the session synchronized with what is in the database.
However, just because you have flushed, doesn’t mean the data can’t be rolled back.
Commit does flush the session, but it also ends the unit of work.
To summarize commit does two things,
1. Commit internally does flush
2. Ends the unit of work (makes the changes permanent).
FLUSH:
Flushing the Session simply gets the data that is currently in the session synchronized with what is in the database. However, just because you have flushed, doesn’t mean the data can’t be rolled back.
Hibernate will flush changes automatically for you:
before query executions
when a transaction is committed
Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory.
COMMIT:
Commit does flush the session, but it also ends the unit of work

Thursday, October 23, 2014

Notepad++ Multi editing

Yes: simply press and hold the Alt key, click and drag to select the lines whose columns you wish to edit, and begin typing.
You can also go to Settings > Preferences..., and in the Editing tab, turn on multi-editing, to enable selection of multiple separate regions or columns of text to edit at once.
It's much more intuitive, as you can see your edits live as you type.

Tuesday, October 21, 2014

Does a method's signature in Java include its return type?

Quoting from Oracle Docs:
Definition: Two of the components of a method declaration comprise the method signature—the method's name and the parameter types.
enter image description here
Since the question was edited to include this example:
public class Foo {
    public int  myMethod(int param) {}
    public char myMethod(int param) {}
}
No, the compiler won't know the difference, as their signature: myMethod(int param) is the same. The second line:
    public char myMethod(int param) {}
will give you can error: method is already defined in class, which further confirms the above statement.

Wednesday, October 15, 2014

Maven does not find JUnit tests to run

By default Maven uses the following naming conventions when looking for tests to run:
  • Test*
  • *Test
  • *TestCase
Your test class doesn't follow these conventions. You should rename it or configure Maven Surefire Plugin to use another pattern for test classes.

Tuesday, October 7, 2014

How to run a JAR file

You need to specify a Main-Class in the jar file manifest.
Sun's tutorial contains a complete demonstration, but here's another one from scratch. You need two files:
Test.java:
public class Test
{
    public static void main(String[] args)
    {
        System.out.println("Hello world");
    }
}
manifest.mf:
Manifest-version: 1.0
Main-Class: Test
Then run:
javac Test.java
jar cfm test.jar manifest.mf Test.class
java -jar test.jar
Output:
Hello world
http://stackoverflow.com/questions/1238145/how-to-run-a-jar-file

Cannot make Project Lombok work on Eclipse (Helios)

After adding lombok and restarting eclipse or spring tools my project still failed to recognize getters and setters. Red markers everywhere!
The solution: right-click your project, go to Maven and select Update Project
After hours of searching and trying random solution, I find this to be the only solution that worked for me.
enter image description here

Friday, October 3, 2014

How do you rotate a two dimensional array?

O(n^2) time and O(1) space algorithm ( without any workarounds and hanky-panky stuff! )
Rotate by +90:
  1. Transpose
  2. Reverse each row
Rotate by -90:
  1. Transpose
  2. Reverse each column
Rotate by +180:
Method 1: Rotate by +90 twice
Method 2: Reverse each row and then reverse each column
Rotate by -180:
Method 1: Rotate by -90 twice
Method 2: Reverse each column and then reverse each row
Method 3: Reverse by +180 as they are same