Top 5 Design Patterns Books for Java Developers - Best of Lot

Design patterns are an essential topic for object-oriented programmers, like Java and C++ developers. It becomes even more important as your experience grows because everybody starts expecting a lot more from you in terms of writing quality code. I often receive emails from intermediate and senior Java developers about progressing to the next level, like how to become Tech Lead, Team Lead, or software architect; knowledge of design patterns plays an important role in taking more technical responsibility. While the GoF book is the bible for object-oriented design patterns, in my opinion, it is a bit too dry and academic.

Top 5 Books to learn SQL and Database Design in 2024 - Best of Lot

SQL (Structured Query Language) is one of the most essential skills of a programmer. I would rate this skill similar to UNIX if you are a professional programmer because it doesn't matter whether you are Java, C++, or a .NET developer, you are bound to write SQL queries. Since a database is an integral part of any modern Java or Web application, the Interviewer always preferred candidates with excellent SQL skills. Now, the big question comes, how a programmer can learn SQL? Does just knowing how to query a table is enough? If you remember, insert, update, delete, and select, then are you a competent SQL programmer?

Top 10 Free Python Programming Books - Download PDF or Read Online

Every Programmer loves free eBook and free courses, even more, if it comes from renowned technical book publishers like Oreilly and Manning. In the last article, I have shared some of the best free Java programming books, and today I am going to share some of the equally best free Python Programming books. These books are not illegal copies that are uploaded into the internet, but they are legal books, made free by their authors and publishers, much like free Udemy courses, which their instructor made free for educational and promotional reasons. Though these are not full-fledged books but concise eBooks, they are very informative and comprehensive enough to learn things like Data Science and Functional programming in Python.

Top 6 Django Python Courses for Beginners to Learn Online in 2024 [UPDATED]

Hello guys, if you want to become a Python web developer and looking for the best online courses to learn Django, Flask, and Python web development, then you have come to the right place. In the past, I have shared the best Python courses and the best Flask courses, and today, I will share the best course to learn everything about Python web development. You may know that Python is a multi-purpose programming language meaning that you can use it in different fields such as GUI application, artificial intelligence, web application, and much more, just to name a few.

Top 7 Free Maven and Jenkins Online Courses for Java Programmers in 2024 [ UPDATED]

Hello Java programmers,  if you want to learn Maven and Jenkins and look for free resources like free online courses, you have come to the right place. Earlier, I have shared the best Maven courses and best Jenkins courses, and in this article, I will share the best free Jenkins and Maven courses for Java programmers. If you have been doing professional Java development, you know that Maven and Jenkins are two of the most popular tools in the Java world. Maven helps organize your project and provide support to build and deploy Java projects, while Jenkins can provide continuous integration and delivery by completely automating build and deploy projects.

Top 5 Books to Learn Hibernate for Java Developers in 2024 - Best of Lot

Hello guys, if you want to learn Hibernate and looking for the best Hibernate books to start with then you have come to the right place. In the past, I have shared the best Hibernate courses and Spring online courses, and today, I am going to share the best books to learn Hibernate for beginners. These books have been created by Hibernate experts like Gavin King, creator of Hibernate himself and it will help you to master this essential Java framework for full-stack developers. Hibernate is the leading ORM (Object to relational) framework in the Java world used to implement the persistence layer of enterprise Java applications.

Top 5 Books to Improve Coding and Programming Skills - Must Read, Best of Lot

Learning a Programming language, like Java, Python, or C++ is easy, but learning to write good code is not. Writing good code is more Art than Science and also an important differentiating factor between an average programmer vs. a good programmer. Since most of the programmers often look for inspiration and resources to improve their coding skill, I decided to share some of the good books which can help them to improve their coding.  Since many universities, colleges, and training courses only teach programming languages but not the art of coding, it still remains one of the self-learned skills which many programmers acquired either in Job or working on real-world projects.

Top 5 Free AWS Developer Associate Certification DVA-C02 Courses in 2024 - Best of Lot

Hello guys, if you are preparing for the AWS Certified Developer Associate exam and looking for free online courses, then you have come to the right place. In the past, I have shared the free online courses to prepare for AWS Cloud Practitioner and SysOps Administrator certifications. Today, I will share free online training courses to prepare for the prestigious AWS Developer Associate exam. The Exam requires hands-on experience with AWS, but that's not enough, you also need to prepare all the exam topics, and that's where these online courses can help you. These are the best and completely free courses from websites like Udemy, Coursera, freeCodeCamp, and Youtube, and you can use them to prepare for this prestigious AWS cloud certification. 

3 Best Books to Learn Java Programming for Beginners

Hello guys, if you want to learn Java from scratch and looking for the best Java books then you have come to the right place. Earlier, I have shared the free Java courses for beginners, and today, I am going to share the best books to learn Java from scratch. There is no doubt that the best book to learn Java for beginners is indeed Head First Java, 3rd Edition. It's interesting, informative, and yet easy to read, which is what a beginner wants. The only drawback of this book was that there is was 3rd Edition available until a couple of months ago but now that drawback has also gone as the 3rd Edition of Head First Java is now available and it covers Java SE 17, the latest version of Java. 

10 Free Courses to Learn Data Structure and Algorithms in Java, Python, and C++ in 2024 [UPDATED]

Algorithms and Data Structure are two of the most fundamental and essential topics in Computer Science, which is used everywhere in software development. I firmly believe that a good knowledge of these two topics is also crucial to becoming a better programmer because a person who has a good understanding of algorithms and data structures can make thoughtful choices and write programs that can handle changes better and perform well. They are also essential to crack coding interviews at top tech companies like Google, Microsoft, Amazon, Facebook, and Apple, which emphasizes candidates' ability to use existing data structures and algorithms to solve complex problems they have never seen before.

Top 10 Books Every Programmer Should Read

There is a saying that if you learn from your mistakes, you will only going to learn few things, but if you learn from other's mistakes, you can learn a lot of things in a short time, and what could be a better way to learn from someone's experience then reading books. Programming as a career is about constant learning and updating yourself, but unfortunately, there is no right way to begin. Schools and Colleges are far behind when it comes to real-world programming, and every Computer Science graduate is not lucky to work in a company that is great in training. The other viable option is to read books, join online courses, and follow advice from the great programmer and authors who are gone on that path, and learning from the book is the most tried and trusted way of all of them.

Top 5 Books to learn React.js for Beginners in 2024 - Best of Lot

Hello guys, if you want to learn React.js and looking for the best resources like books, online courses, and tutorials then you have come to the right place. Earlier, I have shared the best React courses, websites, roadmap, and projects you can build to learn React.js, and in this article, I am going to share the best books to learn React.js in 2024. From my experience of learning so many techs and programming language, I can say that books are the most complete way to learn. For a better learning experience you can combine those with online courses and projects. For example, you can combine these React books with these best React courses and React projects to become a React Developer in 2024. 

Top 5 Spring Framework Books for Java developers (Includes Spring Security and Spring Boot) - Best of lot

Spring framework is one of the most famous structures in the Java world, which used to develop Java applications, both core Java and web application. It is also one of the most job-oriented skills for Java developers; hence many beginners and intermediate Java programmers try to learn the Spring framework on their own. Though there are some excellent Spring training courses available online, books are still the most popular and preferred way to learn Spring frameworks like Spring core, Spring Boot, Spring MVC, Spring Batch, or Spring Security.  I often receive queries for Spring book recommendations e.g., which Spring book is suitable for beginners, or which Spring book is good for intermediate and advanced developers, which book should I read to learn Spring boot, Spring Cloud, Spring Batch, or Spring security, etc.?

Top 10 Algorithms books Every Programmer Should Read

Algorithms are language agnostic, and any programmer worth their salt should be able to convert them to code in their programming language of choice. Unfortunately, I have come across several programmers who are REALLY good at programming languages like Java or Python, like know minor details of API and language intricacies but have very poor knowledge of the fundamentals of Algorithms and Data Structure. Just ask them to implement any popular sorting algorithms like quicksort or merge sort, and they will fall apart. If you expect them to know more advanced and sophisticated algorithms like String processing algorithms, graph algorithms, tree traversal, or greedy algorithms, be ready to check on Interviews; otherwise, you might end up with some surprises.

Top 10 Java Online Courses and Tutorials for Beginners in 2024 [UPDATED]

Hello everyone! if you want to learn Java Programming and become a Java Programmer in 2024 and looking for the best resources like books, online courses, tutorials, projects, and websites, you have come to the right place. Earlier, I have shared the best Java books for beginners, best Java websites, best Java tutorials, and free Java courses. Today, we will go through some of the best online courses for learning the Java Programming language. These Java online courses are curated from top websites and learning platforms like Coursera, Udemy, Educative, CodeCademy, Javaespecialist, etc. 

Top 5 Free Database and SQL Query Courses for Beginners to Learn Online in 2024 - Best of Lot

Hello guys, I have been sharing some free programming resources e.g. books and courses in this blog for quite some time. Earlier I have shared free courses on Java, Maven, Spring, and Data Structure and Algorithms and today I'll share some of the free online training courses to learn SQL and Database. Why you should learn SQL? Well, it's one of the must-have skills for programmers, application developers, and IT professionals. Like Linux, this is one skill that is going to serve you longer than any other programming language, framework, or library. 

Top 6 Free Courses to Learn TypeScript in 2024 - Best of Lot

If you are interested in learning TypeScript or Angular, one of the popular JavaScript frameworks for developing front-end, which uses TypeScript, and looking for some resources like books, tutorials, and courses, then you have come to the right place. In this article, I am going to share some of the best, free TypeScript online courses you can use to learn this powerful programming language. For those who don't know TypeScript, it's a new dynamically typed programming language from Microsoft that augments JavaScript's programming syntax by adding some new features which help in object-oriented application development, particularly the introduction of Types.

8 Free Linux Courses for Programmers and IT Professionals to Learn Online [2024]

Linux is one of the most popular operating systems to run server-side applications. I have seen almost all Java applications running on Linux, barring a couple of them, which run on Windows as a service. If you take out standalone apps like IDEs or tools, most of the real-world Java applications run on Linux, like payment gateways, trading systems, and other financial applications. That's why it's essential for any programmer, IT professional, or developer to learn and understand Linux, both the operating system, as well as the command line.

Top 5 Free R Programming Courses for Beginners in 2024 - Best of Lot

More and more people are learning the R programming language to become Data scientists, one of the hottest and high-paying technical jobs on the planet. Though I am from Python camp when it comes to choosing between Python and R for Data Science, Machine Learning, and Artificial Intelligence, mainly because of the excellent libraries Python offers, I had tried R for a short time. If you are also in the same boat and want to try or learn R programming for Data Science and machine learning purposes and looking for some excellent free courses to start your journey, then you can take some ideas from this article.

How to replace an element of ArrayList in Java? Example

You can use the set() method of java.util.ArrayList class to replace an existing element of ArrayList in Java. The set(int index, E element) method takes two parameters, the first is the index of an element you want to replace, and the second is the new value you want to insert. You can use this method as long as your ArrayList is not immutable, I mean,  not created using the Collections.unmodifiableList(), in such case the set() method throws java.lang.UnsupportedOperationExcepiton

3 Difference between Web Server vs Application Server vs Servlet Containers - Apache vs JBoss vs Tomcat

In the Java EE, or J2EE or JEE world, there is a lot of confusion between terminology, which is quite evident that now we have three words (J2EE, Java EE, and JEE) to describe the same technology platform. You will see Java developers using the terms like Web Server, Application Server, and Web containers interchangeably but they are not exactly the same. The main difference between a Web server and an application server is that a web server is meant to serve static pages like HTML and CSS, while an Application Server is responsible for generating dynamic content by executing server-side code like JSP, Servlet, or EJB.

What is the difference between byte and char data types in Java? Example

The byte and char are two numeric data types in Java and both can represent integral numbers in a range but there are very different from each other. The main difference between a byte and char data type is that byte is used to store raw binary data while other is used to store characters or text data. You can store character literals into a char variable e.g. char a = 'a'; A character literal is enclosed in single quotes. In terms of range, a byte variable can hold any value from -128 to 127 but a char variable can hold any value between 0 and 255. 

Difference between ArrayList and HashSet in Java? Answer with Example

ArrayList vs HashSet Java
The main difference between ArrayList and HashSet is that one is a List implementation while the other is a Set implementation. It means all the differences between a List data structure and a Set data structure also apply to this pair. For example, List implementations are ordered, it stores the element in the order they were added, while Set implementation doesn't provide such a guarantee. Similarly, since List provides Random access, you can access any element directly if you know the index, but Set doesn't provide such a facility. 

4 ways of Session management in Servlets, JSP, and Java Web Applications

Session tracking or Session management is an important feature of modern web applications which allows the server to remember its clients. By keeping a session for each user, the Server can serve the client better. It also helps in safety, security, and personalization and must for certain kinds of web applications like e-commerce sites like Amazon or e-bay which stores items selected by the user for purchase in a shopping cart, even after the user is logged out. 

String to Enum in Java - Example

Creating Enum from String
You can create Enum from String by using Enum.valueOf() method. valueOf() is a static method that is added on every Enum class during compile-time and it's implicitly available to all Enum along with values(), name(), and cardinal() methods. In order to create Enum from String, String must be the same as declared Enum otherwise, the code will throw "java.lang.IllegalArgumentException: No enum const class". the same technique can be used to convert String into Enum instance as well. 

9 difference between static vs non-static method in Java - Answer

One of the key differences between a static and a non-static method is that the static method belongs to a class while the non-static method belongs to the instance. This means you can call a static method without creating an instance of the class by just using the name of the class like the  Math.random() for creating random numbers in Java. Often utility methods that don't use the member variables of the class are declared static. On the other hand, you need an instance of the class to call a non-static method in Java. You cannot call it without creating an object because they are dependent upon the member variables which have different values for different instances.

How to Add Elements of two Arrays in Java - Example

One of the common programming exercises on various Java courses is the addition and multiplication of two arrays. How do you add two integer arrays in Java? Can you add two String arrays? how about other data types etc? These are some of the interesting questions because Java doesn't support operator overloading. You cannot use the plus operator to add two arrays in Java e.g. if you have two int arrays  a1 and a2, doing a3 = a1 + a2 will give a compile-time error. The only way to add two arrays in Java is to iterate over them and add individual elements and store them into a new array. 

How to read a text file into ArrayList in Java? Examples

Prior to Java 7, reading a text file into an ArrayList involves a lot of boilerplate coding, as you need to read the file line by line and insert each line into an ArrayList, but from Java 7 onward, you can use the utility method Files.readAllLines() to read all lines of a text file into a List. This method returns a List of String that contains all lines of files. Later you can convert this List to ArrayList, LinkedList, or whatever list you want to. Btw, this the fourth article in the series of reading a text file in Java. 

6 Difference between forward() and sendRedirect() in Servlet - Answer

Servlet in JEE platform provides two methods forward() and sendRedirect() to route an HTTP request to another Servlet for processing. Though both are used for forwarding HTTP requests for further processing there are many differences between the forward() and sendRedirect() method e.g. forward is performed internally by Servlet, but the redirection is a two-step process, where Servlet instructs the web browser (client) to go and fetch another URL, which is different from the original. That's why forward() is also known as a server-side redirect and sendRedirect() is known as the client-side redirect. 

java.lang.IllegalStateException: getOutputStream() has already been called for this response

This error comes when you call to include() or forward() method after calling the getOutputStream() from ServletResponse object and writing into it.  This error is similar to java.lang.IllegalStateException: getWriter() has already been called for this response error, which we have seen in the earlier article.

This is the exception:
org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:424)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
HelloServlet.doGet(HelloServlet.java:25)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

and here is the root cause :

3 ways to Copy a File From One Directory to Another in Java, Examples

Even though Java is considered one of the best feature-rich programming languages, until Java 7, It didn't have any method to copy a file from one directory to another directory. It did have the java.io.File class, which provides a method to check if a file exists or not and methods for several other file operations but it lacks support for copying files from one folder to another. It was easy to write your own routine to copy a file using FileInputStream or FileChannel, most developers prefer to use Apache Commons IO library; which is not a bad idea at all. 

How to read a text file as String in Java? Example

There was no easy way to read a text file as String in Java until JDK 7, which released NIO 2. This API now provides a couple of utility methods that you can use to read the entire file as String e.g. Files.readAllBytes() returns a byte array of the entire text file. You can convert that byte array to String to have a whole text file as String inside your Java program. If you need all lines of files as a List of String e.g. into an ArrayList, you can use Files.readAllLines() method. This returns a List of String, where each String represents a single line of the file. 

How to convert Enum to String in Java with Example

Enum to String Conversion Example in Java
There are two ways to convert an Enum to String in Java, first by using the name() method of Enum which is an implicit method and available to all Enum, and second by using toString() method. name() method of Enum returns the exact same String which is used to declare a particular Enum instance like in WeekDays Enum if we have MONDAY as one Enum instance then the name() will return String "MONDAY". This method of conversion from Enum to String is useful if the String representation of Enum is the same as its String name but if you have different String representation then you can use toString() method. 

How to Increase Heap Size of Java Program running in Eclipse [Example]

It is possible to increase the heap size allocated by the JVM by using command-line options Here we have 3 options

-Xms<size>        to set the initial Java heap size
-Xmx<size>        to set the maximum Java heap size
-Xss<size>          to set the java thread stack size

$ java -Xms1G -Xmx2G MainClass

In the above line, we have set the minimum heap size to 1GB and the maximum heap size to 2GB.

How to fix java.lang.IllegalStateException: getWriter() has already been called for this response [Solution]

This error comes when a Servlet calls the getOutputStream() method on the response object for writing something after calling the include() method. Suppose a Servlet calls the include() method to load the response of a JSP. Since JSP has already written the response on it hence again opening OutputStream on the response object is illegal, you get the java.lang.IllegalStateException: getWriter() has already been called for this response error. This error also comes when you try to include the response of another Servlet and then tries to write something on the output stream again. In short, your Servlet should never write anything on the response object after calling the include() method. 

Difference between jsp:include and jsp:forward action- Example

JSP provides standard actions to do things without using Java inside the scriptlet. Two of such standard actions, which help JSP to interact with other server resources e.g. another JSP, Servlet, or HTML files are, include and forward actions. The <jsp:forward> action enables you to forward an HTTP request to a static HTML file, a servlet, or another JSP. It has an attribute called page, which accepts the URL of another resource as shown below:
<jsp:forward page="URL" /> 

How to get Current Date and Time in Java with Example

You can get today's date or current date and time in Java by creating a new Date() object. A java.util.Date object represents the current date and time instance in Java. Now, if you want to date in DDMMYYYY format or any other date format, you can easily convert the Date object to String by using SimpleDateFormat class. Since the Date instance contains both date and time, if you only need a date then you can further convert the java.util.Date to java.sql.Date. Similarly, if you need just time then you can convert the java.util.Date to java.sql.Time, they represent the date and time part of java.util.Date object in Java. 

How to convert java.util.Date to java.sql.Timestamp in Java - JDBC Example

You can convert java.util.Date to java.sql.Timestamp by first taking the long millisecond value using the getTime() method of Date class and then pass that value to the constructor of Timestamp object. Yes, it's as simple as that. For better code reusability and maintenance, you can create a DateUtils or MappingUtils class to keep these kinds of utility or mapping functions. Now, the question comes, why do you need to convert java.util.Date to java.sql.Timestamp? 

Well, If you are storing date values to a database using JDBC, you need to convert a java.util.Date to its equivalent java.sql.Timestamp value. Even though both of them represent date + time value and can be stored in DATETIME SQL type in Microsoft SQL Server database or equivalent in other databases like Oracle or MySQL, there is no method in JDBC API which takes the java.util.Date object. Instead, you have got three separate methods to set DATE, TIME, and TIMESTAMP in the java.sql package.

How to Run a JAR file from Command Prompt - Windows and UNIX [Example]

So you got a JAR file that contains your favorite Java game and you are wondering how to run a Java program from a JAR  file? Or you may be simply trying your hand after running the Java program from the command prompt and Eclipse IDE. Anyway, it's good to know How to execute Java programs from the JAR file, as the JAR file is the most popular way of shipping Java programs. JAR file usually contains all sources and resources in the form of class files, images, sound files, etc. 

What is default Serialization in Java? Serializable and Externalizable Interface Explanation

What is Serialization in Java
Serialization in Java is a process to persist any Java Object's state into a File System or convert them into a byte stream to transfer over the network to another JVM or program. Serialization in Java is done by JVM by employing the default Serialization process which persists all of the Object's state except the transient variable and a static variable. How Serialization works in Java is another popular Java Serialization interview question, well It's easy to make any Java class Serializable, the class needs to implements java.io.Serializable interface, and JVM will automatically serialize its instance when passed over to java.io.ObjectOutputStream using writeObject()

How to use Enum in Java? Example

Enum is a useful feature of Java and the best way to represent a fixed number of things like the number of the planet in the solar system, the number of state orders can be, or simply a number of days in a week. Java Enum is different than its predecessor in other languages like C and C++, where the enum is just a wrapper around integer constant. Enum in Java is a full-blown type like class and interface, they can have a constructor (though only private constructors are permitted for Enum), they can override methods, they can have member variables, they can even declare methods, can implement interfaces, and have specialized high-performance Map and Set implementation in form of EnumMap and EnumSet.

Why you shouldn't use == with float and double in Java?

In this article, you are going to learn why you shouldn't use == with float and double in Java? Especially for checking loop termination conditions. Java programmers often make the mistake of using floating-point numbers in a loop and checking conditions with the == operator, in the worst case this could create an infinite loop, causing your Java application to hung.

For example, the following code will not work as you expect :

for(double balance = 10; balance!=0; balance-=0.1) {
   System.out.println(balance);
}

How to load data from CSV file in Java - Example

You can load data from a CSV file in a Java program by using BufferedReader class from the java.io package. You can read the file line by line and convert each line into an object representing that data. Actually, there are a couple of ways to read or parse CSV files in Java e.g. you can use a third-party library like Apache commons CSV or you can use Scanner class, but in this example, we will use the traditional way of loading CSV files using BufferedReader.

6 Difference between include directive and include action in JSP

Difference between include directive and include action
Even though both include directive and include action allows you to include the response of one JSP into another, they are quite different from each other e.g. include directive is processed at translation time and used to include the static resources e.g. HTML files, images, and CSS, etc, while the <jsp:include> action is processed at request time and used to include more dynamic resources e.g. JSP or Servlet. What is the difference between include directive and include action is also one of the most popular JSP interview questions, mostly asked either at telephonic round or first few round of Java web developer interviews?

Top 5 Free Courses to Learn C Programming for Beginners in 2024 - Best of Lot

Hello guys, if you want to learn the C Programming language and looking for a free online course then you have come to the right place. In the past, I have shared the best C programming courses and top C++ courses and today I am going to share the best free C programming courses for beginners.  C is one of the most extended programming languages in the world. It is used for creating operating systems and embedded applications. With the increasing popularity of object-oriented programming, C is being rapidly replaced as "the" programming language by C++, a superset of the C language that uses an entirely different set of programming concepts, but the base is the same in both.

Top 5 Python Books for Beginners to Learn Programming in 2024 - Best of Lot

Python is one of the most popular programming languages, and there is a vast demand for Programmers who knows Python, and the best part is its increasing every year. If you want to learn Python in 2024 then you have come to the right place because earlier I have shared some of the free courses to learn Python and today I am going to share some of the best books to learn Python in 2024. Even though I am a Java Programmer, I am learning Python. In the real world, you often find that a big project in a bank or insurance domain leveraging several technologies together, like Java, C++, Python, UNIX, SQL, and several others.

Thread-safe Singleton in Java using Double Checked Locking Idiom

Singleton Pattern is one of the famous design patterns from the Gang of Four. Even though nowadays it is considered as an anti-pattern, it has served us well in the past. In the Singleton pattern, a class has just one instance throughout its lifetime and that instance is shared between multiple clients. Singleton class has two responsibilities, first to ensure that only instance of the class gets created and second, to provide a method getInstance() so that everyone can get access to that single instance, I mean,  global access.

How to convert float to int in Java? Examples

Even though both float and int are 32-bit wide data types, the float has a higher range than the integer primitive value. Since a float is bigger than int, you can convert a float to an int by simply down-casting it e.g. (int) 4.0f will give you integer 4. By the way, you must remember that typecasting just get rid of anything after the decimal point, they don't perform any rounding or flooring operation on the value. So if your float value is 3.999, down casting to an integer will produce 3, not 4. If you need rounding then consider using the Math.round() method, which converts float to its nearest integer by adding +0.5 and then truncating it. 

How to use BigInteger class in Java? Large Factorial Example

In Java, the BigInteger class, part of the java.math package, provides a powerful and flexible solution for dealing with arbitrarily large integers that exceed the capacity of primitive data types like int or long. This class is particularly useful when precision and magnitude are crucial, such as in cryptographic applications, mathematical computations, or scenarios where large integers are involved. Unlike primitive data types, BigInteger can handle numbers of virtually unlimited size, making it an essential tool for developers facing challenges related to integer overflow or the need for extensive precision. In this guide, we will explore the fundamentals of using the BigInteger class, covering instantiation, basic arithmetic operations, conversion, and the practical scenarios where its usage becomes indispensable. You will also understand the capabilities of BigInteger empowers developers to tackle numerical challenges with confidence in Java applications. For example, we will use BigInteger to calculate factorial of large number.

How to set JAVA_HOME (PATH) in Mac OS? Example Tutorial

You can set JAVA_HOME in Mac OS X 10,10 or Yosemite by adding the following command in your ~/.bash_profile file, as shown below:

export JAVA_HOME=`/usr/libexec/java_home` (remember backticks)
or
echo export "JAVA_HOME=\$(/usr/libexec/java_home -v 1.7)" >> ~/.bash_profile

This will append export "JAVA_HOME=\$(/usr/libexec/java_home -v 1.7)" into your bash_profile file. If you have set JAVA_HOME in UNIX then it's exactly similar to that.

How to use final in Java? Final class, final method, and final variables Example

You can use the final keyword with variables, methods, and classes in Java. You can use the final modifier with variables to make them constant. A final variable is initialized only once in its lifetime, once initialized you cannot change its value. Though you can initialize the final variable at the time you declare them or you can initialize them at constructor if they are blank final variables. A static final variable, also known as a constant must be initialized in the same line. You can also use the final modifier with methods to prevent method overriding. In Java, you cannot override final methods. 

How to write to File in Java using BufferedWriter [Example]

You can use either OutputStream or Writer class in Java to write data to a file in Java. For example, you can use a combination of FileWriter and BufferedWriter to write text content into a text file in Java. If you want to write raw bytes consider using FileOutputStream class. Just remember that InputStream is used to read data and OutputStream is used to write data to file or socket. You can write anything to file e.g. String, integer, float values, etc. Java provides DataOutputStream to write different data types directly into a file like writeInt() to write integer values, writeFloat() to write floating-point values into a file, and writeUTF() to write String into File.  BufferedWriter, like its counterpart BufferedReader, allows you to perform buffered IO, which can drastically improve performance while reading large files.

How to fix java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory

Problem: You are getting java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory in your Java program, which uses a logging framework to log messages into a log file.  It could be direct dependency or indirect dependency due to any framework e.g. Spring, Hibernate, or any open-source library like jackson or any other JSON parsing library.

How to format numbers in Java? - NumberFormat Example

You can use java.util.text.NumberFormat class and its method setGroupingUsed(true) and setGroupingSize(3) to group numbers and add a comma between them. Most numbers that are used to represent monetary value e.g. price, amount, etc require a comma to be added to improve readability and follow conventions. For example, if your variable is storing 1 million dollars then you would like to see it as 1,000,000 rather than 1000000. Clearly, the first one is more readable than the second one. Of course, you can further format to add currency based upon locale, but this tutorial is not about that. 

How to append text to existing File in Java? Example

In the last tutorial, you have learned how to write data to a file in Java, and in this tutorial, you will learn how to append text to a file in Java. What is the difference between simply writing to a file vs appending data to a file? In the case of writing to a file, a program can start writing from the start but in the case of appending text, you start writing from the end of the file. You can append text into an existing file in Java by opening a file using FileWriter class in append mode. You can do this by using a special constructor provided by FileWriter class, which accepts a file and a boolean, which if passed as true then open the file in append mode. 

How to break from a nested loop in Java? [Example]

There are situations we need to be nested loops in Java, one loop containing another loop like to implement many O(n^2) or quadratic algorithms e.g. bubble sort, insertion sort, selection sort, and searching in a two-dimensional array. There are a couple of more situations where you need nesting looping like printing the pascal triangle and printing those star structures exercises from school days. Sometimes depending upon some condition we also like to come out of both inner and outer loops. For example, while searching a number in a two-dimensional array, once you find the number, you want to come out of both loops. The question is how can you break from the nested loop in Java. 

How to Convert a Double to Long in Java - Example Tutorial

We often need to convert a floating-point number into an integral number e.g. a double or float value 234.50d to long value 234L or 235L. There are a couple of ways to convert a double value to a long value in Java e.g. you can simply cast a double value to long or you can wrap a double value into a Double object and call it's longValue() method, or using Math.round() method to round floating-point value to the nearest integer. The right way to convert a double value to a long in Java really depends on what you want to do with the floating-point value. 

How to create User Defined Exception class in Java? Example Tutorial

Java has very good support for handling Errors and Exceptions, It has a well-defined Exception hierarchy and language level support to throw and catch Exceptions and deal with them. Java Programmers often deal with built-in exceptions from java.lang package and several others which are already defined in JDK API like NullPointerException. If you have read Effective Java, you may remember the advice of Joshua Bloch regarding Exception. According to him, you should try to reuse the Exception classes provided in the JDK, like IndexOutOfBoundException, ArithmeticException, IOException, and java.lang.ArrayIndexOutOfBoundsException , instead of creating new ones for a similar purpose.

Second Highest Salary in MySQL and SQL Server - LeetCode Solution

Write a SQL query to get the second highest salary from the Employee table.

+----+--------+
| Id | Salary |
+----+--------+
| 1  | 100    |
| 2  | 200    |
| 3  | 300    |
+----+--------+

For example, given the above Employee table, the second highest salary is 200. If there is no second highest salary, then the query should return NULL. You can write SQL query in any of your favorite databases e.g. MySQL, Microsoft SQL Server, or Oracle. You can also use database specific feature e.g. TOP, LIMIT or ROW_NUMBER to write SQL query, but you must also provide a generic solution which should work on all database. 

10 Tools Java Developers Should Learn in 2024 - (UPDATED)

Hello folks, we are in the first week of 2024, and many programmers have already started making a good process to their goals for 2024, which is very good, but if you are someone, who is still not sure what to learn in 2024, then you have come to the right place. In the past, I have shared 10 things Java developers to learn in 2024, and last week, I published the top 5 Java Frameworks to learn, but there is one topic that kept coming from my readers.  The question which I have received this week a couple of times from my fellow Java developers and readers is which tools Java programmers should learn in 2024? Or what are some excellent Java tools used in application development? And finally, what should I learn in 2024?

Top 5 Free Amazon Web Services or AWS Courses to Learn in 2024- Best of Lot [UPDATED]

Hello guys, if you are thinking about learning cloud technologies or cloud computing, and looking at the various cloud providers like AWS, GCP, or Azure, then you are going in the right direction. The future lies with Cloud, and it's essential for every developer to learn about cloud computing solutions. When we talk about Cloud, the first thing that comes to mind is AWS, the biggest Cloud Computing platform, and that's why I suggest a lot of developers learn it. If you want to learn Amazon Web Services, popularly known as AWS, and looking for some excellent resources like books, courses, and tutorials, then you have come to the right place.

How to Prepare for AWS Certified Solutions Architect Associate SAA-C03 Exam in 2024

Hello guys, If you are preparing for the new AWS Certified Solutions Architect Associate Exam, SAA-C03 in 2024 and looking for guidance then you have come to the right place. While you can find several articles online about the AWS Solutions Architect Associate exam and preparation but most of them are outdated and cover older version of exam like SAA-C01 and SAA-C02. Even if you find good content, , it's not easy to keep all the good content or bookmark them all. However, it takes time to find all the right content and keep it safe for reading and learning more. We understand the value of your time and effort at the time of the exam, so here we present all the content related to the Associate AWS Solutions Architect exam in one place so that you can start your preparation in a structured way. 

Top 5 Free C++ Courses for Beginners to Learn Programming Online in 2024 - Best of Lot

Hello, guys, you might know that C++ is one of the most popular and powerful object-oriented programming languages, and if you want to do low-level stuff, then it's the best language to start with. Most of the complex software like Operating Systems, Database Management Systems, and Powerful trading systems, are written in C++. While many of us have learned to program by using C and C++, let me be honest with you; learning C++ is challenging, especially if you are coming from Python or Ruby background. There are many areas that are tough to grasp like pointers and memory management, but you will learn them slowly, and that's where these free C++ courses will help you.

7 Free Blockchain Developer Courses and Certifications to Learn in 2024 - Best of Lot

Hello guys, if you want to learn Blockchain development and are looking for some free Blockchain courses, you have come to the right place. Earlier, I shared my favorite and best blockchain courses for programmers, and a lot of you asked for free online courses to learn Blockchain, so today, I am going to share the best free Blockchain development courses you can join in 2024. Blockchain is one of the most in-demand technologies and one skill that you should learn in 2024. It will not only help in your career but also raise your profile. This is one thing I have highly recommended programmers to learn this year. 

Top 5 Courses to Learn Linux and UNIX in 2024 - Best of Lot [UPDATED]

Hello guys, if you want to learn Linux operating systems and command lines and look for the best Linux courses, you have chosen the right place. In the past, I have shared some free Linux courses and bash scripting courses for programmers and developers, and many of you asked for more comprehensive online Linux courses to learn Linux in-depth, which motivates me to write this article. In this article, you will find the best Linux online training classes, online paths, and tutorials from Udemy, Pluralsight, Coursera, and edX, my favorite online learning platforms.  

Top 5 Free Google Cloud Platform Courses for Beginners in 2024 - Best of Lot

Hello guys,  If you also want to learn Google Cloud Platform in 2024 and are looking for some free online Google Cloud training courses and materials to start your GCP journey, you have come to the right place. Earlier, I have shared the best Google certification courses. Today, I will share free online courses from Udemy and Coursera, which you can learn from the Google Cloud Platform. If you don't know, Google Cloud Platform is the massive Cloud platform for Google, one of the three biggest public cloud platforms along with AWS and Microsoft Azure.  There is a huge demand for Google Cloud Professionals, but there are few in the market; hence more and more people are learning about Google Cloud and getting certified.

Top 5 Hibernate and Spring Data JPA Online Courses in 2024 - Best of Lot

Hello Java programmers, if you want to learn Hibernate and Spring Data JPA, two of the leading persistence framework for enterprise Java development, and need the best resources like books, tutorials, and online courses then you have come to the right place. In the last article, I have shared the best Spring framework courses, and best Hibernate booksand today, I am going to share the best online courses to learn both Hibernate and Spring Data JPA in 2024. These are the top-quality courses from popular online learning platforms and sites like Udemy, Pluralsight, and Baeldung and are trusted by thousands of Java developers around the world to learn these essential frameworks for Java developers.