Saturday, 12 March 2016

10 Hibernate Interview Questions and Answers for Java J2EE Programmers

Hibernate Interview Questions are asked on Java J2EE Interviews, mostly for web based enterprise application development role. Success and acceptability of Hibernate framework on Java world have made it one of the most popular Object Relational Mapping (ORM) solution in Java technology stack. Hibernate frees you from database-specific coding and allows you to focus more on utilizing powerful object oriented design principle to implement core business logic. By using Hibernate you can switch between database rather easily and also take advantage of out of box caching facilities provided by Hibernate, in terms of second-level cache and query cache. It also frees Java developer from writing JDBC code as Hibernate takes care of that. In short, provides a complete solution to implement DAO layer of your Java or JEE application. 
Read more »

How to Reverse a String in place in Java - Example

It's possible to reverse a String in place by using a StringBuilder. Since String is Immutable in Java, it's not possible to reverse the same String, but you can minimize the number of intermediate String objects by using StringBuilder or StringBuffer, which are mutable. The algorithm to reverse the String in place is similar to the algorithm we have used earlier to reverse an array in place. You need to traverse the String from one end, swapping characters at another end until you reach the middle of the String. At the point characters in your String is reversed. This algorithm only requires one extra character of memory to facilitate the swapping of characters. The time complexity of this algorithm is O(n/2) i.e. O(n) where n is the length of String.
Read more »

Friday, 11 March 2016

How to Remove First and Last Character of String in Java - Example Tutorial

You can use the substring() method of java.lang.String class to remove the first or last character of String in Java. The substring() method is overloaded and provides a couple of versions which allows you to remove a character from any position in Java. Alternatively, you can convert String to StringBuffer or StringBuilder and then use its remove() method to remove the first or last character. Both StringBuffer and StringBuilder provides a convenient deleteCharAt(int index) method which removes a character from the corresponding index. You can use this method to remove both first and last character from String in Java. In the last article, I have showed you how to get the first and last character from String and today I will teach you how to remove the first and last character of String in Java. Let's see a couple of examples and how you can use these two techniques to solve this problem.
Read more »

Wednesday, 9 March 2016

Top 50 Java Thread Interview Questions Answers for Experienced

You go to any Java interview, senior or junior, experience or freshers,  you are bound to see a couple of questions from the thread, concurrency, and multi-threading. In fact, this built-in concurrency support is one of the strongest points of Java programming language and helped it to gain popularity among enterprise world and programmers equally. Most of lucrative Java developer position demands excellent core Java multi-threading skills and experience in developing, debugging and tuning high-performance low latency concurrent Java applications. This is the reason, it is one of the most sought after skill on Java interviews. The multithreading and concurrency are also hard to master concept and only good developers with solid experience can effectively deal with concurrency issues.
Read more »

Sunday, 6 March 2016

How to convert an Array to HashSet in Java - Example Tutorial

The array was there in Java before the Collection framework makes its entry in JDK 1.4, hence, you will find several legacy code, which accepts array than the Collection or Set. Due to this, we often need to convert an array to different types of collection e.g. List or Set. Earlier, I have told you the trick to convert an array to list and today I'll teach you how to convert an array to HashSet by using the same technique. The concept you need to know is that Collection provides a copy constructor i.e. you can pass a collection to create another collection. We'll leverage the same fact and to create an HashSet, we'll pass an ArrayList. Since you can use Arrays.asList() to convert an array to ArrayList, converting an array to HashSet is just two step job, first convert an array to a list and then convert a list to set.
Read more »

Saturday, 5 March 2016

3 Books to Learn Eclipse IDE for Java JEE Programmers - Best of Lot

In order to become a good Java developer solid knowledge of Eclipse IDE, or whatever IDE you use e.g. Netbeans or IntelliJ Idea, is a must. Java has been blessed with excellent tooling which turbo-charge application development. IDEs or Integrated Development Environment allows you to code, run, test and debug from just one tool. They are the immense productivity booster. Since I have started Java development coding in Notepad, TextPad, and JCreator, I know how it feels having the power of IDEs with you. There are three big IDEs in Java world, Eclipse, NetBeans and IntelliJ Idea. First two are free and third one requires the license. I use Eclipse and it's also the most popular IDE in Java world.
Read more »

Thursday, 3 March 2016

Difference between map() and flatMap() in Java 8 Stream

The map() and flatmap() are two important operations in new functional Java 8. Both represents functional operation and they are also methods in java.util.stream.Stream class. The key difference between map() and flatmap() function is that when you use map(), it applies a function on each element of stream and stores the value returned by the function into a new Stream. This way one stream is transformed into another e.g. a Stream of String is transformed into a Stream of Integer where each element is length of corresponding Stream. Key thing to remember is that the function used for transformation in map() returns a single value. If map() uses a function, which, instead of returning a single value returns a Stream of values than you have a Stream of Stream of values, and flatmap() is used to flat that into a Stream of values.
Read more »