HTML

How to create ConcurrentHashSet from ConcurrentHashMap in Java 8 - Example Tutorial

There is no ConcurrentHashSet in JDK 8 but you can still create one for yourself by using the ConcurrentHashMap class of java.util.concurrent package. There is a new method added into ConcurrentHashMap in JDK 8, newKeySet(), which allows you to create a concurrent hash set backed by a concurrent hash map. If you remember whenever you get keys from the map they are returned in a Set e.g. for the old keySet() method because map only has unique keys. Since map doesn't allow duplicate keys, it can be used as a set, as long as you only care for keys or just one element. That's why Java designers are added newKeySet() method to convert a map to set. This is also a static method, which means you don't need a ConcurrentHashMap object to create a concurrent hash set.

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.

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.

Java 8 Default Methods FAQ - Frequently asked Questions and Answers

In last a couple of articles, I have to talk about default methods introduced in JDK 8. First, we have learned what is default method and why it is introduced in Java. Then we have seen the example of how you can use default methods to evolve your interface. After that we have analyzed does Java really support multiple inheritances now in JDK 8 (see here) and how will Java handle the diamond problem that will arise due to default methods. For example, what will happen if a class extend a class and implement an interface and both contain a concrete method with same method signature? Will a diamond problem arise? How will Java handle that and how you can solve it, and the difference between abstract class and interface in Java 8?  Once you went through those articles, you would have a good knowledge of default methods in Java 8.

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 are 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.

How to find large files with size in Linux? find and du command example

One of the common problem while working in UNIX is to find large files to free some space. Suppose, your file system is full and you are receiving an alert to remove spaces or if your host is run out of space and your server is not starting up, the first thing you do is find top 10 largest files and see if you can delete them. Usually, old files, large Java heap dumb are good candidates for removal and freeing up some space. If you are running Java application e.g. core java based programs or web application running on Tomcat then you can remove those heap dump files and free some space, but the big question is how do you find those? How do you know the size of the biggest file in your file system, especially if you don't know which directory it is? We'll try to find answers for some of those questions in this article.

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.