HTML

Top 23 Spring MVC Framework Interview Questions Answers - Java JEE

Spring Interview Questions Answers 
Spring Interview Question is one of the first things Java programmer should prepare before appearing on any Java or Spring interview. With growing popularity of Spring framework in Java world, Interview questions on Spring are getting more important day by day. For those who don't know, Spring framework is one of the most popular Java programming framework, which not only provided dependency Injection and Inversion of Control but also provides useful API to Java programmers. Spring framework is divided into many different modules e.g. Spring MVC, Spring Integration, Spring Batch, Spring LDAP, Spring Security and several other modules.

Difference between Abstraction and Encapsulation in Java - OOPS

Abstraction vs Encapsulation – Java OOPS
Abstraction and Encapsulation in Java are two important Object oriented programming concept and they are completely different to each other. Only similarity between Abstraction and Encapsulation is that they are OOPS concept, other than that they mean two different things. Abstraction represent taking out the behavior from How exactly its implemented, one example of abstraction in Java is interface while Encapsulation means hiding details of implementation from outside world so that when things change no body gets affected. One example of Encapsulation in Java is private methods; clients  don't care about it, You can change, amend or even remove that method  if that method is not encapsulated and it were public all your clients would have been affected. Apart from this main difference in behavior here are couple of more differences between Abstraction and Encapsulation in Java.

Can we override static method in Java - Method Hiding

Can we override static method in Java
No, you cannot override static method in Java because method overriding is based upon dynamic binding at runtime and static methods are bonded using static binding at compile time. Though you can declare a method with same name and method signature in sub class which does look like you can override static method in Java but in reality that is method hiding. Java won't resolve method call at runtime and depending upon type of Object which is used to call static method, corresponding method will be called. It means if you use Parent class's type to call static method, original static will be called from patent class, on ther other hand if you use Child class's type to call static method, method from child class will be called. In short you can not override static method in Java. If you use Java IDE like Eclipse or Netbeans, they will show warning that static method should be called using class name and not by using object becaues static method can not be overridden in Java.

What is method overriding in Java – Example Tutorial

Method overriding in Java
Method overriding in Java is a concept based on polymorphism OOPS concept which allows programmer to create two methods with same name and method signature on interface and its various implementation and actual method is called at runtime depending upon type of object at runtime. Method overriding allows you to write flexible and extensible code in Java because you can introduce new functionality with minimal code change. Method overriding is different than method overloading in Java which we have discussed in last article. In method overloading, Only name of two overloaded methods are same but method signature must be different while in method overriding, method signature must be same. method overriding represent true polymorphic behaviour, where only name needs to be same underlying method logic can be different. In this Java tutorial we will see What is method overriding in Java, Rules to override method in Java and an example of How to override method in Java. We won't discuss difference between method overloading and overriding in Java, may be some other post.

What is method overloading in Java - Example Tutorial

What is method overloading in Java
Method overloading in Java is a programming concept when programmer declares two methods of the same name but with different method signature, e.g. change in the argument list or change in the type of argument. method overloading is a powerful Java programming technique to declare a method which does a similar performance but with a different kind of input. One of the most popular examples of method overloading is System.out.println() method which is overloaded to accept all kinds of data types in Java. You have println() method which takes String, int, float,double or even char in output. All of those methods are collectively referred as an overloaded method in Java. The difference between method overloading and overriding is also a popular Java interview question. In next section, we will some important points about method overloading in Java and then a simple example of how to overload a method in Java.

Difference between String and StringBuffer in Java

String vs StringBuffer in Java
String and StringBuffer are two classes which are most widely used in any Java program. If I say you can not write a program without using String in Java then it would not be an exaggeration. The string is everywhere, the main method accepts String argument, logs are String etc. Though many Java programmers familiar with String, not many are careful while performing operations on String, Since String is final in Java; every operation e.g. converting String into Uppercase, creating SubString,  converting String to Lowercase all result in a separate new String Object, which can take trigger frequent garbage collection and affect your application performance. here comes StringBuffer in Java which is a mutable version of String, though it's not as feature rich as String and you can not use StringBuffer in place of String but StringBuffer should be used whenever you are performing String concatenation instead of String in Java.

10 Things Every Java developer Should Know about Package concept

What is package in Java
package in Java is a way to organize related functionality in single place. If you look at File System package in Java represent a directory where Java source file is stored in compilation and class files are stored after compilation. For example, if you create a class HelloWorld in a package called com.java67.welcome; then it will reside under directory com/java67/welcome in the source tree and you can view that in your IDE like Eclipse or Netbeans or even by navigating to file system. once you compile your Java program either by using your IDE, Ant build Script or maven compile plugin; it creates class files under same package structure. For example, maven will create target/classes/com/java67/welcome directory and place HelloWorld.class inside that. Its mandatory that class files reside on same package or directory as declared in there source file using package keyword, failure to do will result in java.lang.NoClassDefFoundError in Java. In summary answer of the question What is package in Java can be as simple as that package is a keyword in Java which is used to specify directory structure for the particular class file.

What is Thread and Runnable in Java - Example

What is Thread in Java
Thread in Java is an independent path of execution which is used to run two task in parallel. When two Threads run in parallel that is called multi-threading in Java. Java is multithreaded from the start and excellent support of Thread at language level e.g. java.lang.Thread class, synchronized keyword, volatile and final keyword makes writing concurrent programs easier in Java than any other programming language e.g. C++. Being multi-threaded is also a reason of Java's popularity and being number one programming language. On the other hand if your program divides a task between two threads it also brings lot of programming challenges and issues related to synchronization, deadlock, thread-safety and race conditions. In short answer of question What is Thread in Java can be given like "Thread is a class in Java but also a way to execute something in parallel independently in Java". Thread in Java requires a task which is executed by this thread independently and that task can be either Runnable or Callable which we will see in next section along with an example of  How to use multiple Thread in Java. Difference between Thread and Runnable in Java is also a popular thread interview question in Java.

What is class file in Java - How to create Class File

What is class file in Java
Class file in Java is compiled form of Java source file. When we compile Java program which is written in Java source file  ended with .java extension, it produces one more class files depending upon how many classes are declared and defined in that Java source file. One Java source file can only contain one public class and its name must match with name of file e.g. HelloWorld.java file can contain a public class whose name should be HelloWorld as shown below :

How to traverse iterate or loop ArrayList in Java

How to Loop ArrayList in Java
Iterating, traversing or Looping ArrayList in Java means accessing every object stored in ArrayList and performing some operations like printing them. There are many ways to iterate, traverse or Loop ArrayList in Java e.g. advanced for loop, traditional for loop with size(), By using Iterator and ListIterator along with while loop etc. All the method of Looping List in Java also applicable to ArrayList because ArrayList is an essentially List. In next section we will see code example of Looping ArrayList in Java.

Difference between HashMap and ConcurrentHashMap in Java Collection

HashMap vs ConcurrentHashMap in Java
ConcurrentHashMap in Java is introduced as an alternative of Hashtable in Java, which is a synchronized collection class, that makes the main difference between HashMap and ConcurrentHashMap which is one is non-synchronized , non-thread safe and not for use in Concurrent multi-threaded environment while ConcurrentHashMap is a thread-safe collection and intended to be used as primary Map implementation especially for multi-threaded and Concurrent environment. Apart from thread-safety, there are some subtle differences between HashMap and ConcurrentHashMap which we will see in this article. By the way, Difference between HashMap and ConcurrentHashMap as well as ConcurrentHashMap vs Hashtable are two popular core Java interview question, mostly asked on senior level Java programmers.

Video example - Dijkstra's Algorithm shortest path in Graph


Video example - Dijkstra's Algorithm shortest path in Graph

Dijkstra's Algorithm in Graph theory allows you to find least cost path or shortest path between two nodes in directed and weighted graph. Dijkstra's Algorithm is one of the important concept of Graph theory and often asked in Exams and interviews. Frankly speaking Its not easy to understand Dijkstra's Algorithm , at least until you have a good example and this leads me to search for simple and easy to learn example of Dijkstra's Algorithm which landed me on this video. I have earlier shared Graph traversal BFS and DFS algorithm from this same author and when I found his video on Dijkstra's Algorithm, I knew this is going to be another best. By the way Dijkstra's Algorithm has several practical usage like finding shortest path between cities for Air planes route or bus route as cities and driving path between cities fits nicely
as vertices of Graph and directed and weighted path between them. In Dijkstra's Algorithm , path between two nodes which are unreachable directly is assumed as infinity. I suggest watching this video example more than one time if you are unsure how Dijkstra's Algorithm works.