Wednesday, March 27, 2024

How to Compare Date in SQL Server Query? Finding All Rows Between Two Dates

It's tricky to use dates in the SQL server query, especially if you don't have good knowledge of how DateTime type works in the SQL server. For example, one of the frequently asked SQL queries on the interview is to "select all rows where the date is 20151007?" How would you do that? Does the following SQL Query will work correctly

select * from table where date = '20151007'

It may or may not, it entirely depends on upon data in your table. When you only provide date part of a DateTime variable, it uses '00:00:00.000' for the time part.

Tuesday, March 26, 2024

Top 50 Java Programs from Coding Interviews

Coding is an integral part of any programming job interviews, and Java development interviews are no exception. I would even suggest you should never hire anyone without testing their coding skill, coding is also an art, and more often than a good code is an excellent developer as well. If you look at tech giants like Amazon, Facebook, and Google they thoroughly test the coding skill of any developer they hire, notably Amazon who first send online coding exercises to filter Java programmers who can code. This online test usually gives you requirements and ask you to write a program in a limited time, usually 2 to 3 hours. The application should meet the output provided by the exercise itself. These type of tasks are very tough to crack if you don't have excellent coding skill.

Monday, March 18, 2024

What is N+1 SELECT Problem in Hibernate? Strategies to avoid this?

In some cases while using Hibernate for object-relational mapping, you will encounter the N+ 1 select problem. That is, Hibernate will execute (n+1) queries to populate a list of records of size n, I mean 5 SELECT queries will be required to populate 4 records. This happens when each object contains reference of another object which needs to be populated. For example, suppose you have list of authors and you want to print out title of books written by each other. A naive ORM will first do a SELECT query to load all authors and then execute another N SELECT query to load book for each author. That's your N + 1 SELECT problem because it involves N+1 database roundtrips'. There are some mechanisms suggested by Hibernate that can be used to mitigate this risk e.g. EAGER fetching mode.

Sunday, March 17, 2024

Top 22 Apache Tomcat Interview Questions Answers for Java JEE Developers

The Apache Tomcat is one of the most popular web server used to deploy Java web application comprising HTML, JavaScript, Servlet and JSP. If you have ever worked in a Java web application you might have found yourself using Tomcat everywhere, from test environment to production. It is the defacto standard for deploying Java Web applications without EJB because using application server like WebSphere or WebLogic is both costly and superfluous for such web application. As a Java developer, working in Java and Spring based web applications, you should know some basic and advanced detail of Tomcat server to efficiently support your Java web app and troubleshoot any issue arising on request processing. 

Thursday, March 14, 2024

Top 10 HTTP Status Code Every RESTful web Service Developer Should know

A good knowledge of HTTP protocol is must for a RESTful Web Service developer because REST uses HTTP principles and a good portion of its popularity is due to HTTP itself. One of the important part of HTTP is the status code, which gives useful information related to client request. They are also known as HTTP response code because they are sent in header on HTTP response by Server to indicate what happened with client's request. The status codes ranges from 100 to 500 but not all of them are valid and useful. Instead the first number e.g. 1xx or 2xxx denotes the class of status codes. 

Saturday, March 9, 2024

10 Example of Gson in Java - JSON tutorial

The Gson library is a gift from Google to Java developers. It provides the simplest but powerful mechanism to deal with JSON documents in Java. By using Gson library, you can parse JSON String to generate Java objects, serialize a Java object to create a JSON document. You can even pretty print JSON String by setting some option to the Gson class, which is the main helper class to interact with Gson library. It also provides mechanism to deal with nulls e.g. you can include null on JSON String or you can omit them. By default Gson print JSON in compact format where null fields are not exported to JSON document but null within array and list are exported. 

Thursday, March 7, 2024

Difference between Servlet and Filter in Java

Servlet and Filter are two of the essential concepts defined in Servlet specification. They are core of any web application because most of the request will pass through them. This is why they are also very popular on Java Web developer interviews. What is the difference between a Servlet and a Filter is one of the most common and interesting interview question related to Servlet. If you can explain the difference clearly, you improve your chance of hiring a lot. In order to understand and explain the difference, you must understand what is the purpose of Servlet and Filter, How they work and how they are used in various web applications. 

Sunday, March 3, 2024

Top 27 Gson Interview Questions with Answers for Java Developers

Hello guys, parsing and creating JSON is a very common task in any Java application, particularly spring based application and that's why its important for a Java developer to not just understand the JSON format but also to be familiar with the important JSON parsing libraries in Java like Gson and Jackson. It's not just important for your day to day Java development work but also for interviews as there is a increased focus on checking if candidate is familiar with key JSON libraries like Jackson or Gson or not. Since I shared Java interview questions on core Java topics like concurrency, abstract class, static, and final modifier, a lot of my reader asked me to share JSON related interview questions as well. 

Friday, March 1, 2024

Difference between known_hosts and authorized_keys file in SSH - Linux

If you have used SSH to login into remote host in Linux, you might have come across these two files stored under the .ssh directory in your home directory e.g. ~/.ssh. Both files are used in the login process for authentication, but the main difference between known_hosts and authorized_keys files are that, known_host is used for server authentication, while authorized_keys are used for client or user authentication. SSH allows login using both password and private keys, you might have heard about trusted SSH connection between two host to download files without entering password, this is achieved using public and private keys. 

2 ways to Split String with Dot (.) in Java using Regular Expression? Examples

You can use the split() method of java.lang.String class to split a string based on the dot. Unlike comma, colon, or whitespace, a dot is not a common delimiter to join String, and that's why beginner often struggles to split a String by dot. One more reason for this struggle is the dot being a special character in the regular expression. If you want to split String on the dot you need to escape dot as \\. instead of just passing "." to the split() method. Alternatively, you can also use the regular expression [.] to split the String by a dot in Java. The dot is mostly used to get the file extension as shown in our example.

Thursday, February 29, 2024

What is the ContextLoaderListener in Spring MVC? What does it do?

The ContextLoaderListener is one of the important component of Spring MVC framework. It is like any listener defined by Servlet specification and specified in web.xml using <listener> tag. It is loaded when Spring MVC based web application is deployed in any Servlet container e.g. Tomcat. The ContextLoaderLister of Spring MVC is responsible for loading root ApplicationContext for Spring. The application context is the place where Spring bean lives. If you need reference to a Spring bean either its auto-wired or injected by framework or you can get it directly from application context. In Spring MVC based web application, there can be multiple application context e.g. root application context and context local to each DispatcherServlet.

Thursday, February 15, 2024

Review - Is Grokking the System Design interview Course on DesignGuru Worth it?

Hello guys,  we are here again today for another exciting topic to discuss. But today, we will not discuss something related to Java or any other language or spring boot. Today, we will discuss something that is immensely practical and has the potential to land you very high-paying jobs. Today we are going to review a course that focuses on System Design! System Design is crucial for coding interviews! And it's also one of the most challenging topics to master. I have shared the best System design courses for coding interviews in the past. Today, I will review one of the top system design courses for technical discussions, Grokking the System Design Interview by Design Gurus.

Tuesday, February 13, 2024

Top 5 React and Redux Courses to Learn Online in 2024 - Best of Lot

If you are a Web developer or someone passionate about web development and looking for some awesome courses to learn React or React JS, a popular JavaScript framework to develop a component-based user interface then you have come to the right place. Facebook's React library has taken the front-end development world by storm. More and more people have started using React even in favor of Google's Angular, another popular front-end development framework. Well, I am not going into the classic debate of Angular vs React as both the framework has their own advantage and disadvantage but if you have chosen to learn React, you have made the right decision.

Monday, February 12, 2024

Top 10 System Design Courses for Beginners and Experienced Developers in 2024 - Best of Lot

Hello guys, if you are preparing for System design interview and looking for best online courses to learn essential System design concepts like load balancing, API Gateway, scalability, Microservices architecture as well as learn how to solve popular System design questions like how to design YouTube, WhatsApp, Parking Lot, Library System as well when to use NoSQL and SQL then you have come to the right place.  In the past, I have shared best System Design Books, Free System design courses,  System design prep guide, and System Interview Questions and in this article, I am going to share best System Design Courses for beginners and experienced Software Engineer to level up their System Design skills in 2024. 

Thursday, February 1, 2024

Top 6 Object Oriented Programming and Design Courses for Java Programmers in 2024 - Best of Lot

There is no doubt that Object-oriented programming is a pillar of software development and one of the reasons for the massive success of Java. Good knowledge of Object-oriented programming helps you to create better software. It also allows you to communicate your ideas better with your team members and fellow programmers. Despite being such an important technology, it's difficult to find programmers who understand OOP well. Many programmers just think that OOP is nothing more than Abstraction, Inheritance, Encapsulation, and Polymorphism, without genuinely understanding these concepts and mastering them.