Top 80 Core Java Interview Questions with Answers

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. 

How does Hello world program in Java works? Example and Explanation

When I first started with Java programming, the first program I wrote was HelloWorld in Java. That time I just copied it from a textbook we were referring to, I didn't know anything about it. It took me a lot of time to understand everything about HelloWorld in Java and how it works. From that time, I made it a rule to start with writing the HelloWorld program in any new programming language I learn and try to understand every single element of it in as much detail as possible, but,  to be frank, its not that easy. 

How to Create, Start, and Stop a New Thread in Java? [Example Tutorial]

One of the most important tasks for a Java developer is to learn multi-threading and learn it correctly. There are more Java developers who know multi-threading incorrectly than the programmer who doesn't know at all. In order to learn it correctly, you need to start it from scratch, means the most fundamental concepts of multithreading like how to create create, start, and stop a new thread in Java. I am sure you already know that as you have done that a lot of time but it's worth remembering few facts to not repeat the mistakes many programmers do when they write multithreading code in Java. 

How to use CountDownLatch in Java? Example

CountDowaLatch is a high-level synchronization utility that is used to prevent a particular thread to start processing until all threads are ready. This is achieved by a countdown. The thread, which needs to wait for starts with a counter, each thread make the count down by 1 when they become ready, once the last thread call countDown() method, then the latch is broken and the thread waiting with the counter starts running. CountDownLatch is a useful synchronizer and is used heavily in multi-threaded testing.

How to sort a List or Stream by Multiple Fields in Java? Comparator comparing() + thenComparing Example

One of the common requirements in Java is to compare objects by multiple fields. For example, if you have a list of CreditCard objects and you want to compare them by their provider and credit limit I mean, first compare them by their providers like VISA, Master, or American Express and if they are from the same provider then compare them by their credit limit, also known as breaking ties. Before Java 8 this wasn't easy because you have to write nested codes to compare multiple fields of an object as there was no easy way to chain multiple Comparators in Java, but things have changed a lot from Java 8.

How to use CompletableFuture in Java? Example Tutorial

Hello friends, we meet again today on our journey to Java. So I hope you guys are excited about this Java concurrency lesson. Let me ask you guys one thing before we proceed. Do you guys ever wonder about the future? At some point in time, all of you must have thought about it and wondered about different kinds of outcomes. Well, our Java program also wonders about its future tasks so, let us learn today something similar to that! First of all, before jumping onto what a CompletableFuture is, let us first know what a Future in Java is? For guys who know this beforehand, just refresh the concept and for everyone else, let’s understand what it is.

How to get the value of a checkbox using jQuery ? Example Tutorial

Suppose you have a web page with a checkbox like a registration page where you have a checkbox about reading terms and conditions. When the user clicks the submit button, your job is to validate whether that particular checkbox is checked or not? How do you do that? How do you get the value of the checkbox to see if it's checked or not? Well, you can use a pseudo-selector ":checked" to see if that checkbox is checked or not. This selector returns true if the user has clicked and kept the checkbox checked; false otherwise. You can get the checkbox either by class or id and then you can call the is(":checked") method, as shown in our example. 

How to convert an int to String in Java? 4 Examples Tutorial

Hello guys, if you new to Java programming and wondering how to convert an int to a String object in Java then don't worry, you have come to the right place. Earlier, I have shown you how to convert an Integer to a String and in this article, I will show you how to convert an int variable to a String in Java. The difference between an Integer and an int is that the former is an object while an int variable is a primitive value. You can use the String.valueOf() or Integer.toString() method to convert an int value to a String object in Java. Remember, String is not just a char array but a full feature object in Java. 

How to use lifecycle methods in React? Example Tutorial

Components in React are the building blocks of an application. Every component in React has a lifecycle. In simple terms, every component goes through several different phases or events during its lifetime. These phases are -
  • Mounting
  • Updating
  • Unmounting
React provides several in-built methods for each of these phases. These methods are invoked at a certain time during the lifecycle of a component. Such methods are called lifecycle methods. This article will discuss some of the commonly used lifecycle methods in React.

How to use String.matches() with Regular Expression in Java? Example Tutorial

String Matching Example in Java
The string matches method in Java can be used to test String against regular expressions in Java. The string matches() method is one of the most convenient ways of checking if a String matches a regular expression in Java or not. Quite often we need to write code that 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 a regular expression. 

How to prepare for Google Cloud Machine Learning Engineer Exam?

Hello guys, if you are preparing for Google Cloud Machine Learning Engineer Certification Exam and looking for a guide then you have come to the right place. Earlier, I have shared a guide for the Google Cloud Security Engineer exam, and in this article, I will share my tips, process, and resources to prepare for the Google Cloud Machine Learning Engineer exam. The Professional Machine Learning Engineer certification test is regarded as one of the most difficult GCP certifications because More than one accurate answer is provided for almost every question; nevertheless, just one is considered the best one. 

How to Prepare for Google Cloud Security Engineer Exam

The world is changing, so does the studying procedure. In today's world, everything is before us, any course, any certificate can be accomplished using a single gadget. But, maximum of us are deluded by assigning unmerited & boring courses, which lack in quality. In the path of this article, I'll be directing you to some splendiferous resources that would help you undoubtedly. To succeed in this target, I've vetted a tracing of tactics. In this plan, I've fractioned the sketch into three parts – accumulating wisdom via courses & books, and evaluating your gained wisdom into practice tests. Let's buckle down into the details of the Google Cloud Security Engineer Exam and analyze this exam, strategies, what it is to pass this exam. 

How to use Switch Statement and Expression in Java? Tutorial with Examples

Hello friends, welcome aboard to the journey to understand and enjoy Java! We meet once again today to discuss a really interesting topic in Java. But, before we get to the actual topic, let’s talk about a scenario.  Suppose you guys have an integer, which can take up to 5 values, and depending on the value, we perform some tasks. To give you an example, here is a little code on it :


int value;


Now, suppose this int can have up to 5 values associated with it. Let’s say {0, 1, 2, 3, 4}.

For each value, we need to do different processing. 

Understanding "Lifting State Up" in React - Example Tutorial

Introduction

If you have ever worked with React, then you know the importance of state management. The state is managed within the component and decides the component’s behavior. But as the application grows, the state is required to be shared among the different components. For such global state sharing, third-party libraries such as Redux are used.


Apart from managing the state inside a component or using redux for the global state, there is one more way to work with the state. This is called “lifting state up”. In this article, we will discuss what is “lifting state up” in React with the help of an example. 

Higher Order Components in React - Example Tutorial

As a React application grows, it becomes more and more complex. The number of components increases too. With increasing code, you may encounter situations where the same logic is being used in multiple components. Why write the same code everywhere when we can perform code reusability? It is important to understand code reusability and it is recommended to reuse code as much as possible. Higher-Order Components are one such technique. In this article, we will discuss what is Higher-Order Components with the help of a simple example.


How to Create Custom hooks in React.js? Example Tutorial

Introduction

The introduction of React hooks in React version 16.8 changed the React development completely. The web application development using React was mostly limited to class components because the state and lifecycle methods were not supported in the functional components. But with React hooks, the state can be used in functional components. Moreover, lifecycle methods like functionality can also be achieved using the useEffect hook. 

How to do Type checking in React using PropTypes? Example Tutorial

In React, data can be passed from a parent component to a child component as props. Props are the properties that contain immutable read-only data. A prop value is basically an object which can hold any number of values of different data types. Props are an essential part of a React application. If not handled properly, props can lead to potential bugs and conflicts. The main issue is the data type of the value that is being passed from one component to another. React provides type checking support that is very useful in such cases. In this article, we will discuss how to use type checking in React with the help of PropTypes. 

How to use React forms in JSX? Example Tutorial

Introduction

Forms are an essential part of web application development. You can find forms on almost every website you visit. Forms are important because they are used to handle input from the users. Websites will not function properly if there is no way for input handling. 


Input can be taken in various forms. The most common type of input is text input. Other forms of input are checkboxes, radio buttons, and ranges. 


In React, forms are created like they are created in HTML. The most important part of forms in React is handling them. In this article, we will discuss how to create forms in React and handle them. 

How to use "styled-components" in React? Example Tutorial

Introduction

Today, no website is complete without CSS. The user experience is heavily dependent on the CSS applied to the website. Without CSS, the website will look extremely unpleasant. So to make a website attractive and user-friendly, it is necessary to apply top-notch CSS. 


Since its introduction in 1996, CSS has changed a lot. Over time CSS has undergone many changes and lots of new features are added to it. Moreover, to make the developer comfortable, CSS frameworks, libraries, and tools are invented. One such tool is styled-components and in this article, we will discuss what are styled-components and how to use them in React. 

What is context API in React? Example Tutorial

Introduction
Props and state are essential parts of a React component. While the state is controlled within the component, props are passed to it from the parent component. In a huge React application, a global state is generally created to pass the data around. Through props can also be used to pass data around multiple components but that can lead to unwanted situations. To avoid such unwanted situations, React provides the Context API. In this article, we will discuss what Context API is and how (and why) it is used.