Tuesday, March 30, 2021

How to use InstanceOf keyword in Java [Example Tutorial]

The Java programming language and JVM are full of hidden gems and even though I am using Java for more than a decade I still get surprised by features that I didn't know for quite some time e.g. shutdown hook, covariant method overriding, and JVM option to refresh DNS cache.  The instanceof operator is also one of the rarely known features of Java, It is used to check if an object is the instance of a particular class or not. It returns true if the object is an instance of the class, otherwise, returns false. You might have seen usages of the instanceof keyword in Java while overriding the equals() method. Since for checking equality of two instances, the first step is to verify whether they are the instance of the same object or not, you can use the instanceof operator there.

Monday, March 29, 2021

5 Advanced Books for Experienced Java, C++, Python, Ruby and JavaScript Developers

It's one thing to know about the syntax and semantics of a programming language and other things to use it effectively. If you are a programmer and want to take your programming skill to next level in your choice of programming language, and looking for the best resources then you have come to the right place. Earlier, I have shared the best online courses to learn Python, Java, JavaScript, and C++, and today, I am going to share advanced programming books for experienced Java, C++, Python, Ruby, and JavaScript developers. To be honest, there are several books that will be taught you about the syntax and grammar of a programming language, but there are really few books that will teach you the customary and effective ways to use it, also known as idiom and usages.

Difference between 32-bit vs 64-bit JVM in Java?

Hello Java Programmers, if you want to learn Java virtual Machine in-depth and wondering what is the difference between a 32-bit and 64-bit JVM and which one should you use and why? then you have come to the right place. Earlier, I have shared the best JVM books and online JVM courses and in this article, I am going to talk about 32-bit vs 64-bit JVM and their pros and cons. This is also a common Java interview question for beginners and intermediate Java programmers. I have tried to answer this question to the point that's why this article is a short but informative one. You will find out what they are, how they are different, how much heap size, and the pros and cons of each of them. 

Friday, March 26, 2021

ContextLoaderListener - Spring MVC Tutorials for Beginners [UPDATED]

The ContextLoaderListner is one of the essential components of the Spring MVC framework, probably the most important after the DispatcherServlet itself. It is used to create the root context and responsible for loading beans, which are shared by multiple DispatcherServlet like beans related to the service layer and data access layer. In general, When you develop Spring MVC based web applications and also using Spring in the services layer, you need to provide two application-contexts. The first one is configured using ContextLoaderListener, and the other is set using DispatcherServlet. The DispatcherServlet is responsible for loading web component-specific beans like controllers, view resolvers, and handler mappings while, as I said before, ContextLoaderListener is accountable for loading middle-tier and data-tier beans which forms the back end of Spring applications.

Wednesday, March 24, 2021

What is difference between Heap and Stack Memory in Java JVM

One of the many traits of a good programmer is how well he understands the fundamentals and if you want to check the fundamentals of a Java programmer then asking the difference between heap and stack memory is a good choice. Even though both are part of JVM and both consumer's memory allocated to the Java process, there are many differences between them like Heap memory is shared by all threads of Java application but Stack memory is local to each thread. Objects are created in heap memory but method frames are stored in Stack memory, and the size of heap space is much bigger than the small size of Stack in Java.

Tuesday, March 23, 2021

Difference between GET and POST Request in HTTP and REST APIs

HTTP Protocol supports many methods to retrieve data from the server or perform any operation on the server, like upload data, delete the file, etc. In total, the HTTP protocol supports the following methods, GET, POST, PUT, DELETE, HEAD, DELETE, OPTIONS, and TRACE, and the HTTP 1.1 reserves technique called CONNECT for future use.  GET, and POST is two of the most common HTTP methods you would hear or work on the web. Though both can be used to send and receive data from client to server, there are some crucial differences between the GET and POST in HTTP, which will help you to understand when you should use GET vs. POST while writing your client and server application.

Monday, March 22, 2021

How to Send HTTP Request from a Java Program - Example Tutorial

If you are thinking is it possible to send an HTTP request from a Java program and if yes, how to send a simple HTTP GET request in Java, then you have come to the right place. In this article, I'll show you how you can use the HttpURLConnection class from the package to send a simple HTTP request in Java. But, first, let me answer your first question, is it possible to send an HTTP request in Java? Yes, it's possible and you can send any kind of HTTP request like GET, POST, PUT, DELETE, HEAD, or PATCH. The package provides a class called HttpURLConnection, which can be used to send any kind of HTTP or HTTPS request from Java program.

Saturday, March 20, 2021

Is it Possible to take Spring Professional v5.0 Certification without the Official Training course?

Just a couple of years ago, It wasn't possible to take Spring Professional certification without a mandatory expensive training course from Pivotal, but from 10th May 2017 onwards, you can take Spring Certification without a training course. Yes, you read it correctly, it's now possible to become Spring certified developer without spending USD 3200 on mandatory Spring training, like the Core Spring training. For years, Pivotal, the company behind the Spring framework (now Vmware) ensured that a Java developer can only get a Spring Professional certification by first going into a 4-day training run by Pivotal and its partner around the world.

Thursday, March 18, 2021

Difference between trustStore vs keyStore in Java SSL

If you are confused between truststore and keystore and looking to find what exactly they mean then you have come to the right place. Earlier, I have shared free Java courses and today, I am going to tell you the difference between trustStore and keyStore in Java. Both trustStore and keyStore are important but confusing concepts and constantly tormented Java developers when they connect to servers using SSL. The main difference between trustStore vs keyStore is that trustStore (as the name suggest) is used to store certificates from trusted Certificate authorities(CA) which are used to verify certificate presented by Server in SSL Connection while keyStore is used to store the private key and own identity certificate which program should present to other parties (Server or client) to verify its identity.

Wednesday, March 17, 2021

How to Prepare for Java Certifications like OCAJP, OCPJP, or Java SE 11 Developer?

No doubt that Oracle's Java certification is one of the most valuable certifications for the IT industry and helps you to get a better job, better pay, and a better rise in your current salary. It also improves your recognition and job prospects because many big clients demands certified Java programmers for their mission-critical applications. Because of enormous popularity and usefulness, many Java developers and computer science graduates aspire for Java certifications. I often receive queries like, what is the best way to prepare for Java certifications like OCAJP or OCPJP?

7 Examples of HttpURLConnection in Java - Sending GET and POST Request

If you want to learn how to send GET and POST requests from the Java program then you have come to the right place. Earlier, I have shared free Java Courses for beginners, and today, I am going to show you how to use HttpURLConnection class in Java to send HTTP requests to the server.  The HttpURLConnection is an important class in the package which allows you to send an HTTP request from a Java program. By using this class you can send any kind of HTTP request like GET, POST, PUT, DELETE, HEAD, etc to the server and call REST APIs. 

Tuesday, March 16, 2021

Decorator Design Pattern Example in Java [Tutorial]

The Decorator design pattern is one of the famous Gang of Four (GOF) structural design patterns, which provides a dynamic way of extending an object's functionality. It's different than the traditional way of adding new functionality into an object using Inheritance, instead, it uses Composition which makes it flexible and allows the addition of new functionalities at the run time, as opposite to Inheritance, which adds new functionality at compile time. Because of this flexibility, Decorator is one of the darling patterns for many Java developers. 

Sunday, March 14, 2021

How get and put methods of HashMap or Hashtable internally works in Java [Answered]

In this article, I am revisiting a couple of interesting questions related to the internal working of HashMap in Java, mostly asked senior Java developers, ranging from 4 to 6 and up to 8 years of experience. I did cover a lot of these questions from HashMap, ranging from thread-safety to race conditions, in my post about the internal working of Java HashMap, but I thought to revisit two of those questions, how does get and put method of HashMap or Hashtable works internally in Java and what happens if two different keys return the same hashCode, how do you return value from HashMap in that case. 

Saturday, March 13, 2021

Top 5 Books for Java 8 Certifications - 1Z0-808 (OCA) and 1Z0-809 (OCP)

If you are preparing for Oracle's Java SE 8 certification then you may know that in order to become a Java 8 Certified developer, you need to pass two exams, the OCAJP 8 exam with code 1Z0-808 and the OCPJP8 exam with code 1Z0-809. You will not be a Java SE 8 certified programmer if you just pass the OCAJP8 exam. In order to prepare for both these exams, you need to choose an excellent study guide, a couple of quality online courses, and a unique mock exam simulator, apart from writing programs on a daily basis. This is the perfect recipe to crack Oracle's Java certification in the first attempt. It requires a lot of hard work but it's worth it. 

Thursday, March 11, 2021

Top 5 Free JavaScript Books for Beginners - Download PDF or Read Online

The internet is full of good things, and one of them is free eBooks and PDF. Programmers can almost run anything by these free books. Earlier I have shared some of the free JavaScript tutorials, and in this article, I am going to share 5 good books to learn JavaScript, which are open to read online or allow you to download PDF for offline reading. JavaScript is probably another language I recommend someone who knows Java, Why? Because it's really ubiquitous. There is almost no website that is not using JavaScript in one or another format.

How to check if a Key Object Exists in HashMap Java? containsKey() Example

Hello guys, you might know that one of the common programming tasks while using HashMap in Java is to check if a given key exists in the map or not. This is supposed to be easy, right? Yes, it is easy if you know your API well, all you need to is call the containsKey() method, it returns true if the given key exists in HashMap, otherwise false; but I have seen many programmers write code like below which is not correct, which inspired me to write this blog post.

if(map.get(key) !=  null){
    System.out.println("key exits in Map");

This code is fragile, it will not work if you have added null values into HashMap because HashMap does allow null values.

Wednesday, March 10, 2021

10 Programming questions and exercises for Java Programmers

If you have just started learning the basics of Java programming language or familiar with programming in either C or C++, then these Java programming questions and exercises for you. It doesn't focus on a particular part of Java, but these coding exercises will switch you into programming mode. These are also great ways to master basic programming construct like if-else, loops like for and while break and continue with loop,   Java operators e.g., arithmetic and logical operator, recursion, methods, or functions, and standard Java API. You may also find these Java programming questions in most Java courses taught in schools, colleges, and various Java training courses.

Tuesday, March 9, 2021

Top 5 Books to Learn Groovy and Grails for Java Programmers - Best of Lot

If you want to learn Groovy and Grails and looking for the best resources then you have come to the right place. Earlier, I have shared some of the must-read Groovy books, and today, I'll share some of the best books to learn Grails for Java developers. Grails is a web application development framework completely written in Groovy. The Grails and Gradle framework are built using the Groovy language. Grails is the framework to develop a web application using Groovy. The concepts within Grails, like interceptors, tag libs, and Groovy Server Pages (GSP) are very similar to what we have in Java.

How to Count number of 1s (Set Bits) in a binary number in Java [Solved]

Good morning folks, In today's article, we are going to discuss one of the frequently asked bit manipulation-based interview questions, how do you count the number of set bits in a given bit sequence?  Bit Manipulation is an important topic in programming interviews and a good programmer should have sufficient knowledge and skill to work with binary numbers. This kind of question tests the skill of the programmer. Sometimes, it is also asked as to how to count the number of 1s (ones) in a given number? Both are the same question because 1 is also known as set bit.  For example, if the given input is 1000110010 then your program should return 4, as three are only four set bits in this bit sequence.

Monday, March 8, 2021

How to Find the Largest and Smallest of Three Numbers in Java? [Solved]

Hey Java programmers, I have been sharing coding problems from interviews for quite some time and today I am going to share with you another interesting coding problem for beginners, how to find the largest and smallest of three numbers. If you are learning how to program or looking to improve your problem-solving and coding skills then these kinds of small problems are good to start with. They not only provide you an opportunity to think about how to solve a problem using basic programming constructs like conditionals (if, else, if-else, switch), loops (for, while, do-while), operators like arithmetic, bitwise and logical operator as well as teach you how to write functions, class and create a program which you can run.

Sunday, March 7, 2021

80+ Core Java Interview Questions for 1 to 3 Years Experienced Professionals

Hey Java programmers, if you are preparing for a Core Java interview and looking for some frequently asked Java interview questions for quick revision then you have come to the right place. Earlier, I have shared the best books and best courses for Java interviews.  I have also shared many posts about Java Interview Questions and in this article, I will share Java Interview questions and answers especially for junior Java programmers, someone with 1 to 3 years of experience. This includes college graduates, who are looking for the job, Java programmers who have 1 to 2 years of experience in Java, and junior developers who have 2 to 3 years of experience in Java, C++, etc. 

Thursday, March 4, 2021

How to Print all leaf Nodes of a Binary tree in Java [ Coding Interview Questions]

This is another interesting coding problem that is based on a binary tree and mostly asked beginner programmers. If you have some experience in solving binary tree-based problems then it's rather easy to solve because, like many other binary tree algorithms, you can use recursion to print all leaf nodes of a binary tree in Java. Since the tree is a recursive data structure, you can apply the same algorithm to both the left and right subtree. In order to solve this problem, the first thing you should know is what is a leaf node because if you don't know that then you won't be able to solve the problem. Well, a leaf node is the one whose left and right child nodes are null.

Tuesday, March 2, 2021

Binary tree InOrder traversal in Java using Recursion

The InOrder traversal is one of the three popular ways to traverse a binary tree data structure, the other two being the preOrder and postOrder. During the in-order traversal algorithm, the left subtree is explored first, followed by root, and finally nodes on the right subtree. You start traversal from root then go to the left node, then again go to the left node until you reach a leaf node. At that point in time, you print the value of the node or mark it visited and moves to the right subtree. Continuing the same algorithm until all nodes of the binary tree are visited. The InOrder traversal is also known as the left-node-right or left-root-right traversal or LNR traversal algorithm.

Monday, March 1, 2021

3 ways to Count words in Java String - Google Interview Questions

Today, I am going to share with you Java interview questions from Google, which were asked to one of my readers during the telephonic round. How do you count the number of words in a given String in Java? You can count words in Java String by using the split() method of String. A word is nothing but a non-space character in String, which is separated by one or multiple spaces. By using a regular expression to find spaces and split on them will give you an array of all words in a given String. This was the easy way to solve this problem as shown here, but if you have been asked to write a program to count a number of words in a given String in Java without using any of String utility methods like String.split() or StringTokenizer then it's a little bit challenging for a beginner programmer.