HTML

10 Programming languages to learn in 2018 - (Kotlin, Go, Python, Rust, and More)

Hello guys, 2017 is coming to end and 2018 is approaching. This is the time, most of us start making our goals e.g. physical goals, educational goals, and financial goals. As a programmer, one of our goals is to learn new technologies and programming languages, but which languages should you learn? Since learning a programming language requires both time and patience, you should learn a language which is worth the effort i.e. it can reward you a better job and career growth. In this article, I am going to share with you the top 10 programming languages for 2018 as per StackOverflow's 2017 survey.

Difference between table scan, index scan, and index seek in Database

Good understanding of Indexes is very important while working in a database and SQL and that's why you will find many questions based upon indexes on Programming Job interviews. One of such frequently asked SQL question is the real difference between table scan, index scan, an index seek? which one is faster and why? How does database chooses which scan or seek to use? and How you can optimize the performance of your SQL SELECT queries by using this knowledge. In general, there are only two ways in which your query engine retrieves the data, using a table scan or by using an index. Which method is used for your particular query depends upon what indexes are available in that table, what columns you are requesting in your query, the kind of joins you are doing, and the size of your tables.

How to Reverse String in Java with or without StringBuffer Example

Reverse String in Java
There are many ways to reverse String in Java. You can use rich Java API to quickly reverse contents of any String object. Java library provides StringBuffer and StringBuilder class with reverse() method which can be used to reverse String in Java. Since converting between String and StringBuffer or StringBuilder is very easy it's the easiest way available to reverse String in Java. At the same time, Writing Java program to reverse String in Java without StringBuffer is one of the popular Java String interview question, which requires you to reverse String by applying logic and by not using API methods.

How to create and initialize List or ArrayList in one line in Java

creating and initializing List in same time
Sometime we want to create and initialize List like ArrayList or LinkedList in one line much like creating array and initializing it on same line. If you look Array on Java programming language you can create and initialize both primitive and object array e.g. String array very easily in just one line but in order to create a List equivalent of that array, you need to type lot of code. This is also one of the tricky Java question some time appears in Interview as Write Java code to create and initialize ArrayList in same line. In this Java tips we will see this trick which allow you to create and initialize List much like an Array. This tip can also save lot of time while creating test program or quickly trying some stuff.

What is difference between Thread vs Process in Java

Thread and Process are two closely related term in multi-threading and main difference between Thread and Process in Java is that Threads are part of process. i.e. one process can spawn multiple Threads. If you run a Java program in UNIX based system e.g. Linux and if that program creates 10 Threads, it still one process and you can find that by using ps -ef | grep identifier command which is one of most popular use of grep command in UNIX, Where identifier is unix text which can be used as regular expression to find that Java process. Another major difference between Process and Thread is that, each process has its own separate memory space but Threads from same process same memory space. Some linux command map Java thread with light weight process or lwp, e.g. if you use prstat command in Solaris, you can get how many light weight process or Thread a particular Java program is using.

How to read file in Java using Scanner Example - text files

Reading file with Scanner
From Java 5 onwards java.util.Scanner class can be used to read file in Java. Earlier we have seen example of reading file in Java using FileInputStream and reading file line by line using BufferedInputStream and in this Java tutorial we will See How can we use Scanner to read files in Java. Scanner is a utility class in java.util package and provides several convenient method to read int, long, String, double etc from source which can be an InputStream, a file or a String itself. As noted on How to get input from User, Scanner is also an easy way to read user input using System.in (InputStream) as source.Main advantage of using Scanner for reading file is that it allows you to change delimiter using useDelimiter() method, So you can use any other delimiter like comma, pipe instead of white space.

What is difference between View and Materialized View in Database or SQL?

Difference between View and Materialized view is one of the popular SQL interview questions, much like truncate vs delete, correlated vs noncorrelated subquery or primary key vs unique key. This is one of the classic questions which keeps appearing in SQL interview now and then and you simply can’t afford to learn about them. Doesn’t matter if you are a programmer, developer or DBA, these SQL questions are common to all. Views are a concept which not every programmer familiar of, it simply not in the category of CRUD operation or database transactions or SELECT query, its little-advanced concept for the average programmer.

What is the cost of Oracle Java Certifications - OCAJP8, OCPJP8, OCEWCD, OCMJEA?

One of the frequently asked questions about Oracle Java certifications, formerly known as Sun Certified Java programmer e.g. OCAJP, OCPJP, OCEWCD, OCMEJA etc is about the cost of certification. Many of my readers often ask what is the cost of OCAJP8 or OCPJP8? Is there any discount available? What are the fees of Java 8 certifications? how much Java architect exam cost? etc. I have answered many of them one to one via Facebook and Email in the past, but after so many such requests, I decided to write a blog post about it.

Difference between == and equals() method in Java - String Object

What is the difference between == and equals() method for comparing Objects in Java is one of the classical Interview Questions which appears now and then in many interviews? This question is mostly asked in conjunction with String because comparing String using == and equals() method returns different results. I have often seen along with other popular String  question e.g. StringBuffer vs StringBuilder, Why String is final etc.  Java is a pure object-oriented language and every object has one state and location in the memory and equals () and == are related to the state and location of the object, now in this article will try to understand this concept and difference between == and equals method in Java.

Java Enum ValueOf Example - How to use

valueOf Example in Java Enum
valueOf method of Java Enum is used to retrieve Enum constant declared in Enum Type by passing String in other words valueOf method is used to convert String to Enum constants. In this Java Enum valueOf example we will see how to use valueOf method in Java. valueOf method is implicitly available to all Java Enum because every enum in Java implicitly extends java.lang.Enum class. valueOf method of enum accepts exactly same String which is used to declare Enum constant to return that Enum constant. valueOf method is case-sensitive and invalid String will result in IllegalArgumentException. In short String passed to valueOf method of Java enum must be same to String returned by name() method e.g. TrafficSigal.RED.name() returns RED and you should pass RED to valueOf() to get TrafficSignal.RED. This will be more clear will following Java Enum valueOf example. By the way its third tutorial on Enum in Java after previous post on Java Enum Swith Example  and Java Enum toString example. If you have not read those tutorial you may find useful.

How to fix java.lang.unsupportedclassversionerror unsupported major.minor version 49.0 50.0 51.0 in Java

java.lang.unsupportedclassversionerror unsupported major.minor version 50.0 error comes in Java environment when you compile your Java file in a higher Java version e.g. Java 1.6 and then trying to run same Java program in lower Java version e.g. Java 1.5. Java is backward compatible i.e. you can run your Java 5 binary or JAR into Java or JRE 6 but vice-versa is not true. You can not run Java program which is compiled in higher Java version into lower JRE. class file version changes between every Java version and class file generated by javac command of Java 6 installation is not appropriate  for JRE of Java 5 Installation. In order to solve java.lang.unsupportedclassversionerror unsupported major.minor version 49.0 , 50.0 or 51.0 we need to first understand What is major and minor version of class file in Java. Every Java release has a major source version as shown in this table

How to sort Object in Java - Comparator and Comparable Example

Java Object Sorting Example
How do you sort a list of Objects in Java is one of the frequently asked coding questions in Java interviews and surprisingly not every Java programmers know How sorting of object happens in Java. Comparator and Comparable interface along with Collections.sort() method are used to sort the list of object in Java. compare() and compareTo() method of Comparator and Comparable interface provides comparison logic needed for sorting objects. compareTo() method is used to provide Object's natural order sorting and compare() method is used to sort Object with any arbitrary field. Almost all value classes in Java library e.g. String, Integer, Double, BigDecimal implement compareTo() to specify their natural sorting order. While overriding compareTo method String is sorted lexicographically and Integers are sorted numerically. Just beware that it must inconsistent with equals method i.e. two objects which are equal by equals method in Java, compareTo() method must return zero for them.  Anyway,  sorting standard value Object is not a problem for many Java programmer but some of them really struggle when it comes to sorting custom Objects or domain Objects. In this Java sorting tutorial, we will create a custom object and sort list of Object in ascending and descending order.

Java 8 - Convert ArrayList to HashMap or LinkedHashMap - Example Tutorial

One of the common task in Java is to convert a List of object e.g. List<T> into a Map e.g. Map<K, V>, where K is some property of the object and V is the actual object. For example, suppose you have a List<Order> and you want to convert it into a Map e.g. Map<OrderId, Order>, how do you that? Well, the simplest way to achieve this is iterating over List and add each element to the Map by extracting keys and using the actual element as an object. This is exactly many of us do it in pre-Java 8 world but JDK 8 has made it even simpler. In Java 8, you can get the stream from List and then collect all elements into a Map by using a Collector. The collect() method of Stream class and java.util.stream.Collectors class gives you ample choices to decide which property goes into the key and which object goes into the value.

Difference between Primary key vs Candidate Key in table - SQL database

Primary key vs Candidate Key
What is the difference between primary key and candidate key is another popular SQL and database interview questions which appears in various programming interviews now and then? The concept of primary key and candidate key is not just important from interview point of view but also on designing database and normalization. By the way, this is my second post about primary keys, In last one, we have seen a comparison of primary key vs unique key, which also happens to be one of the frequently asked database questions. By definition primary key is a column or collection of columns, which uniquely define a row in a table. Candidate keys are keys which can be a primary key and also able to uniquely identify any row in the table.

What is difference between Clustered and Non-Clustered Indexes in SQL - Database

Clustered vs Nonclustered Indexes in SQL
The difference between Clustered and Nonclustered index in a relational database is one of the most popular SQL interview questions almost as popular as the difference between truncate and deleteprimary key vs unique key and correlated vs noncorrelated subqueries. Indexes are a very important concept, it makes your queries run fast and if you compare a SELECT query which uses an indexed column to one who doesn't you will see a big difference in performance. There can be two kinds of indexes in relational database Clustered and Nonclustered indexes. A clustered index determines physical sorting order of rows in a table similar to entries on yellow pages which are sorted in alphabetical order.

What is difference between primary key and unique key in table - SQL database

primary key vs unique key in SQL
The primary key and unique key are two important concepts in a relational database and used to uniquely identify a row in a table. Both primary key and unique key can identify a row uniquely but there is some subtle difference between them which we will see in this article. In fact, primary key vs unique is a popular SQL interview questions along with classics like truncate vs delete and  How to manage transaction in a database, mostly asked to fresher and 2 to 3 years experience guys in any programming language. SQL is not just limited to any DBA or PLSQL developer but its an important skill even for Java programmer and you can expect SQL interview question even in many Java interviews.

Java program to calculate Simple Interest - homework exercise

How to calculate simple interest in Java or Write a Java program to calculate Simple interest is a popular Java programming exercise people use in Java course in school and college. So if you have recently got an homework exercise about calculating Simple interest in Java and wondering How to write Java program than this tutorial can help you, provided you know What is simple interest and What is formula of simple interest. If you are completely new in Java programming than I would suggest to try HelloWorld Example in Java and understand What is Path and Classpath in Java. IF you have been doing Java programming and looking for some good coding exercise than you can also see our earlier programs e.g. calculating Fibonacci series using recursion, checking if number is palindrome and How to reverse String in Java using recursion.

Could not create the Java virtual machine Invalid maximum heap size: -Xmx

"Could not create the Java virtual machine" is a general Java Virtual Machine error when you run java command directly or indirectly and its not able to create virtual machine because of invalid maximum heap size, invalid minimum heap size or just any error in command line. This error not only come when you run Java program from command line but also when you run them using any IDE like Eclipse or Netbeans. Could not create the Java virtual machine invalid maximum heap size -Xmx is a special case for it which comes when you try to run your java command with -Xmx option and value of that option is invalid like syntax error, value error or anything else. In this Java article we will see couple of scenarios when you get "Could not create the Java virtual machine Invalid maximum heap size: -Xmx" which will help you to avoid those error and fix this problem.

Difference between first level and second level cache in Hibernate

The main difference between first level and second level cache in Hibernate is that the first level is maintained at the Session level and accessible only to the Session, while the second level cache is maintained at the SessionFactory level and available to all Sessions. This means, you can use the first level cache to store local data i.e. the data which is needed by the Session and you can use the second level cache to store global data i.e. something which can be shared across sessions. This is also one of the frequently asked Hibernate Interview questions and popular in both telephonic rounds as well as on face to face interview, in both fresher and experienced level interviews.

String contains() and indexOf() Example - Check String for SubString

Some time you want to check if one String contains another String or SubString or not e.g. "HelloWorld" contains "Hello" and "World" SubString. There are many ways to check SubString in String in Java e.g. contains(), indexOf() or matches() method of java.lang.String class. In our last article we have seen how to use matches method of String class with regular expression and In this article we will see example of contains() and indexOf() method to check any String or SubString in Java. contains and indexOf method are defined in java.lang.String class and used to check if String contains a particular SubString or not, only difference between contains() and indexOf() method is that, contains is added in Java 5 along with String matches() method while indexOf() is as old as equals(), hashCode and compareTo(). Another difference between contains() and indexOf() method is that contains() return boolean value e.g. true if String contains SubString and false if String doesn't contains SubString but indexOf() return int value, which is actually index of SubString i.e. starting location. indexOf() return -1 if source String does not contain SubString in Java.

How to escape HTML Special characters in JSP and Java

Escaping HTML special characters in JSP or Java is a common task for Java programmers. There are many ways to escape HTML meta characters in Java, some of them we have already seen in last article escaping XML metacharacters in Java.  For those who are not familiar with HTML special characters, there are five e.g. < , >, &, ' and '' and if you want to print them literally just like here, Than you need to escape those character so < becomes &lt; , > becomes &gt; and so on. Of course, you can write your own custom tag or method for converting HTML special characters to entity format which browser understand but you don't need to do this because there are more easy and standard way to escape HTML special characters in JSP and Java. In this JSP and Java tutorial, we will learn about HTML special characters and explore some techniques to escape them in JSP pages and Java code. By the way, this is also a popular JSP Interview question mostly asked 2 years experience programmers.

5 Best Gifts for Programmers,Software Developers and Tech Geeks 2017 - 2018

So, its that time of the year again when you start thinking about gifts for your programmer boyfriend, husband, colleagues or your near dear ones. Even if selecting gifts were not tough, if your friend happened to be a programmer, it becomes slightly tougher. You might have heard that Programmers are aloof, nerd and tech freaks, well, you heard it right. Programmers  prefers to be alone in their own world but they also like gifts and you got it right, they are a nerd so they like books, gadgets, music and something which help them to learn something e.g. a PluralSight membership.

In 2017, gadgets like Apple Watch and Samsung Gear is rocking but that's what everyone is buying so if you want to be a little bit different, chose the one from this list.

How to test RESTful Web Services using curl command in Linux

The curl command of Linux is very powerful and versatile command which allows you to send sophisticated HTTP request right from Linux command line. You can use curl to test your RESTful Web Services by sending GET and POST request, doing authentication, saving a cookie in the file etc. The curl command is the go-to tool for many Java and Spring developers for consuming the secured RESTful Web Services, but you can also use it test your simple REST Web APIs without security.

How to convert primitive int value to a Long object in Java?

Suppose you have an int variable but the part of the application is expecting a Long object, how do you convert a primitive int to a Long object in Java? It shouldn't be a problem, right? after all long is a bigger data type than int, so all int values are acceptable as long, but we also need a Long object, not just the long primitive value. Now, the problem is reduced to converting a long primitive to Long object, which is not really a problem if you are running on JRE version higher than Java 5. But, sometimes autoboxing is not efficient e.g. when you have to convert multiple long values into the Long object in a loop. A better way to convert your long primitive to the Long object is by using static factory methods like Long.valueOf(long l), which was originally meant to convert long primitive values to a Long object, prior to Java 5, but, also works fine with int primitive.

ArrayList vs Vector in Java - Interview Question

ArrayList vs Vector in Java
ArrayList and Vector is two most widely used Collection class in Java and used to store object in ordered fashion. Every Java programmer which is introduced to Java Collection Framework either started with Vector or ArrayList. For beginners Difference between Vector and ArrayList in Java  and LinkedList vs ArrayList are two most  popular Java Interview question. ArrayList vs Vector is not only important on interview perspective but also on effective use of Java Collection API. After reading this article you will know when to use Vector in Java, When to use ArrayList in Java and would be able to compare ArrayList vs Vector over several important parameters e.g. Speed, Synchronization, Code quality etc. Before seeing difference on Vector vs ArrayList, let's What is common between the.

How to convert comma separated String to ArrayList in Java - Example Tutorial

Suppose you have a comma separated list of String e.g. "Samsung, Apple, Sony, Google, Microsoft, Amazon" and you want to convert it into an ArrayList containing all String elements e.g. Samsung, Apple, Google etc. How do you do that? Well, Java doesn't provide any such constructor or factory method to create ArrayList from delimited String, but you can use String.split() method and Arrays.asList() method together to create an ArrayList from any delimited String, not just comma separated one. All you need to do is first split the given String on delimiter e.g. comma using the split() method, this will give you an array of String. Now, you can pass that array to Arrays.asList() method to create a List, but remember this would be fixed length list and not truly an ArrayList.

Java String Matches Example - Regular Expression Tutorial

String Matching Example in Java
String matches method in Java can be used to test String against regular expression in Java. String matches() method is one of the most convenient way of checking if String matches to a regular expression in Java or not. Quite often we need to write code which needs to check if String is numeric, Does String contains alphabets e.g. A to Z or a to Z, How to check if String contains a particular digit 6 times etc. There are so many cases in Java programming where we need regular expression. If you are familiar with Java's regular expression API than you must know about java.util.regex.Pattern and java.util.regex.Matcher class, these class provides regular expression capability to Java API. matches method of String class actually delegate request to these classes. Anyway regular expression can be best learn by seeing few examples and this is what we are going to do in this Java String matches example tutorial.

What is difference between Overloading and Overriding in Java

Overloading vs Overriding in Java
In last couple of articles we have seen What is method overloading and What is method overriding in Java and now we will see What is difference between overloading and overriding in Java. Overloading vs overriding is one of those frequently asked Java interview question which can not be ignored. Overloading vs Overriding has appeared in almost every Java interview, mostly at beginner and intermediate level e.g. 2 to 4 years experience. In fact most of those tricky Java interview Question came from Overloading and Overriding. It's one of the tricky fundamental to understand. In this article we will some important difference between Overloading and Overriding which not only help to understand concept better but also serves as good recap for Java interviews.

Top 10 Java Web Service Interview question answers

Java Web Services Questions and Answers
Web Services interview questions are part of J2EE interviews for jobs which are looking some experience in Java web services Space. Most of the Web services questions come from two different way of implementing Web Services e.g. SOAP and REST. SOAP is an standard and mature way of calling Web Services which uses XML while REST is a new way of implementing Web Services which is based on HTTP protocol. In fact REST Web Service interview questions are getting more and more popular on web services interviews in Java, So if you are going for any Java J2EE interview which require some web service experience, be prepare with both SOAP and REST Web services questions. Following is list of Java web services interview questions which I have prepared for practice. Answers of these web services questions can be easily found in many places on Internet and I will update this list whenever I have new web services interview question. If you guys find any interesting tricky or tough Java web service question asked in Interviews then please share with us :

keytool command examples Java - add view ssl certificate in keyStore trustStore

keytool command in Java is a tool for managing certificates into keyStore and trustStore which is used to store certificate and requires during SSL handshake process. By using keytool command you can do many things but some of the most common operation is viewing certificate stored in keystore, importing new certificates into keyStore, delete any certificate from keystore etc. For those who are not familiar keyStore, trustStore and SSL Setup for Java application , Here is a brief overview on What is a trustStore and keyStore in Java. Both trustStore and keyStrore is used to store certificate signed by signer authority or CA (Certificate authority), with keyStore additionally storing personal certificate for client which is used during client authentication on SSL handshake process if its enable. In this article we will see some basic example of keytool command in Java to find how many certificates we have in keyStore , viewing those certificates, adding new certificates and deleting old certificates from keyStore or trustStore in Java.

10 Linux and UNIX Interview Questions and Answers asked in Wipro TCS Capegemini

UNIX and Linux Interview Questions and Answers
Questions from various UNIX operating systems e.g. Solaris, Linux, IBM AIX or any other UNIX operating system is asked on different support and programming interviews. I have always seen few interview questions from Linux and UNIX along with SQL in almost every Java programming interviews. You just can not afford not to prepare questions from UNIX and Linux until your Job absolutely doesn't require any work in UNIX operating system. I have collected many UNIX command interview questions and already shared them but I found that except system admin jobs, many programming job interviews only focus on general UNIX commands e.g. chmod, find or grep and fundamentals like finding files and directories, managing file space, networking commands, checking process status and managing file permissions.

Difference between ServletConfig and ServletContext in JSP Servlet J2EE

Difference between ServletConfig and ServletContext
ServletContext and ServletConfig these two are important interface of Servlet API which is used by Java J2EE programmer during web application development. Correct understanding of What is ServletContext and ServletConfig is very important for any J2EE application developer. Apart from that Difference between ServletContext and ServletConfig are a popular Servlet JSP interview questions and mostly asked on both fresher and experienced Java programmer during J2EE interviews. Both ServletContext and ServletConfig are basically configuration objects which are used by servlet container to initialize various parameter of web application. But they have some difference in terms of scope and availability so first we see what is ServletContext and ServletConfig objects are and then we will see difference between ServletConfig and ServletContext in Java J2EE.

Rules of Method Overloading and Overriding in Java

The overloading and overriding rule in JavaSince you can either overload or override methods in Java, its important to know what are the rules of overloading and overriding in Java. any overloaded method or overridden method must follow rules of method overloading and method overriding to avoid compile time error and logical runtime errors;  where you intend to override a method but method get overloaded. That is not uncommon and happen several times when Java programmer tries to override equals in Java or  overriding compareTo method in Java while implementing Comparable interface, which accepts Object type of argument. From Java 5 onwards which introduces @Override annotation along with Enum, Generics and varargs method you can completely avoid that problem.

Top 10 Tough Core Java Interview Questions Answers for Programmers

tough core Java interviews questions and answers
What is tough core java interview question ? Why do people look for tough Java questions before going for an interview? well, I don't think I need to answer these tough questions because it's pretty natural to prepare for tough questions even if you are not expecting tough questions from core Java. If you are prepared for tough and tricky Java interview question than you feel more confident and answer other Java interview question with confidence. On the other hand, if you are not prepared for tough and tricky core Java questions than seeing them on Java interview or written test may surprise you. But the definition of tough core Java questions is not universal, same Java question which is easy for one programmer might be tough for other Java programmer. That's why it's best to prepare your own list of tough interview questions before appearing on any Java job interview. In this article, I am going to share you with my Top 10 tough core Java interview questions and answers, which may help you in Java interview.

Palindrome: Java program to check number is palindrome or not

How to find if number is palindrome in Java
Checking whether a number is palindrome or not is a classical Java homework exercise. When you start learning Java programming most institute which teach Java  programming provides these classical Java programs like How to find Armstrong number in Java or how to find Fibonacci number in Java using recursion etc. Write a Java program to check if number is palindrome comes from same category. For those who are not familiar with palindrome numbers, palindrome number is a number which is equal to reverse of itself. For example 121 is a palindrome because reverse of 121 is 121, while 123 is not a palindrome in Java because reverse of 123 is 321 and 121!=321. Finding palindrome number is easy in Java, you just need to develop logic to reverse a number in Java. Thankfully Java provides couple of arithmetic operators like remainder(%) operator also known as modules operator, which returns remainder in division operator and division operator(/) which returns quotient. By using remainder and division operator in Java we can create program to check if number is palindrome or not.

Can we overload static method in Java Program - Example

Overloading static method In Java
Yes, we can overload static method in Java. In terms of method overloading static method are just like normal methods and in order to overload static method you need to provide another static method with same name but different method signature. Static overloaded method are resolved using Static Binding during compile time. Overloading method in Java is completely different than overriding method and as discussed in our last article we can not override static method in Java but we can certainly overload static method in Java. Here is an example which confirms that we can overload static method in Java:

Can we override private method in Java - Example program

No, We can not override private method in Java, just like we can not override static method in Java. Like static methods, private method in Java is also bonded during compile time using static binding by Type information and doesn't depends on what kind of object a particular reference variable is holding. Since method overriding works on dynamic binding, its not possible to override private method in Java. private methods are not even visible to Child class, they are only visible and accessible in the class on which they are declared. private keyword provides highest level of Encapsulation in Java. Though you can hide private method in Java by declaring another private method with same name and different method signature.

Top 10 Java HashMap Interview Questions and Answers

The java.util.HashMap is one of the workhorses of JDK. Along with ArrayList, it is one of the most used classes from Java's collection framework. There is hardly a real world Java project, where I haven't seen the use of HashMap. It is an implementation of hash table data structure and it's not a surprise that HashMap is so useful, as someone has rightly said, "if you could have just one data structure, make it a hash table". The hash table data structure allows you to search for a value in O(1) time if you have key. In Java, there are several implementations of hash table data structure exists e.g. Hashtable, ConcurrentHashMap, LinkedHashMap etc but HashMap is your general purpose map. Though, if you have a special need you can use other hash table implementations available in JDK.

What is transient variable in Java - Serialization Example

What is 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 de-serialization, for example for object transient variable it would be null. this behavior can be customized by using Custom Serialized form or by using Externalizable interface. transient variable is used to prevent any object from being serialized and you can make any variable transient by using transient keyword. By the way difference between transient and volatile variable in Java is a famous Java interview question but transient variable is completely different than volatile variable which we have discussed in our post What is volatile variable in Java. In next section we will see complete example of serialization where we will first serialize an instance of Book class which implements Serializable and than de-serialize to see What is the value of transient variable after deserialization.

What is Volatile Variable in Java - When to use in Thread? Example

What is Volatile variable in Java
volatile variable in Java is a special variable which is used to signal threads, a compiler that this particular variables value are going to be updated by multiple threads inside Java application. By making a variable volatile using the volatile keyword in Java, application programmer ensures that its value should always be read from main memory and thread should not use cached value of that variable from their own stack. With the introduction of Java memory model from Java 5 onwards along with introduction of CountDownLatch, CyclicBarrier, Semaphore and ConcurrentHashMap, volatile variable also guarantees "happens-before" relationship, which means not only another thread has visibility of latest value of volatile variable but also all the variable is seen by the thread which has updated value of volatile variable before these threads sees it. What is volatile variable and when to use it is always a popular Java threading question.

Difference between HashSet and HashMap in Java

HashSet and HashMap in Java
HashSet vs HashMap is a classical Java Collection interview question which 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 most popular collection classes. Despite being hash based collection HashSet and HashMap are different to each other because the underlying interface is different. HashSet implements Set interface via extending AbstractSetclass and HashMap implements Map interface. Before seeing differences between let's see what is common between HashSet and HashMap in Java:

5 difference between Hashtable and HashMap in Java

Hashtable vs HashMap in Java
Hashtable and HashMap are two hash based collection in Java and used to store objects as key value pair. Despite being hash based and similar in functionality there are a significant difference between Hashtable and HashMap and without understanding those difference if you use Hashtable in place of HashMap than you may run into series of subtle programs which is hard to find and debug.Unlike Difference between ArrayList and HashMap,  Difference between Hashtable and HashMap are more subtle because both are similar kind of collection. Before seeing difference between HashMap and Hashtable let's see some common things between HashMap and Hashtable in Java.

Top 12 Java Thread, Concurrency and Multithreading Interview Questions For experienced

Java concurrency and thread interview questions answers
Multithreading is an important feature of Java programming language, which means threads are also an important part of any Java interview. It's true and in fact at beginners and freshers level Thread interview questions in Java are one of most difficult to answer. One reason for interview question related to multithreading and concurrency being difficult is confusion around how multiple threads works together and second is threads are genuinely a complicated topic to understand and use correctly. Mostly thread interview questions checks Java programmers knowledge on Java Thread API, Java concurrency API, issues related to multi-threading like a race condition, thread-safety, and deadlock. Some time multithreading and concurrency interview question also focus on parallel design patterns like solving the producer-consumer problem, implementing work steal pattern or solving dining philosopher problem in Java. This is especially true while interviewing experienced Java developers with 4 to 6 years of experience.

Top 10 Java Programming Coding Interview Questions Answers for programmers

Java coding interview questions answers
Java coding interview questions are mostly some programming exercises which is asked to be solved in java programming language in limited time during any core Java or J2EE interview. No matter whether you have 2 years of experience or 4 years of experience, There is always some coding interview question in Java programming job you are applying. Actually questions related to Java Coding are increasingly getting popular on Java interviews for two reasons, first its difficult to crack Java coding interview questions than answering fact based questions like Why String is immutable in Java or Why main is static in Java; Second reason of popularity of Coding question in Java interviews is read need of good developers who are required to do lot of coding in projects rather than doing some maintenance works.

10 Advanced core Java interview questions for senior and experienced programmer

Java interview questions for Senior and Experienced programmer
Java is very big and there is no way to prepare completely for any core java interview but there is a level of question depends upon your experience, if you are fresher than questions asked in Java interview are mostly based on fundamentals like Iterator vs Enumeration in Java, Why main is public static and void or may be ArrayList vs LinkedList in Java. Things changes when you apply for senior developer, Technical lead or Team Lead Java positions, questions asked on that level are more advanced and less popular among Java circles, you may be asked questions from design pattern, questions from multi-threading, Collections and even asked to write code, design classes and prepare JUnit tests. In this Java article I will share some advanced Core Java interview questions which is appear in Senior level interviews mostly on 4 to 6 years and 6 to 8 years of experience. One important thing to note is that you can not clear interview by just mugging answers of these question because interviewer is most likely asked you follow-up question based upon your response and only way to get through it is to understand the topic well.

What is PATH and CLASSPATH in Java - Path vs ClassPath

What is PATH and CLASSPATH in Java
The PATH and CLASSPATH are two most important environment variables of Java environment which is 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 two most problematic thing for beginners in Java programming language due to two reasons; first because in most of Java courses nobody tell 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. These basic question which answers most of the details about PATH and CLASSPATH in Java are mostly not answered until Java programmer itself acquire these knowledge, Things may be changed nowadays but important of PATH and CLASSPATH is still high. Most common cause of dreaded error like java.lang.NoClassDefFoundError and java.lang.ClassNotFoundException is either incorrect or misconfigured CLASSPATH in Java.

5 Free SQL Books For Beginners and Experienced - Download PDF or Read Online

There is no doubt that SQL is one of the most important skills for both programmers and business analyst. Since many Enterprise applications use the relational database at their backend e.g. Oracle, Microsoft SQL Server, MySQL, it's important to know SQL to work with data resided on those databases. SQL has been around for many years and it will be around for many more coming years. It is also one of the matured technology, hence there are a lot of free resources e.g. books, articles, tutorials are available online.   I have been sharing some free eBooks on different technologies e.g. Java, Python, and jQuery and today I'll share some of the free SQL books for online and offline reading.

What is main method in Java ? Why main is public static and void

What is main method in Java
main method in Java is an standard method which is used by JVM to start execution of any Java program. main method is referred as entry point of Java application which is true in case of core java application but in case of container managed environment like Servlet, EJB or MIDlet this is not true as these Java programs have there own life-cycle methods like init(), service() or destory() for Servlet's which is used by container. main method in Java is run by main thread which is a non daemon thread and Java program runs until main method finishes or any other user thread is running. When we start JVM by running java command we also provide name of class which contains main method, which is later invoked by JVM to start Java program execution. for example in below command :

Default Methods in Interface, Multiple Inheritance and Diamond Problem in Java 8

Ever since Java 8 introduced default and static methods in JDK 8, it's become possible to define non-abstract methods in interfaces and since in Java one class can implement multiple interfaces and because there can be concrete methods in interfaces, the diamond problem surfaced again. What will happen if two interface has methods o the same name and a Java class inherit from it? Many Java programmer also asks me the question that, is Java 8 is also supporting multiple inheritances of classes, as it seems because interface with methods is similar to abstract class or in that any class. Well, it’s not.

Java 8 Default Methods On Interface : What, Why and Example

Whenever someone talks about Java 8, the first thing he speaks about is lambda expression and How lambda expression will change the way you use Collections API today. In truth, lambda expression would not be that useful had language not been enhanced to support default methods on Java Interface. Also known as a virtual extension or defender methods, they allow you to declare a non-abstract method inside Java interface. Which means, finally you can add new methods without breaking all classes, which implements a certain interface. This opens a new path for enhancing and evolving existing Collection API to take advantage of lambda expressions. For example, now you can iterate over all elements of Collection in just one line, as opposed to four lines it requires you to do prior to Java 8.

Difference between Abstract class and Interface in Java 8 with Default Methods

Ever since JDK 8 has allowed concrete methods on interface e.g. default and static methods, many of my readers have asked me how should they answer the classical abstract class vs interface questions. In this post, I'll revisit this hugely popular Java interview question in light of Java 8 changes. Before JDK 8, the level of abstraction was the clear cut difference between abstract class and interface i.e. interface was the purest form of abstraction which only define what interface is supposed to do without specifying how i.e. it only declare API methods and leave implementation to its subclasses.  All methods of an interface were abstract but since Java 8 you can define non-abstract methods in form of default and static methods inside interface in Java.

Top 5 Free Spring Certification Mock Exams and Practice Questions

Many Java developers don't know that similar to Oracle's Java certification, there is also a Spring certification program, which certifies yourself for your Spring framework skill. There is three Spring certifications currently available, Spring Professional certification exam, which certifies on your general knowledge about Spring framework, Spring Web Application Developer exam, which certifies you about your Spring MVC skill and Spring Enterprise Integration Specialist certification exam, which is for advanced Spring Integration skill. Earlier, SpringSource provides this company but now they are provided by Pivotal, the company behind Spring framework.

7 Free 1Z0-803 and 1Z0-804 Sample Questions - OCAJP 7 and OCPJP 7 Mock Exams (Oracle Certified Associate Java SE 7 Programmer 1 and 2 )

In this article, I am going to share some OCAJP 7 or 1Z0-803 exam and OCPJP 7 or 1Z0-804 certification sample questions and mock exam for practice which are completely free and available online. The sample questions are not good enough for thorough practice but you can use these mock tests to get an idea of what to expect in the actual exam. Many of the free mock questions are actually the samples questions provided by professional certification exam simulator provided e.g. Whizlabs, Enthuware, MyExamCloud etc, which are samples of their full-length exam simulators. As I have said many times in this blog that in order to succeed and do well on Java certification you must need a good study guide and a good exam simulator to practice well.

How to backup and load crontab from a file in Linux and UNIX

If you have been using Linux for some time then you might know about cron jobs. They are the scheduler which is used to automatically start processes in a Linux box. I have worked in many projects which use cron jobs to start the environment daily or weekly. They are similar to Autosys when it comes to scheduling job but cron is a Linux command as opposed to Autosys which is separate application altogether. In Linux, crontab command is used for loading cron jobs from a file, listing existing cron entries, and editing them. It manages the cron table that is used by the cron daemon in Linux to execute the cron jobs. Though there are comments to view cron jobs, edit cron jobs and upload cron jobs from a file there is no command to backup existing cron jobs, but don't worry, I'll show you a trick to backup your cron job before editing them or loading a new set of cron jobs.

Top 10 Java Date, Time and Calendar Interview Questions Answers

The Date and Time API is very important one for day to day Java development work but many interviewers don't ask enough questions on this topic. Most of the questions are based on either Java Collection framework e.g. HashMap, ConcurrentHashMap or ArrayList, or on multi-threading concepts e.g. volatile, synchronized and atomic variables. This is not good and I think many interviewers have realized that a good understanding of date and time API is also important for a good Java developer. That's the main reason of increasing number of date, time and calendar based Java interview questions in recent time, particularly in 2017.

How to determine if a string has all unique characters in Java?

This is one of the common string based coding problem from programming job interviews. You need to write a program to determine if a given string has all unique characters or not. For example input= "Java" then your function should return false because all characters are not unique, and if the input is "Python" then your program should return true because all characters in Python are unique. For the purpose of this problem, you can assume the given String only contains ASCII printable characters, though you should always verify that with the interviewer. You can also assume that your solution needs to case-sensitive i.e. "P" and "p" will be considered two different characters and a string containing a letter in both capital and the small case will be considered unique. You are also free to solve the problem in place of using any additional data structure.

Top 17 SQL and UNIX Interview Questions for Software Support Engineers

The SQL and UNIX are two of the most essential skill for any support or development job. It doesn't matter whether you are applying for Java developer or C++ developer, Python developer or Ruby programmer, SQL and UNIX always have some role to play. Hence, it's imperative for any programmer to prepare both SQL and UNIX well before going for any job interview. This becomes even more important if you are going for a support engineer role. Since the main job of support professional is to look after production environment, which often runs on Linux, it's must for them to have a good knowledge of both Linux operating system and command line. They should know what they are doing because an incorrect grep or rm command can bring down the whole production system. That's why they are extensively questioned and tested in their UNIX skill.

5 ways to redirect a web page using JavaScript and jQuery

When an HTTP request for one page automatically goes to another page then it is called a redirection. The redirection of a web page is used for different reasons e.g. redirecting to a different domain e.g. when you move your website from one URL to another URL or redirecting to a more recent version of a page you are looking at it. There are many ways to redirect a web page and different web technologies provide different ways e.g. Java provides sendRedirect() and forward() method for redirection. The redirection can also be divided into two categories, client side and server side. In client side, redirection client is responsible for routing request to another URL but in server side redirection, its server's job to redirect to a new page.

How to find all files containing specific text in Linux? Use grep command

One of the most common task while working in programming projects is finding files containing some specific text e.g. you have your application deployed in Linux server and you are migrating your database from one server to another. Now, you want to file all config files and scripts which are referencing your old database using the hostname or IP address, so that you can replace them with an alias. Well, you should always use an alias to connect to the database or any other system, but sometimes it happens you have to use hostname. Anyway, how do you find all those files containing hostname in your Linux machine? Well, the grep command is here to help you.

String Rotation in Java - Write a Program to check if strings are rotations of each other or not

String based algorithmic questions are very popular in Java interviews e.g. checking if two String is the anagram of each other (see), or checking if given String is a palindrome (see), or just finding permutations of given String (see). One of such popular String based interview questions is about to check if two Strings are a rotation of each other in Java. In order to solve this question, you should know what is String rotation? Well, A string is made of characters and you just rotate the String around any character e.g. "programming" will become "ingprogramm" if we rotate the String on trailing character 3 times. A k-rotation on a string takes the trailing k characters of the string and attaches it to the beginning of the string in the same order. You can rotate the String either in the clock wise (right from the top) or anti-clockwise(left from the top). The string can also be rotated in one go e.g. "123456" will become "456123" if we rotate 456 to the left around character "3".

3 Spring Certification Books - Best of Lot, Must Read

Books, Study guides, and mock exams are some of the important resources to prepare for Spring certifications. In the last article, I have shared some of the best Spring certification guides for Spring Core and Spring web certifications and today I'll share some of the best books to learn Spring frameworks from the certification perspective. If you are preparing for Spring certifications then these books will help you to learn Spring better. It's also true that more and more experienced and intermediate Java developers have started preparing for Spring certifications to make themselves more marketable. In a challenging and competitive environment like today's, Spring is one the essential skills for Java developer. The Spring certifications make you valuable in the eye of employers and help you to get both job and career growth.

How to Sort Map by values in Java 8 using Lambdas and Stream - Example Tutorial

In past, I have shown you how to sort a HashMap by values in Java, but that was using traditional techniques of pre-Java 8 world. Now the time has changed and Java has evolved into a programming language which also has the power of functional programming. How can you take advantage of that fact to do your day to day task e.g. how do you sort a Map by values in Java using lambda expressions and Stream API. That's what you are going to learn in this article. It will serve two purposes, first, it will tell you a new way to sort a Map by values in Java, and, second and more important it will introduce you to essential Java 8 features like lambda expression and streams.

Top 5 Spring Certification Study Guides for Core, Web, and Enterprise Integration Exams

Ever since Pivotal has announced that Spring training is not mandatory for becoming Pivotal certified Spring developer, more and more experienced Java programmers, who have been using Spring for years are preparing for the exam. This is obvious because the expensive Spring training, which cost around 32000 USD in the USA and most of the western nations and around 50,000 INR in India was the biggest hurdle on getting Spring certified. Even though training is the best way to prepare for certification because it is totally focused on certification exam and you will cover all topics there, it is not affordable for most of the Java developers around the world. Now, the cost of Spring certification has just reduced to 200 USD from the whopping 3200 USD it cost earlier.

Can you make an abstract class/method final in Java?

No, you cannot make an abstract class or method final in Java because abstract and final are the mutual exclusive concept. An abstract class is incomplete and can only be instantiated by extending a concrete class and implementing all abstract methods, while a final class is considered as complete and cannot be extended further. This means when you make an abstract class final, it cannot be extended hence it cannot be used and that's why Java compiler throws a compile time error when you try to make an abstract class final in Java. In short, an abstract class cannot be final in Java, using both abstract and final modifier with a class is illegal in Java.

Solving org.springframework.beans.factory.BeanCreationException: Error creating bean with name X [Java Spring]

If you are using Spring framework in your Java application and getting this error during startup it means Spring is not able to initialize the bean X and add into its application context, Why? There could be multiple reasons e.g. a typo on spring bean name. Let's take a closer look at the stack trace to find out the real reason:

BeanInstantiationException: Could not instantiate bean class [X]: No default constructor found; nested exception is java.lang.NoSuchMethodException: X.()

Here X is the class, which is declared as Spring bean. The error clearly says that default constructor is not present in class X. By default, Spring will try to instantiate beans by calling the default or no-argument constructor and if it doesn't find the default, no-argument constructor then it is not able to initialize the bean and hence it throws the BeanInstantiationException during startup, the real reason is also appended into stack trace as NoSuchMethodException.