3 Ways to convert java.util.Date to java.time.LocalDate in Java 8 - Example, Tutorial

One of the great features of Java 8 is the new Date and Time API which is intended to fix existing issues related to mutability and thread-safety with existing java.util.Date class. But given java.util.Date is used very heavily across all the Java application, you will often end up with a situation where you need to convert java.uti.Date to java.time.LocalDate while working in Java 8. Unfortunately there is no toLocalDate() method in the java.util.Date class. Though, you can easily convert Date to LocalDate if you are familiar with how new and old API classes map to each other.

What is difference between final vs finally and finalize in Java?

The final, finally, and finalize are one of the three confusing keywords, modifiers, and methods in Java. They sound similar, but they are for different purposes. For example, the final keyword is a modifier in Java. When you use the final keyword with a class, it becomes a final class, and no one can extend this like String is final in Java. When you use the final modifier with a method, then it cannot be overridden in a subclass, and when you use the final keyword with a variable, it becomes a constant, i.e. its value cannot be changed once assigned. On the other hand, it finally is a keyword related to exception handling in Java. It's often used with a try block, and it's part of try, catch, and finally trio.

How to Convert String to LocalDateTime in Java 8 - Example Tutorial

Hello guys, today, I will talk about a common problem while working in a Java application, yes you guessed it right, I am talking about String to Date conversion in Java. I had discussed this before (see the Date to String) when Java 8 was not out, but with Java 8, I don't see any reason to use old date and time API, and hence I am writing this post to teach you how to convert String to Date in Java 8 or beyond. Suppose you have a date-time String "2016-03-04: 11:01:20" and you want to convert this into a LocalDateTime object of Java 8 new date and time API, how do you do that? Well, if you have worked previously with String and Date then you know that you can parse String to Date in Java.

Deep Dive into float and double data types in Java

Hello All, float and double are two fo the important data types in Java, but many developers don't pay enough attention to these two data types, resulting in writing poor code with subtle bugs. To be honest, they are not easy to use because of the complexity with floating-point calculation but knowing even simple things like the maximum, and minimum limit of float and double data types and how to compare float and double variables can go a long way in eliminating bugs which are not obvious. All this information is available on Java documentation and books and courses I have shared earlier, but by writing this article, I am bringing all this information in one place, which will help you to learn and remember them better.

Can you Make a Class Static in Java? Interview Question

This is one of the tricky questions in Java because there is no straight forward. Yes and No answer here. You cannot make a top-level class static in Java, but Yes, you can make a nested class static in Java. In fact, it is even advised (see Effective Java) to prefer a nested static class in Java than normal inner classes. Now, the question comes what is a top-level class, and what is a nested class in Java? Well, you can declare multiple classes in a single Java source file. A class is said to be the top level if it is not inside any other class, and a class that is inside another class is known as nested class. You can create a nested class inside another top-level or another nested class in Java. This is the class that can be static in Java.

Top 30 Spring Interview Questions and Answers for Java/JEE Developers

Spring Interview Questions Answers 
Spring Interview Question is one of the first things Java programmer should prepare before appearing on any Java or Spring interview. With the immense popularity of Spring frameworks like Spring MVC and Spring Boot in Java world, focus on Spring skills on interviews is increasing day by day. For those who don't know, the Spring framework is one of the most popular structures for Java applications, which aims to simplify Java development. It revolutionized the Java development when it initially came with concepts of  Dependency Injection and Inversion of Control, which made writing testable and maintainable Java application

How to send Email in Java using Spring - JavaMailSenderImple Example

Email is an essential function of any enterprise Java application. Your application will need Email functionality to send reminders, bills, payments, confirmations, passwords, alerts, and several other kinds of system notifications. There is hardly any enterprise application in Java which doesn't send emails. It could be for a functional reason or non-functional reason but you will find yourself writing code to send emails every now and then, but it's not straight forward in Java. You need to include Java Mail API and learn some key classes and how to configure them to send emails from Java Programs. You can see the whole process in my earlier article about how to send emails from Java Program, but the point is that its not so easy.

Is it Possible to Create Object or Instance of an Abstract class in Java?

Hello guys, how are you doing? Hope you are doing well. It's been long since  I shared a core Java interview question in this blog, so let's start with that. Earlier I have shared one of the frequently asked questions in Java, can we make an abstract class final in Java and my readers really liked and asked for more such questions. So, today I am going to talk about whether you can create an instance of an Abstract class in Java or not? This is another interesting core Java question that you will find on telephonic interviews, a written test that has multiple-choice questions and most notably Oracle certified Java programmer certification like OCAJP 8  and OCAJP 11.

How to read a CSV file with Header in Java using Jackson library - Example Tutorial

Hello guys, today I am going to show you how to read a CSV file in Java with a simple example of Jackson API. For a long time, I only knew that Jackson can be used to parse JSON but later realized that you can also use it to parse or read CSV file in Java. The Jackson DataFormat CSV library allows you to read a CSV file in just a couple of line and its really powerful and feature rich. For example, you can read a CSV file with a header or without a header. You can even read a tab-delimited text file like CSV. It's also highly configurable and allows you to define columns separator to read a text file with any delimiter. You can even use it to directly convert the CSV data into Java objects, just like we do while reading JSON String in Java.

Spring HelloWorld Example in Java using Annotation and Autowiring

Spring framework has gone a couple of releases since I last share the Spring hello world example with XML configuration. In this article, I am going to explain to you how to create a Spring hello world example with Spring 4.2 release and by using Annotation for dependency injection and autowiring. So no more XML files to specify bean dependencies. It's a simple program that shows how you can use the Spring framework to create Services that are loosely coupled. The example will show you the basic concept of dependency injection by creating a simple Java application that greets the user. It's actually a little bit complex version of a simple Helloworld program but if you need decoupling and in-direction you need to accept some level of complexity. That's the price you need to pay to achieve the flexibility in your code.

Learn Tree Data Structure in 5 Minutes - Binary Tree (BT), Binary Search Tree (BST), and Balanced Tree (AVL vs Red Black)

The Tree data structure is one of the essential data structures, but unfortunately, many programmers don't pay enough attention to learning Trees, particularly advanced tree data structures like balanced trees like AVL and Red-Black tree. Many of them think that knowing just array and the linked list is enough for programming interviews, but when they face questions about a tree, like the difference between binary tree and binary search tree, or difference between binary search tree and a self-balanced tree-like AVL tree or Red-Black tree, they become speechless.

The Right way to Remove Objects while Iterating over ArrayList in Java - Example Tutorial

One of the common problems many Java Programmers face is to remove elements while iterating over ArrayList in Java because the intuitive solution doesn't work, e.g., you just cannot go through an ArrayList using a for loop and remove an element depending upon some condition. Even though java.util.ArrayList provides the remove() methods, e.g. remove (int index) and remove (Object element), you cannot use them to remove items while iterating over ArrayList in Java because they will throw ConcurrentModificationException if called during iteration. The right way to remove objects from ArrayList while iterating over it is by using the Iterator's remove() method.

Top 25 Java Date, Time, and Calendar Interview Questions Answers

The Date and Time API is a 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 like  HashMap, ConcurrentHashMap, or ArrayList or on multi-threading concepts like 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 for an increasing number of date, time and calendar-based Java interview questions in recent times, particularly in the last couple of years.

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 fundamental and if you want to check the fundamentals of Java programmer than asking the difference between heap and stack memory is a good choice. Even though both are part of JVM and both consumers memory allocated to the Java process, there are many differences between them e.g. 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 size of heap space is much bigger than the small size of Stack in Java. Even if you know this much information about heap and stack in Java, you are one of the better candidates, but let's see some more details to impress the interviewer.

Difference between the getRequestDispatcher and getNamedDispatcher in ServletContext?

The ServletContext class provides two methods getRequestDispatcher(String url-pattern) and getNamedDispatcher(String name), which can be used to dispatch a request to a particular servlet. The main difference between getRequestDispatcher() and getNamedDispatcher() method is that former accepts a URL pattern or path while later agrees with a Servlet name defined in deployment descriptor or web.xml file, both return an instance of RequestDispatcher class, which can further use to forward or redirect a request in Java web application. Let' see some more detail about these two methods and how they work.

How to Reverse an Array in place - Java Coding Problems with Solution

It's relatively easy to reverse an array if you have the luxury to use another array, but how would you reverse an array if a temporary buffer is not allowed? This is one of the testing array interview questions, which often proved tricky for Java and other beginner Programmers. But, don't worry, I'll tell you how you can solve this problem without losing your cool. Well, you can also reverse an array in place without using an additional buffer. If you know how to access array elements and how to loop over an array in Java using traditional for loop, you can easily solve this problem without using additional space or in-place as described in many Algorithms books and courses, and on Coding interviews.

How to make a new array in Java?

There are several ways to create an array in Java, for example, you can declare the array without initializing it, or you can create and initialize the array in the same line. If you want to make an array with values, then you need to first decide which type of array you want to create? e.g., do you want String array, which can contain String objects like "abc," "def," or do you want to create an int array which contains int values like 10, 20, etc. In Java, you can create an array of any type, including both primitives like byte, int, long and objects like String, Integer, and other user-defined objects. Let's some code to make a new array in Java.