Top 21 Maven Interview Questions Answers for Java Developers

Hello guys, for a Java developer, Maven in one of the essential tool and its used to build your Java application. Since most of the Java projects used Maven for building, it is expected from a Java developer that he knows Maven and knows it well. That's why Maven questions are quite common on Java developer interviews but I have seen many Java programmers coming to these interview unprepared and not able to answer most of the questions on tools like Maven, Gradle or even git. When I asked one candidate why don't you prepare for Maven before your Java interviews, he said, I wasn't able to find any list of Maven questions. 

How to enable or disable form elements using jQuery? Examples

In last couple of tutorials you have learned how to get all selected checkbox and radio buttons, and in this tutorial, you will learn how to enable/disable form elements using jQuery. A form element e.g. a textfield, radio buttons and checkbox, all represented using input tag can be enabled or disabled by adding an attribute called "disabled". It's similar to "checked" attribute we have seen for checkbox and radio buttons. If this attribute is not present then element is enable, but if this attribute is present then you can use disabled=true to disable the form element and disabled=false to enable the form elements as shown in our example. Like previous example of checking/unchecking checkbox, you can use prop() jQuery function to enable/disable form element if you are running on jQuery 1.6 or higher version and attr() function if you are running on jQuery 1.5 or lower version. 

How to shuffle a List in Java? Collections.shuffle() Example

Hello guys, if you have a List of numbers and you want to shuff it but don't know how then you have come to the right place. Shuffling is an important technique which is used quite a lot on coding games like number guessing games and card games., The java.util.Collections class provides shuffle() method which can be used to randomize objects stored in a List in Java. Since List is an ordered collection and maintains the order on which objects are inserted into it, you may need to randomize elements if you need them in a different order. Collections.shuffle() method uses default randomness to randomize elements but you also have an overloaded version of shuffle() to provide an instance of the java.util.Random object, which can be used to randomize elements.

How to Compare Two Dates in Java? Check If They Are Equal, Later or Earlier - Examples

There are multiple ways to compare two dates in Java, it also depends on what exactly comparison means. If you are looking to compare two dates to find out whether they are equal or not, then you can simply use the equals() method of java.util.Date class. This method will return true if both dates are equal, precisely both have the same millisecond value. If you are looking to find out whether a date comes before or after another date then you have 3 choices, you can use the compareTo() method of java.util.Date class, or you can use before() and after() method of Date class, or you can use before() and after() method of Calendar class. I suggest leveraging the before() and after() method of the Date class, they are more readable and easy to use.

What is transient variable in Java? Serialization Example

What is a transient variable in Java?
transient variable in Java is a variable whose value is not serialized during Serialization and which is initialized by its default value during deserialization, for example for object transient variable it would be null. This behavior can be customized by using a custom Serialized form or by using the Externalizable interface. A transient variable is used to prevent any object from being serialized and you can make any variable transient by using the transient keyword. You cannot make a local variable transient through and it's only the member variables which can be transient. 

Difference between HashSet and HashMap in Java? Answered

HashSet and HashMap in Java
Hello friends, if you have given Java developer interview then there is good chance that you may have come across questions like Difference between HashSet vs HashMap or HashSet vs TreeSet etc. In this article, we are going to discuss differnece between HashMap and HashSet, two of the popular Collection classes from JDK. The HashSet vs HashMap is a classical Java Collection interview question that focuses on What are differences between HashSet and HashMap in terms of features, usage, and performance. If you are in Java programming even for a year or so, you are likely to be familiar with What is HashSet in Java and What is HashMap in Java, these two are the most popular collection classes. 

What is PATH and CLASSPATH in Java? Path vs ClassPath Example

What is PATH and CLASSPATH in Java
The PATH and CLASSPATH are the two most important environment variables of the Java environment which are used to find the JDK binaries used to compile and run Java in windows and Linux and class files which are compiled Java bytecodes. From my personal experience I can say that PATH and CLASSPATH are the two most problematic things for beginners in Java programming language due to two reasons; first because in most Java courses nobody tells details of what is a PATH and CLASSPATH, What do PATH and CLASSPATH do, What is meaning of setting PATH and CLASSPATH, What happens if we do not set them, Difference between PATH vs CLASSPATH in Java or simply How Classpath works in Java, etc. 

Why is main method public, static, and void in Java? Answer

What is the main method in Java?
The main() method in Java is a special method that is used by JVM to start the execution of any Java program. The main method is also referred to as the entry point of Java application which is true in the case of core Java applications because execution starts from the main() method, but in the case of container-managed environments like Servlet, EJB, or MIDlet this is not true as these Java programs have their own life-cycle methods like init(), service() or destroy() for Servlet's which is used by the container. The main method in Java is run by the main thread which is a non-daemon thread and the Java program runs until the main method finishes or any other user thread is running. 

How to convert JSON String to Java Object using Gson? JSON Deserialization Example

Hello Java Programmers, In the last article, you have learned how to convert a Java object to JSON String and in today's article, you will learn the opposite, i.e. converting a JSON String to a Java object. The first example was known as JSON serialization example and this one is known as JSON deserialization because we are creating a Java object from a String. The idea is very similar to classical Serialization in Java where you convert a Java object to another binary format that can be transported over the network or can be saved in the disk for further usage.

Difference between var, val, and def in Scala? Examples

Hello guys, if you are new to Scala or preparing for Scala interview then you may have come across the question, what is difference between var, val, and def keywords in Scala? This is one of the frequently asked questions from Scala interviews. Even though both var and val keyword is used to declare variables in Scala there is a subtle difference between them. A var is a variable. It’s a mutable reference to a value. Since it’s mutable, its value may change throughout the program's lifetime. On the other hand, the val keyword represents a value. It’s an immutable reference, meaning that its value never changes. Once assigned it will always keep the same value.

3 ways to convert String to JSON object in Java? Examples

It's very common nowadays to receive JSON String from a Java web service instead of XML, but unfortunately, JDK doesn't yet support conversion between JSON String to JSON object. Keeping JSON as String always is not a good option because you cannot operate on it easily, you need to convert it into a JSON object before you do anything else e.g. retrieve any field or set different values. Fortunately, there are many open-source libraries which allows you to create JSON object from JSON formatted String like Gson from Google, Jackson, and json-simple. In this tutorial, you will learn how to use these 3 main libraries to do this conversion with step-by-step examples.

Difference between Correlated and Non-Correlated Subquery in SQL? Examples

Hello guys, the difference between correlated and non-correlated subquery is one of the popular SQL interview question and an important concept for any programmer to learn. The correlated subquery is one of the tricky concepts of SQL. It's similar to recursion in programming which many programmers struggle to understand, but like recursion, it also offers the unique capability to solve many SQL query-based problems like the second-highest salary problem where you need to compare one row of the table to another row. It gives you a different kind of power. The main difference between a regular, non-correlated, and correlated subquery in SQL is in their working, a regular subquery just runs once and returns a value or a set of values that is used by the outer query.

How to sort ArrayList in Java? Examples

Hello Java programmers, sorting ArrayList in Java is not difficult; there are multiple ways to sort a given ArrayList in Java. For example you can use  the Collections.sort() method to  sort ArrayList in ascending and descending order in Java. The  Collections.sort() the method optionally accepts a Comparator. If provided, it uses Comparators' compare() method to compare Objects stored in Collection to compare with each other; in case of no explicit Comparator, Comparable interfaces' compareTo() method is used to compare objects from each other. If objects stored in ArrayList don't implement Comparable, they can not be sorted using the Collections.sort() the method in Java.

What is final modifier in Java? fina class, method, and variable example

Hello Java Programmers, the final variable is a very important concept in Java. It's a modifier that you can apply on variables, methods, and classes and when you apply the final modifier it can make variables immutable, prevent the method from overriding in subclasses, means no polymorphism, and when you make a class final in Java it cannot be extended anymore, taking out Inheritance from the picture. There are both pros and cons of using the final modifier in Java and that's why it's very very important for a Java developer to have an in-depth knowledge of the final modifier in Java and that's what you will learn in this article. 

Best way to Convert Integer to String in Java with Example

Integer to String conversion in Java
There are many ways to convert an Integer to String in Java e.g. by using Integer.toString(int) or by using String.valueOf(int), or by using new Integer(int).toString(), or by using String.format() method, or by using DecimalFormat, String concatenation, or by using StringBuilder and StringBuffer, etc but which one is the best? Some of them we have already seen on my earlier posts e.g. how to convert int to String and converting double to String.  Well, we are going to find the best way to convert Integer to String in Java in this post.