Month: October 2015

Java Details

Nice Java Tutorials

http://tutorials.jenkov.com (Excellent multi-threading tutorial)

1. Advantages/Disadvantages of using Linked List for HashMap implementation in Java

http://openjdk.java.net/jeps/180

http://stackoverflow.com/questions/27336084/why-does-java-util-hashmap-use-a-linked-list-internally

2.    Serialization/Deserialization process; Difference between Serializable and Externalizable Interfaces

https://javarevisited.blogspot.com/2014/10/how-to-use-locks-in-multi-threaded-java-program-example.html

https://javarevisited.blogspot.com/2013/12/inter-thread-communication-in-java-wait-notify-example.html

https://javarevisited.blogspot.com/2018/07/java-multi-threading-interview-questions-answers-from-investment-banks.html

http://tutorials.jenkov.com/java-concurrency/blocking-queues.html

3. Copy Constructor, Volatile, Cloneable, Comparable, Comparator

4. Memory Leaks in Java

http://stackoverflow.com/questions/313730/is-a-good-idea-to-enable-jmx-lambda-probe-on-a-production-server

https://dzone.com/articles/how-fix-memory-leaks-java

http://developerblog.redhat.com/2014/08/14/find-fix-memory-leaks-java-application/

http://www.dynatrace.com/en/javabook/memory-leaks.html

http://apmblog.dynatrace.com/2013/05/07/fix-memory-leaks-in-java-production-applications/

http://frankkieviet.blogspot.ca/2006/10/classloader-leaks-dreaded-permgen-space.html

http://frankkieviet.blogspot.ca/2006/10/how-to-fix-dreaded-permgen-space.html

5. Application Performance Problems debugging

https://blog.appdynamics.com/apm/finding-the-root-cause-of-application-performance-issues-in-production/

http://karunsubramanian.com/uncategorized/top-10-reasons-why-your-enterprise-java-application-is-slow/

http://www.javaworld.com/article/2078912/build-ci-sdlc/troubleshooting-java-enterprise-application-performance.html

http://stackoverflow.com/questions/3558486/how-to-determine-why-is-java-app-slow

6. Equals and Hashcode

http://www.artima.com/lejava/articles/equality.html

http://www.angelikalanger.com/Articles/JavaSolutions/SecretsOfEquals/Equals.html

http://javarevisited.blogspot.sg/2013/08/10-equals-and-hashcode-interview.html

7.  Garbage Collection

http://stackoverflow.com/questions/3796427/in-java-is-permanent-generation-space-garbage-collected

8.  Where are Static Variables Stored?

http://stackoverflow.com/questions/2142192/java-where-do-static-fields-live-within-the-memory

9.  Calling member functions from constructor?

http://stackoverflow.com/questions/18138397/calling-method-from-constructor

http://stackoverflow.com/questions/18348797/why-is-it-considered-bad-practice-to-call-a-method-from-within-a-constructor?lq=1

10. Why is String immutable in java

http://programmers.stackexchange.com/questions/195099/why-is-string-immutable-in-java

http://java-performance.info/changes-to-string-java-1-7-0_06/

11. Synchronizing on string objects

http://stackoverflow.com/questions/133988/problem-with-synchronizing-on-string-objects

12.  Java clone

http://javarevisited.blogspot.in/2015/01/java-clone-tutorial-part-2-overriding-with-mutable-field-example.html

http://www.coderanch.com/t/568144/java/java/Cloneable-interface-Subclasses

http://howtodoinjava.com/2012/11/08/a-guide-to-object-cloning-in-java/#cloning_using_copy_constructors

http://www.xenoveritas.org/blog/xeno/java_copy_constructors_and_clone

13.  Mutable and Immutable Classes/Objects

http://www.javaranch.com/journal/2003/04/immutable.htm

http://stackoverflow.com/questions/4658453/difference-between-mutable-objects-and-immutable-objects

14.  String concatenation

http://stackoverflow.com/questions/47605/string-concatenation-concat-vs-operator

15. Aggregation vs Composition

http://programmers.stackexchange.com/questions/61376/aggregation-vs-composition

16. Design Patterns in Java

http://javarevisited.blogspot.in/2015/01/adapter-vs-decorator-vs-facade-vs-proxy-pattern-java.html

http://stackoverflow.com/questions/1673841/examples-of-gof-design-patterns-in-javas-core-libraries

http://stackoverflow.com/questions/3649754/examples-of-design-patterns-used-in-jdk?lq=1

http://stackoverflow.com/questions/70689/what-is-an-efficient-way-to-implement-a-singleton-pattern-in-java?lq=1

http://stackoverflow.com/questions/3541077/design-patterns-web-based-applications?lq=1

http://stackoverflow.com/questions/1673841/examples-of-gof-design-patterns-in-javas-core-libraries

17.  What does the following Java program print?

public class Test {
    public static void main(String[] args) throws Exception {
        char[] chars = new char[] {'\u0097'};
        String str = new String(chars);
        byte[] bytes = str.getBytes();
        System.out.println(Arrays.toString(bytes));
    }
}

Answer: The trikyness of this question lies on character encoding and how String to byte array conversion works. In this program, we are first creating a String from a character array, which just has one character ‘\u0097’, after than we are getting byte array from that String and printing that byte. Since \u0097 is within the 8-bit range of byte primitive type, it is reasonable to guess that the str.getBytes() call will return a byte array that contains one element with a value of -105 ((byte) 0x97). However, that’s not what the program prints and that’s why this question is tricky. As a matter of fact, the output of the program is operating system and locale dependent. On a Windows XP with the US locale, the above program prints [63], if you run this program on Linux or Solaris, you will get different values.

To answer this question correctly, you need to know about how Unicode characters are represented in Java char values and in Java strings, and what role character encoding plays in String.getBytes(). In simple word, to convert a string to a byte array, Java iterate through all the characters that the string represents and turn each one into a number of bytes and finally put the bytes together. The rule that maps each Unicode character into a byte array is called a character encoding. So It’s possible that if same character encoding is not used during both encoding and decoding then retrieved value may not be correct. When we call str.getBytes() without specifying a character encoding scheme, the JVM uses the default character encoding of platform to do the job. The default encoding scheme is operating system and locale dependent. On Linux, it is UTF-8 and on Windows with a US locale, the default encoding is Cp1252. This explains the output we get from runing this program on Windows machines with a US locale. No matter which character encoding scheme is used, Java will always translate Unicode characters not recognized by the encoding to 63, which represents the character U+003F (the question mark, ?) in all encodings.

Read more: http://java67.blogspot.com/2012/09/top-10-tricky-java-interview-questions-answers.html#ixzz3pjNm7zms

18. compareTo

http://javarevisited.blogspot.sg/2011/11/how-to-override-compareto-method-in.html

19.  ThreadPool

http://oppansource.com/implementing-own-thread-pool-in-java/

http://tutorials.jenkov.com/java-concurrency/thread-pools.html

20. Performance implications of final keyword

http://stackoverflow.com/questions/3961881/why-defining-class-as-final-improves-jvm-performance

http://www.javamex.com/tutorials/java_final_performance.shtml

http://stackoverflow.com/questions/3961881/why-defining-class-as-final-improves-jvm-performance

21.  Why should variables accessed in anonymous inner class be declared final

http://stackoverflow.com/questions/1299837/cannot-refer-to-a-non-final-variable-inside-an-inner-class-defined-in-a-differen?rq=1

22.  https://stackoverflow.com/questions/11881548/jpa-or-jdbc-how-are-they-different

23.  Java8 features   http://www.journaldev.com/2389/java-8-features-with-examples

https://www.javatpoint.com/java-8-features

24.  Java Generics :  http://javarevisited.blogspot.in/2012/04/what-is-bounded-and-unbounded-wildcards.html

https://www.tutorialspoint.com/java_generics/java_generics_upper_bounded.htm

https://docs.oracle.com/javase/tutorial/java/generics/lowerBounded.html

25.  WeakHashMap  https://www.tutorialspoint.com/java/java_weakhashmap_class.htm

26.  BlockingQueue (Producer Consumer Problem)  http://www.journaldev.com/1034/java-blockingqueue-example

27.  https://stackoverflow.com/questions/2599440/how-can-i-access-a-private-constructor-of-a-class

28.  Spring Boot: https://stackoverflow.com/questions/32997352/what-is-the-diference-between-putting-a-property-on-application-yml-or-bootstrap

29. Spring Boot Actuator

30. How to expose an endpoint with spring boot

31.  https://stackoverflow.com/questions/19738977/how-is-the-internal-implementation-of-linkedhashmap-different-from-hashmap-imple

32.  https://stackoverflow.com/questions/3929361/how-to-wait-for-all-tasks-in-an-threadpoolexecutor-to-finish-without-shutting-do