Monday, January 31, 2022

How Garbage Collection works in Java? Explained

I have read many articles on Garbage Collection in Java, some of them are too complex to understand and some of them don’t contain enough information required to understand garbage collection in Java. Then I decided to write my own experience as an article. You can call it a tutorial about garbage collection in simple words, which would be easy to understand and have sufficient information to understand how garbage collection works in Java. Garbage collection works by employing several GC algorithms like Mark and Sweep, G1, etc. There are different kinds of garbage collectors available in Java to collect different areas of heap memory like you have serial, parallel, and concurrent garbage collectors in Java.

Sunday, January 16, 2022

Top 30 JavaScript Interview Questions with Answers for 1 to 5 Years Experienced Programmers

Building a career as a developer in the IT industry can be challenging if you lack stream-specific preparation. For instance, if you want to be a JavaScript developer, you have to dig deep into its concepts and learn every bit about JavaScript, but then also, I would say, you are 50% prepared for the Job. I'm not saying that you aren't capable enough to get that JavaScript developer's Job; instead, I mean to say that you aren't ready enough to face the recruiters.

Monday, December 13, 2021

What is Log4j 2 RCE issue CVE-2021-44228? How to solve Log injection? [Tactical and Permanent Fix]

Hello guys, since the last couple of days, there is a lot of chaos going into the Java world due to the Log4j2 issue which allows Remote code execution (RCE), the CVE-2021-44228, which is designated a zero-day vulnerability. Everyone is busy whether their Java application is impacted and given the popularity of Log4j it's a good chance that your application will be impacted.  Even if you are not using Log4j2 directly, they might be used by the framework or library you use like Spring Boot, Hadoop, Elastic Serach, or Struts. This is kind of a serious issue becuase RCE Vulnarabilyt means it allows hackers to execute code in your servers, and this has been used in past on many breaches like the 2017 Equifax data breach but its not time to lose calm and understand the impact and whether your app is affected or not and what you can do in short term to prevent it. 

Saturday, November 20, 2021

Pluralsight Free Weekend - 7500+ Pluralsight Courses FREE for 3 Days

Hello folks,  I have exciting news to share with you that Pluralsight is running their Free weekend from 19th to 21st November, which means all of their 7500+ courses are free this weekend. This is an excellent opportunity to try and see the high-quality courses from Pluralsight. If you don't know, Pluralsight is one of the most popular online learning platforms for programmers and developers. Whether you want to learn Java, Python, JavaScript, Web Development, or Data Science, Pluralsight has courses for them. The best thing about Pluralsight is that its creators are reputed and authoritative. For example, there are many Java champions like Richard Warburton and Jose Paumard who have created excellent Java courses. 

Wednesday, November 10, 2021

How to HashMap in Java? Example Tutorial

Hello friends, we are here today again on our journey to Java. I hope everyone is fine and ready to board our train of knowledge. Today we are gonna learn something very interesting and very exciting, yes I am talking about the HashMap class in Java which is the implementation of hash table data structure. In the past, I have shared my thoughts on How HashMap works in Java as well as frequently asked HashMap interview questions but I have never shared an example of how to use HashMap in Java, or when to use HashMap. Today's topic will definitely be very useful in coding and programming. This topic would surely decrease your time complexity if any task very significantly :p 

So what's the wait? Let's start!

Sunday, November 7, 2021

How to Check/Uncheck CheckBoxes in a Page using jQuery? Example Tutorial

In the last couple of articles, I have shared a couple of useful jQuery tips like reloading web pages and working with tag selectors. Today, I'll show you how to check or uncheck a particular checkbox using jQuery, one of the most popular JavaScript frameworks. jQuery provides CSS like selectors which can make this kind of task trivial. If you remember, in HTML a checkbox is checked if the "checked" attribute is present and its value is not false, otherwise, it's unchecked. By using jQuery function prop() you can dynamically add this attribute or if present we can change its value i.e. checked=true to make the checkbox checked and checked=false to mark the checkbox unchecked.

Saturday, November 6, 2021

How to solve java.lang.classnotfoundexception sun.jdbc.odbc.jdbcodbcdriver in Java 8

java.lang.classnotfoundexception sun.jdbc.odbc.jdbcodbcdriver exception comes in Java 8 because it has removed the JDBC ODBC bridge driver class "sun.jdbc.odbc.jdbcodbcdriver" from JDK and JRE. This class is required to connect any database using Object database connectivity driver e.g. Microsoft Access, but unfortunately, you cannot use it from JDK 8 onward. In order to solve this error, just use the Jackcess library or a commercial driver like HXTT. Normally, in pre-Java 8 world, java.lang.classnotfoundexception sun.jdbc.odbc.jdbcodbcdriver error comes when you try to connect to the Microsoft Access database from Java using JDBC and JDBC ODBC bridge driver is not available in the classpath.

Does Standard Column Width of 80 On Coding Make Sense in Modern Era of Big Monitors?

One of the oldest coding practices is to keep line width 80, and many of us follow it blindly but have you ever thought about why we have this practice in the first place? I believe it was to make your code more readable in the age of small monitors so that the whole content can fit on the screen, or it might have originated from the age of punch cards, which was used to be 80 columns wide. This sounds reasonable when we think about those old days but do you think this rule makes sense now? We are now living in the age where most of the developers have got large monitors, which can show up to 180 characters, doesn't this is wastage of precious monitor space? It also makes your code unnecessary long, than it actually is.

Friday, October 29, 2021

How to Split String in SQL Server and Sybase? Example Tutorial

Sometimes we need to split a long comma-separated String in a Stored procedure e.g. Sybase or SQL Server stored procedures. It's quite common to pass comma delimited or delimiter separated String as an input parameter to Stored procedure and then later split comma separated String into multiple values inside stored proc. This is not just the case of the input parameter but you can also have a comma-separated string in any table data. Unfortunately, there is no split() function in Sybase or SQL Server 2005 or 2008 which can directly split a string based on delimiter just like in the Java string split method

Thursday, October 28, 2021

How to Load Resources from Classpath in Java with Example

Classpath in Java is not only used to load .class files, but also can be used to load resources e.g. properties files, images, icons, thumbnails, or any binary content. Java provides API to read these resources as InputStream or URL. Suppose, you have a properties file inside the config folder of your project, and you want to load that properties file, how do you do that? Similarly, you have icons and thumbnails for your web applications on the icons directory of your project, how do you load them? The answer is by using java.lang.Class' getResource() and getResourceAsStream() method. These methods accept the path of resource as String and return URL and InputStream respectively.

Tuesday, October 26, 2021

How to Calculate Difference between two Dates in Java (In Days) - Example Tutorial

If you are not running on Java 8, then there are two ways to calculate the difference between two dates in Java in days, either by using standard JDK classes e.g. java.util.Date and java.util.Calendar or by using the joda-time library. Unfortunately, Java's old Date and Calendar API is buggy and not intuitive, so many of us by default use Joda for all date and time arithmetic. In this example, you will learn how to find the number of days between today and any date entered by a user using Joda, as well as without using any third-party library. When I first time face this problem, I thought what's a big deal about finding the difference between dates? If you can convert Date to milliseconds then finding a number of days, months or years are just a matter of simple arithmetic, but I was WRONG. I was not thinking about the real-world date and time nuisance like leap seconds, leap years, and daylight saving time.

Friday, October 22, 2021

2 Best Open source Java Libraries to Create PDF documents - iText vs Apache FOP

PDF format is a popular format for sending receipts, email confirmation, and other documentation and we often have a requirement to create PDF documents using Java, mostly in JSP pages. Since most of the official documentation uses PDF format nowadays, it becomes imperative to support PDF files. Recently I received a couple of questions regarding the suggestion of open-source Java PDF libraries, like which is the best open source PDF library in Java or should I use iText or Apache FOP in my Java application for PDF processing. These questions motivates me to write this post. In this article, I will share a couple of Java based open source PDF libraries, both FREE and with some licensing fees, which you can use to generate PDF documents in Java projects.

Tuesday, October 19, 2021

3 Ways to Prevent Method Overriding in Java - Private, Static and Final Method Example Tutorial

Every Java programmer knows that final modifier can be used to prevent method overriding in Java because there is no way someone can override final methods; but, apart from final modifier, is there any other way to prevent method overriding in Java? This was the exact question, asked to one of my friend in a recent Java interview at one of the leading Investment bank. I guess, he was lucky to get this question because he already knows those tricks and was able to answer it quickly. When he told me about his experience,  I didn't understand why someone ask this question? What is the purpose? What they were trying to find out? I can understand if they have asked what's the best way to prevent method overriding in Java, or what is the risk of overriding? 

Monday, October 18, 2021

Java 8 Date Time - 20 Examples of LocalDate, LocalTime, LocalDateTime

Along with lambda expressions, streams, and several minor goodies, Java 8 has also introduced brand new Date and Time API, and in this tutorial, we will learn how to use Java 8 Date Time API with simple how-to-do task examples. Java's handling of Date, Calendar, and Time is long been criticized by the community, which is not helped by Java's decision of making java.util.Date mutable and SimpleDateFormat not thread-safe. It seems, Java has realized a need for better Date and time support, which is good for a community which already used to of Joda Date and Time API.

10 Examples of Converting a List to Map in Java 8

Hello guys, suppose you have a list of objects, List and you want to convert that to a Map, where a key is obtained from the object and value is the object itself, how do you do it by using Java 8 stream and lambda expression? Prior to Java 8, you can do this by iterating through the List and populating the map by keys and values. Since it's an iterative approach and if you are looking for a functional solution then you need to use the stream and lambda expression, along with some utility classes like Collectors, which provides several useful methods to convert Stream to List, Set, or Map.