Saturday, May 27, 2023

What is difference between HashMap and Hashtable in Java?

HashMap vs Hashtable in Java
Though both Hashtable and HashMap are data-structure based upon hashing and implementation of Map interface, the main difference between them is that HashMap is not thread-safe but Hashtable is thread-safe. This means you cannot use HashMap in a multi-threaded Java application without external synchronization. Another difference is HashMap allows one null key and null values but Hashtable doesn't allow null key or values. Also, the thread-safety of the hash table is achieved using internal synchronization, which makes it slower than HashMap.

Difference between List and Set in Java Collection? Example

What is the difference between List and Set in Java is a very popular Java collection interview question and an important fundamental concept to remember while using the Collections class in Java. Both List and Set are two of the most important Collection classes Java Program use along with various Map implementations. The basic feature of List and Set are abstracted in the List and Set interface in Java and then various implementations of List and Set adds specific features on top of that e.g. ArrayList in Java is a List implementation backed by Array while LinkedList is another List implementation that works like linked list data-structure.

Friday, May 26, 2023

Difference between Wait and Sleep, Yield in Java? Example

The difference between wait and sleep or the difference between sleep and yield in Java is one of the popular core Java interview questions and asked on multi-threading interviews. Out of three methods that can be used to pause a thread in Java, sleep() and yield() methods are defined in thread class while wait() is defined in the Object class, which is another interview question. The key difference between wait() and sleep() is that the former is used for inter-thread communication while later is used to introduced to pause the current thread for a short duration. This difference is more obvious from the fact that, when a thread calls the wait() method, it releases the monitor or lock it was holding on that object, but when a thread calls the sleep() method, it never releases the monitor even if it is holding. 

What is Timer and TimerTask in Java – Tutorial Example

Timer in Java is a utility class that is used to schedule tasks for both one time and repeated execution. Timer is similar to the alarm facility many people use in mobile phones. Just like you can have one time alarm or repeated alarm, You can use java.util.Timer to schedule a time task or repeated task. In fact, we can implement a Reminder utility using Timer in Java and that's what we are going to see in this example of Timer in Java. Two classes java.util.Timer and java.util.TimerTask is used to schedule jobs in Java and forms Timer API. The TimerTask is an actual task that is executed by Timer. Similar to Thread in JavaTimerTask also implements the Runnable interface and overrides run method to specify a task details. 

Difference between Thread vs Runnable interface in Java

Thread vs Runnable in Java is always been a confusing decision for beginnerin java. Thread in Java seems easy in comparison to Runnable because you just deal with one class java.lang.Thread while in case of using Runnable to implement Thread you need to deal with both Thread and Runnable two classes. though the decision of using Runnable or Thread should be taken considering differences between Runnable and Thread and the pros and cons of both approaches.

What is Daemon thread in Java and Difference to Non daemon thread - Tutorial Example

Daemon thread in Java is those thread that runs in the background and is mostly created by JVM for performing background tasks like Garbage collection and other housekeeping tasks. The difference between Daemon and Non-Daemon (User Threads)  is also an interesting multi-threading interview question, which is asked mostly on fresher level java interviews. In one line main difference between daemon thread and user thread is that as soon as all user threads finish execution java program or JVM terminates itself, JVM doesn't wait for daemon thread to finish their execution.

4 Reasons and Benefits of Using Multithreading in Java? Why Threads?

In one word, we use Threads to make Java applications faster by doing multiple things at the same time. In technical terms, Thread helps you to achieve parallelism in Java programs. Since CPU is very fast and nowadays it even contains multiple cores, just one thread is not able to take advantage of all the cores, which means your costly hardware will remain idle for most of the time. By using multiple threads, you can take full advantage of multiple cores by serving more clients and serving them faster. Since, in today's fast-paced world, response time matters a lot and that's why you have multi-core CPUs, but if your application doesn't make full use of all resources then there is no point adding them, multi-threading is one way to exploiting huge computing power of CPU in Java application.

How to use Fork Join in Java Multithreading - Tutorial with Example

What is fork Join framework in Java: Already popular project coin of JDK7 release has presented a lot of good features e.g automatic resource management, string in switch case, better exception handling in JDK7, etc. Another important feature to note is fork-join as the name implies it divides one task into several small tasks as a new fork means child and joins all the forks when all the sub-tasks are complete. 

Difference between Process and Thread in Java - Example

One of the common questions from programming interviews is, what is the difference between a Thread and a Process? Well, the main difference between them is that a Process is a program that is executing some code and a thread is an independent path of execution in the process. A process can have more than one thread for doing independent tasks e.g. a thread for reading data from disk, a thread for processing that data, and another thread for sending that data over the network. This technique to improve throughput and better utilize CPU power is also known as multi-threading.

How to use Exchanger for Inter thread communication in Java? Example Tutorial

Hello guys, if you are working in a concurrent Java application then you might have heard about the Exchanger class of java.util.concurrent package. The Exchanger in Java is another concurrency or synchronization utility introduced in Java 1.5 along with CountDownLatch, CyclicBarrier, and Semaphores. As the name suggests, the Exchanger allows two Threads to meet and exchange data at the rendezvous or meeting point. This means you can use Exchanger to share objects between threads and for inter-thread communication. The java.util.Exchanger is a parametric class, which defines and holds the type of object to be exchanged. It has an overloaded method called the exchange(), which is used to exchange objects between threads.

What is Phaser in Java? When and How to use Phaser? Example Tutorial

Hello guys, if you want to know what is Phaser and when and how to use Phaser in Java then you have come to the right place. Phaser in Java is a synchronization mechanism introduced in Java 7 that allows threads to wait for a certain phase or a set of phases to complete before proceeding further. It is a reusable barrier that allows threads to synchronize and wait for other threads to reach a certain phase before moving ahead. In the past, I have shared the best Concurrency courses and books and also wrote tutorials about popular Java concurrency utility classes like CyclicBarrierCountDownLatchBlockingQueueForkJoinPool, and recently CompletableFuture in this article, you will learn about Phaser, another useful concurrency utility for Java programmers. 

Thursday, May 25, 2023

Difference between final, finally and finalize method in Java

What is the difference between the final, finally, and finalize method is asked to my friend in a Java interview with one of the US-based Investment banks. Though it was just a telephonic round interview, he was asked a couple of good questions e.g. how to avoid deadlock in Java, How to get() method of HashMap works, and one of the puzzles which are based on recursion. In short final keyword can be used along with variable, method, and class and has a different meaning for all of them. finally is another Java keyword is used in Exception handling along with try, catch, throw, and throws. finalize() is a special method in Java that is called by Garbage Collector before reclaiming GC eligible objects.

Difference between private, protected, public and package modifier or keyword in Java

private vs public vs protected vs package in Java
Java has four access modifiers namely private, protected, and public. package level access is the default access level provided by Java if no access modifier is specified. These access modifiers are used to restrict the accessibility of a class, method, or variable on which it applies. We will start from the private access modifier which is the most restrictive access modifier and then go towards the public which is the least restrictive access modifier, along the way we will see some best practices while using access modifier in Java and some examples of using private and protected keywords.

Difference between ArrayList and Vector in Java

ArrayList and Vector are two of the most used classes on the java collection package and the difference between Vector and ArrayList is one of the most frequently asked java interview questions on first-round or phone interviews. Though it’s quite a simple question in my opinion but knowledge of when to use Vector over ArrayList or does matter if you are working on a project. In this article, we will some point-based differences between Vector and ArrayList in Java and trying to understand the concept behind those differences. 

Difference between TreeSet, LinkedHashSet and HashSet in Java with Example

TreeSet, LinkedHashSet, and HashSet all are implementation of the Set interface and by virtue of that, they follow the contract of Set interface i.e. they do not allow duplicate elements. Despite being from the same type of hierarchy,  there are a lot of differences between them; which is important to understand, so that you can choose the most appropriate Set implementation based upon your requirement. By the way difference between TreeSet and HashSet or LinkedHashSet is also one of the popular Java Collection interview questions, not as popular as Hashtable vs HashMap or ArrayList vs Vector but still appears in various Java interviews.

Difference between static vs non static method in Java - Example

In this article, we will take a look at the difference between the static and non-static methods in Java, one of the frequently asked doubts from Java beginners. In fact, understanding static keyword itself is one of the main programming fundamentals, thankfully it's well defined in the Java programming language. A static method in Java belongs to the class, which means you can call that method by using class name e.g. Arrays.equals(), you don't need to create an object to access this method, which is what you need to do to access non-static method of a class.

Difference between Class and Object in Java and OOP with Example

Class and Object are the two most important concepts of Object-oriented programming language (OOPS)  e.g. Java. The main difference between a Class and an Object in Java is that class is a blueprint to create different objects of the same type. This may look simple to many of you but if you are a beginner or just heard the term Object Oriented Programming language might not be that simple. I have met many students, beginners, and programmers who don’t know the difference between class and object and often used them interchangeably.

Difference between Abstract Class vs Interface in Java

When to use interface and abstract class is one of the most popular object-oriented design questions and is almost always asked in Java, C#, and C++ interviews. In this article, we will mostly talk in the context of the Java programming language, but it equally applies to other languages as well. The question usually starts with a difference between abstract class and interface in Java, which is rather easy to answer, especially if you are familiar with the syntax of the Java interface and abstract class. Things start getting difficult when the interviewer asks about when to use abstract class and interface in Java, which is mostly based upon a solid understanding of popular OOPS concepts like Polymorphism, Encapsulation, Abstraction, Inheritance, and Composition

Difference between valueOf and parseInt method in Java? Example

Both valueOf and parseInt methods are used to convert String to Integer in Java, but there is subtle differences between them. If you look at the code of valueOf() method, you will find that internally it calls parseInt() method to convert String to Integer, but it also maintains a pool of Integers from -128 to 127 and if the requested integer is in the pool, it returns an object from the pool. This means two integer objects returned using the valueOf() method can be the same by the equality operator. This caching of Immutable object, does help in reducing garbage and help garbage collectors. 

What is difference between java.sql.Time, java.sql.Timestamp and java.sql.Date - JDBC interview Question

Difference between java.sql.Time, java.sql.Timestamp and java.sql.Date  is the most common JDBC question appearing on many core Java interviews. As JDBC provides three classes java.sql.Date, java.sql.Time and java.sql.Timestamp to represent date and time and you already have java.util.Date which can represent both date and time, this question poses a lot of confusion among Java programmer and that’s why this is one of those tricky Java questions are tough to answer. It becomes really tough if the differences between them are not understood correctly.

What happens when you call Thread.run() instead of Thread.start() in Java? Trick Interview Question

Hello guys, writing multi-threaded and concurrent programs is not easy, not even in Java.  Even senior developers, including myself, make mistakes while writing concurrent Java applications. This is also one of the trickiest areas of Java programming language, where misconceptions outnumber concepts. Considering the amount of misconception an average Java programmer has about multi-threading and concurrency, I thought to start a new series about common multi-threading mistakes done by Java programmers; what is a better way to learn from common real word mistakes.

Wednesday, May 24, 2023

Review - Is Introduction To Programming the Internet of Things (IoT) Specialization on Coursera worth it?

The internet of things or IoT in a simple word is devices (things) embedded with sensors, software, hardware that are connected and exchange data with other devices such as smart refrigerators, smartwatches, intelligent cameras that can detect fires using artificial intelligence, self-driving cars that can take the wheel over the human, intelligent home security system and the list is endless. This kind of devices is programmed using the language like C and C++. Still, you can also use the python language, and people with IT backgrounds are more likely to learn and understand this kind of technology. Still, I’ve found one of the best courses that can teach you IoT and how to program yourself even if you are a non-technical person. An Introduction to Program the Internet of Things (IoT) Specialization course offered from the University of California Irvine.

How to check File Permission in Java with Example - Java IO Tutorial

Java provides several methods to check file and directory permissions. In the last couple of articles, we have seen how to create Files in java and how to read a text file in Java, and in this article, we will learn how to check whether the file is read-only, whether the file has to write permission or not, etc. In Java we know we have a file object to deal with Files if we have created any file in our application using the file object, we have the privilege to check the access permission of that file using a simple method of File class in Java. Let see what the methods are and how to use that method

How to Change File Permissions in Java – Example Tutorial

Hello guys, In the last article, we saw how to check whether an application can access the file and perform any read-write or execute an operation on that file by using the inbuilt method provided by File Object. Now we deal with some more methods of file class which will use to provide some privileges to users so that they can perform read, write, and execute operations on the particular file. There are few more methods added with the new File API in Java 7, but in this tutorial, we will only learn about traditional ways to change the permission of a file from the Java program, which should work on all versions of JDK.

Java Serialization Example - How to Serialize and Deserialize Objects in Java?Tutorial

Serialization is one of the important but confusing concepts in Java. Even experienced Java developers struggle to implement Serialization correctly. The Serialisation mechanism is provided by Java to save and restore the state of an object programmatically. Java provides two classes Serializable and Externalizable in java.io package to facilitate this process, both are marker interfaces i.e. an interface without any methods. Serializing an Object in Java means converting it into a wire format so that you can either persist its state in a file locally or transfer it to another client via the network, hence it becomes an extremely important concept in distributed applications running across several JVMs.

SimpleDateFormat in Java is not Thread-Safe Use Carefully

SimpleDateFormat in Java is a very common class and often used to format Date to String and parse String into Date in Java, especially in pre Java 8 world, but it can cause very subtle and hard to debug issues if not used carefully because both DateFormat and SimpleDateFormat both are not thread-safe and buggy. A call to format() and parse() method mutate the state of DateFormat class and should be synchronized externally in order to avoid any issue but many Java developers are not aware of these. That's why it's better to completely avoid using SimpleDateFormat class especially if you are using Java Se 8 or higher version like Java SE 11 or Java SE 17. here are a few points which you should take care while using SimpleDateFormat in Java:

Java 8 Comparator comparing() and thenComparing() Example - Tutorial

Hello Java programmers, you may know that the JDK 8 has added a lot of new methods into the Comparator interface which makes comparing and sorting objects in Java really easy. Two such methods are called comparing() and thenComparing() which was added in the java.util.Comparator interface. These methods accept a key extractor function and return a Comparator that can compare to that key. The key must be Comparable though like String, Integer, or any Java class which implements java.lang.Comparable interface, I mean the key must implement Comparable interface. 

How to check if a File is hidden in Java? Example

This article is a quick tip to find hidden files in Java by checking the hidden properties of a File or directory from the Java Program. File Handling is a crucial topic in java already we have discussed how to create a file in java, how to create a directory, how to read write in a text file in Java, how to set permissions on the file, and some more aspects and we will discuss one more property of the file, i.e. hidden property. Now the question arises can we make a file Hidden using our java code or not.

How to create a hidden file in Java- Example Tutorial

In the last article, we saw how to check hidden files in Java and now we will see how to hide files in Java or make hidden files in Java. As we said File API in Java doesn’t provide any method to make a file hidden in Java but still you can apply some quick tricks to hide files from Java program. Like in a Unix environment any file whose names begin with a dot (.) is hidden so you can name your file starting with a dot (.)  and your File will be hidden in Linux or Unix Environment.

Difference between Linked List and Array in Java? Example

Array and linked lists are two fundamental data structures in the programming world. Almost all programs use Array in some form or other, which makes it increasingly important to learn array and linked list. The difference between the linked list and array data structure is also a popular data structure question, frequently asked in the various programming job interviews. This makes it even more important to learn and understand the difference between an array and a linked list. Well, there are a lot of differences between these two starting from how they store data, to how you retrieve data from them.

Tuesday, May 23, 2023

How to merge two sorted arrays in Java? Example Tutorial

Hello guys, if you want to learn how to merge two sorted arrays in Java then you have come to the right place. Earlier, I have shown you how to sort arrays in Javaand in this article, I will show you how to merge two sorted arrays in Java. Btw, if you are a complete beginner then Firstly, you need to know what an array is before going about solving this problem about sorted array.  An array is a data structure in Java that holds values of the same type with its length specified right from creation time. This means you can create an integer array like int[] to store integer value. Think of a container, like a crate of eggs or coke, where number of places are fixed and you cannot change once you created it.

How to implement Strategy Design Pattern in Java? (with Real World Example, Pros and Cons)

Strategy Design pattern is one of most useful versatile pattern, you will often see used in Object Oriented design. This pattern is one of the behavioral pattern mentioned by famous Gang of Four in there design pattern classics Elements of Reusable Design Pattern is Software development. As per definition goes, Strategy pattern allows you to encapsulate a set of algorithms and make them interchangeable. The best thing about Strategy pattern is that it allows you to pass a dynamic code to a method much like Lambda expression. In fact, it was one of the way to achieve same effect prior to Java 8. Also, there are multiple example of Strategy Pattern in JDK itself like Comparator and Comparable are the best example of Strategy Pattern in Java. 

Java 8 Predicate Functional Interface Example [Tutorial]

In Java 8, there is a defined functional interface which is called Predicate. The Predicate interface receives an argument and based on specific condition it returns Boolean value. It can be helpful in testing and it’s located in java.util.Function package. This is one of the many pre-defined or built-in functional interface which JDK provides. A couple of important ones are Supplier which can be used to produce a value of T (any object) and Consumer which can consume and project like takes data and print to console. forEach() is a good example of method accepting Consumer interface. Similarly many method accept a Predicate and when they do you can simply pass a lambda which generates a boolean by checking a condition. 

5 Ways to convert int to String in Java - Example Tutorial

If you have an int variable and wants to convert that into String object e.g. 1 to "1" or 10 to "10" then you have come to right place. In the past I have show explained Enum to Stringhow to convert String to float, String to double, String to int , and String to boolean and in this article, I will show you how to convert an int to String in Java. And, not one or two but I will show you 4 different ways to convert an int to String in Java, from easy to difficult and from common to unknown. Even though it's good to know multiple ways to solve a problem e.g. to perform this conversion, I will also suggest you what is the best way to convert int to String and why?

Difference between @Autowired and @Qualifier Annotation in Spring Framework? Example Tutorial

Hello Java programmers, the difference between @Autowired and @Qualifier annotations in Spring is a common question frequently asked in Spring on Java interviews, and if you are looking for an answer then you have come to the right place. Earlier, I have shared the best Spring courses and books, and in this article, Since most Java developers are familiar with annotations in Spring, they need to understand the difference between them and where to use them. Autowiring is a Spring Framework feature that enables you to inject the object dependency implicitly. This was added to Spring 2.5 to make an annotations-driven dependency injection that helps to "injects" objects into other objects or "dependencies." 

How to do Pagination in Oracle Database - SQL Query With Example

Many times we need an SQL query that returns data page by page i.e. 30 or 40 records at a time, which can be specified as the page size. In fact, Database pagination is a common requirement of Java web developers, especially dealing with the largest data sets.  In this article, we will see how to query Oracle 10g database for pagination or how to retrieve data using paging from Oracle. Many Java programmer also uses display tag for paging in JSP which supports both internal and external paging. In the case of internal paging, all data is loaded into memory in one shot and the display tag handles pagination based upon page size but it is only suitable for small data where you can afford those many objects in memory.

How to Remove Leading/Trailing White Space from a String in SQL Server? LTRIM, RTRIM Example

Unlike Java, Microsoft SQL Server 2008, 2012, 2014,  and even the latest version don't have a built-in trim() function, which can remove both leading and trailing space from the given String. But, SQL Server does have two built-in functions LTRIM() and RTRIM() to remove leading and trailing space. The LTRIM() function removes space from the left side of String so you can use it to get rid of leading space, while RTRIM() removes white-space from the right side of String so you can use it to delete trailing space. You can even combine these two methods to create your own TRIM() method in SQL SERVER e.g. LTRIM(RTRIM(column)) will act as a TRIM() method because it removes both leading and trailing space.

Top 30 Examples of MySQL Commands in Linux and UNIX

Hello guys, if you are working with MySQL database in Linux and looking for MySQL commands to perform common tasks like starting and stopping a MySQL server then you have come to the right place. I have been working with MySQL since last 15 years as Java developer and it was actually the first database I used in a real-world project. Since I need to work with the MySQL database daily, I compiled a list of MySQL commands which I keep handy. This saves me a lot of time while doing development and support and that's what I am going to share with you today. 

Difference between Truncate and Delete in SQL? Example

Truncate and delete in SQL are two commands which are used to remove or delete data from a table. Though quite basic in nature both SQL commands can create a lot of trouble until you are familiar with details before using it. The difference between Truncate and delete are not just important to understand perspective but also a very popular SQL interview topic which in my opinion a definite worthy topic. What makes them tricky is the amount of data. Since most Electronic trading system stores, large amounts of transactional data, and some even maintain historical data, a good understanding of delete and the truncate command is required to effectively work in that environment.

Monday, May 22, 2023

Difference between Clustered Index and Non Clustered Index in SQL - Example

In the SQL Server database, there are mainly two types of indexes, Clustered index, and the Non-Clustered index and difference between Clustered and Non-Clustered index are very important from an SQL performance perspective. It is also one of the most common SQL Interview questions, similar to the difference between truncate and delete,  primary key or unique key, or correlated vs non-correlated subquery. For those, who are not aware of the benefits of Index or why we use an index in the database, they help in making your SELECT query faster. 

Difference between Primary key vs Foreign key in table – SQL Tutorial Example

The main difference between the Primary key and the Foreign key in a table is that it’s the same column that behaves as the primary key in the parent table and as a foreign key in a child table. For example in the Customer and Order relationship, customer_id is the primary key in the Customer table but a foreign key in the Order table. By the way, what is a foreign key in a table and the difference between Primary and Foreign key are some of the popular SQL interview questions, much like truncate vs delete in SQL or difference between correlated and noncorrelated subqueryWe have been learning key SQL concepts along with these frequently asked SQL questions and in this SQL tutorial, we will discuss what is a foreign key in SQL and the purpose of the foreign key in any table. 

Database Website to Run and Practice SQL Query Online for FREE - SQLFiddle

Another day, I was looking for a website to execute SQL query online, since I have uninstalled Microsoft SQL Server because of memory and CPU constraint and I don't want to install it again, just for executing another query. Also, installing database is pain, it takes time and eats up lots of resources e.g. RAM memory, CPU, etc; Given so many databases to work with e.g. Oracle, MySQL, Sybase, PostgreSQL, and SQLLite, it's not really possible to have all of them in your poor laptop. Fortunately, my search leads me to this wonderful site called SQLFiddle, this is what exactly I wanted. This site offers support for a lot of popular databases, allows you to build your database schema online, and execute SQL query on the fly.

What is Referential Integrity in Database or SQL - MySQL Example Tutorial

Referential Integrity is a set of constraints applied to foreign keys which prevents entering a row in the child table (where you have the foreign key) for which you don't have any corresponding row in the parent table i.e. entering NULL or invalid foreign keys. Referential Integrity prevents your table from having incorrect or incomplete relationships e.g. If you have two tables Order and Customer where Customer is parent table with primary key customer_id and Order is child table with foreign key customer_id. Since as per business rules you can not have an Order without a Customer and this business rule can be implemented using referential integrity in SQL on a relational database.

Difference between SQL, T-SQL and PL/SQL?

Hello guys, if you are preparing for SQL and Database Interviews or any Software engineering interview and looking for difference between T-SQL, SQL, and PL/SQL then you have come to the right place. Earlier, I have shared 50 SQL Interview questions and 12 SQL query Examples from interviews and today, we are going to see another common and interesting SQL interview question, what is the difference between SQL, T-SQL, and PL/SQL? It is also one of the most common doubts among SQL beginners. It's common for programmers to think that why there are many types of SQL languages, why not just single SQL across DB? etc. Well, let's first understand the difference between SQL, T-SQL, and PL/SQL, and then we will understand the need for these dialects. 

Difference between IsNull and Coalesce in Microsoft SQL Server (with Examples)

Even though both ISNULL and COALESCE is used to provide default values for NULLs there are some key differences between them like ISNULL() is a T-SQL or Microsoft SQL Server-specific function or operator, and datatype and length of the result depends upon a parameter, but COALESCE is a SQL ANSI standard, it can accept more than one parameter and unlike ISNULL, the result doesn't directly depend upon a parameter, it is always the type and length of the value returned. Also, what is the difference between COALESCE and ISNULL is one of the frequently asked Microsoft SQL Server interview questions, and knowing these differences can help in both your day-to-day SQL development works and during job interviews.

Difference between close and deallocate cursor in SQL

Cursor in a database is used to retrieve data from the result set, mostly one row at a time. You can use Cursor to update records and perform an operation a row by row. Given its importance on SQL and Stored procedures, Cursor is also very popular in SQL interviews. One of the popular SQL questions on Cursor is close vs deallocate. Since both of them sounds to close the cursor, once the job is done, What is the real difference between close and deallocate of Cursor in SQL? Well, there is some subtle difference e.g. closing a cursor doesn't change its definition. In Sybase particular, you can reopen a closed cursor and when you reopen it, it creates a new cursor based upon the same SELECT query.

3 Ways to Remove Duplicates from a table in SQL - Query Example

There are a couple of ways to remove duplicate rows from a table in SQL e.g. you can use temp tables or a window function like row_number() to generate artificial ranking and remove the duplicates. By using a temp table, you can first copy all unique records into a temp table and then delete all data from the original table and then copy unique records again to the original table. This way, all duplicate rows will be removed, but with large tables, this solution will require additional space of the same magnitude as the original table. The second approach doesn't require extra space as it removes duplicate rows directly from the table. It uses a ranking function like row_number() to assign a row number to each row.

Top 25 DevOps Interview Questions and Answers for Experienced Developers

Hello guys, if you re preparing for DevOps Engineer interviews and looking for frequently asked DevOps Interview questions then you have come to the right place. Earlier, I have shared the DevOps RoadMapbest DevOps Courses, and DevOps books and in this article, I will share the frequently asked DevOps Interview Questions and their Answers. But, before we get to the most frequently asked DevOps interview questions, let me tell you what DevOps actually is. DevOps is basically a way of thinking or a collective approach to all the tasks that a company's application development and IT operation teams perform but it has taken the IT software development world by storm.

How to use useDispatch and useSelector? React Hooks Example Tutorial

Hello guys, if you are learning about React hooks and wondering how to use useDispatch and useSelector hooks in React application then you have come to the right place. Earlier,, I have shared the best React courseswebsites, and books and in this article, I am going to show you how React hooks make coding and statement management easier than it was before. The introduction of React hooks changed a lot in the react application development. Developers moved from complicated and length class-based components to simpler functional components that can do the same work in fewer lines of code. 

Sunday, May 21, 2023

Top 20 JSON Interview Questions with Answers for Beginners and Experienced Developers

Hello guys, if you are doing for a web developer interview or a Java web developer interview where you need to write server side application or backend code which uses HTTP to send and receive data then you should prepare about JSON. It's one of the most popular way to exchange data between two systems or between frontend and backend, client and server and most of the top programming language has API to create and parse JSON like Java has Jackson and JavaScript can by default support JSON because its nothing but JavaScript Object Notation.  JSON is also the default data format for REST API  and even GraphQL uses JSON to send request and receive response. 

Top 10 Free Online Tools to View and Validate JSON for Java and Web Developers

Hello guys, if you are working as Java or Web developer then you may know that JSON is one of the most popular format of exchanging data between client and server in modern web world. Almost all REST based Web services are now supporting JSON as preferred exchange format because of its competitive advantage over XML in terms of size, flexibility, and speed. With growing adoption of JSON as format to exchange data between systems, the number of tools and libraries have also increased. You will find several libraries to support JSON in various programming languages like  Jackson and Gson in Java and JSON Gems in Ruby

How to iterate over JSONObject in Java to print all key values? Example Tutorial

Hello guys, if you are wondering how to iterate over a JSONObject in Java and print all its fields and values then you have come to the right place. In this article, I will show you how you can print all data from JSONObject in Java. If you know, In json-simple library, one of the top 5 and lightweight JSON library, JSON object is a wrapper class which contains the actual JSON message. In the last article, I have explained how to parse JSON in Java using json-simple library and one question which pops up can we iterate over JSONObject properties? Well, yes, you can iterate over all JSON properties and also get the values from the JSONObject itself. In this article, I'll show you how you can print all keys and value from JSON message using JSONOjbect and Iterator.

Top 35 React.js Interview Questions Answers for Fullstack Java Developers

Hello guys, if you are preparing for React developer interviews and looking for frequently asked React.js interview questions then you have come to the right place. Earlier, I have shared the best courses, books, and websites to learn React.js and in this article, I am going to share 35 frequently asked React.js interview questions, suitable for 1 to 2 years experience developers. ReactJS is one of the most recently built open-source front-end programming languages. It came directly from Facebook's headquarter back in 2011. Earlier Recat.js was only limited to Facebook but now, it is one of the most extensively used programming languages all across the world.

What is state in React.js? useState Hook Example Tutorial

Hello guys, I have just started a new series, React for Java developers and I am going to publish React tutorials and examples to teach React.js, one of the most popular frontend libraries to Java developers. Since most full-stack Java development is happening on React and Spring Boot, it makes sense for Java developers to learn React.js. In the past, I have also shared both best React courses and books, as well as The React Developer RoadMap, which provides all the tools, libraries, and resources you need to become a proficient React Developer. 

Difference between var, let, and const in JavaScript? Example Tutorial

Hello guys, there are many ways to declare variables in JavaScript like var, let, and const and many JavaScript developer get confused when to use which keyword for declaring a variable in JavaScript. If you also have same doubt and want to understand the difference between var, let, and const in JavaScript then you have come to the right place. This is one of the popular JavaScript interview questions and frequently asked during telephonic and face-to-face round of web developer interview. Knowing the difference will not only make you answer this question better during interview but also to write better JavaScript code in your day-to-day work. Earlier, I have shared the best books and JavaScript courses for beginners and in this article, I will tell you the difference between varlet, and const and when to use them. They are three different ways to declare variables in JavaScript. 

How to use props in React.js? Functional and Class Component + Properties Example Tutorial

Hello guys, If you have ever worked with React.js, one of the popular JavaScript library for building UI components then you definitely know what components are. A React application is made of several components and that is why components in React are defined as the building blocks of the application. In simple terms, a component is a class or function that can accept input and return a piece of code that defines a UI. Every React component can have input. These inputs are known as props. Props stand for properties and they are optional. A component works fine without props but they are one of the most useful parts of React.

React.js useState, useEffect and useDispatch Hooks Example - Tutorial

Hello guys, if you want to learn about Hooks in React.js like useState, useSelector, useEffect, and useDispatch then you have come to the right place. In the past, I have shared the best React courseswebsites, and books and in this article, I am going to show you what is React hooks and how they make coding and statement management easier in React.js. If you remember, React.js is created by Facebook and ever since it came out in 2013 and since then, it has become one of the biggest players in the front-end development community. Today, React.js demand for frontend development is more than any other framework or library. There are several reasons for its popularity. React is flexible, easy to learn, programmer-friendly, and most importantly, it's high performing. 

Student Management System Project - FullStack Java + Spring Boot + React.js Example Tutorial

Hello Java programmers, if you want to learn Spring Boot and Reactjs and looking for a full-stack Java example or a mini project then you have come to the right place. Earlier, I have shared the best Spring Boot coursesbooks, and best reactjs courses as well as many courses to learn full-stack development in Java and become a full-stack java developer. In this mini project, you will learn how to create an application that is capable of creating, deleting, updating, and retrieving functions using the Spring Boot, React, and H2 Database. In this tutorial you will create a School Classroom Application that can insert, update, delete and search students. The frontend of the application is developed using Reactjs and also the backend is developed using spring boot. And, most importantly communication between the two platforms will be done using the REST APIs. 

Friday, May 19, 2023

Udemy Course Review - Is Modern HTML & CSS From The Beginning Worth it?

Hello guys, if you want to learn HTML and CSS from scratch and in depth and looking for best resources like online courses, books, tutorials, and websites then you have come to the right place. In the past, I have shared both best paid HTML courses as well as best free HTML and CSS courses and in this article, we are going to review one of the best Udemy course to learn HTML and CSS, The Modern HTML & CSS From the Beginning by none other than Brad Traversy. The websites contain two things: the front-end code, which is what you see on the screen, and the back-end code, which happens inside the website, like making an account or searching. There are many front-end languages you need to learn to make a stunning website, but HTML and CSS are the first and easy choices for any developer to learn, and this course will help you master them.

How to return JSON, XML or Thymeleaf Views from Spring MVC Controller? Example Tutorial

Hello guys, if you are working in Spring based web application and you wan to return JSON, XML, or Thymeleaf View from your application but don't know how to do that then you have come to the right place. Earlier, I have shared how to create REST API in Spring, React + Spring project, and Spring Boot Interview Questions  and In this tutorial we are going to discuss, how to return to JSON, XML, or Thymeleaf view from the Spring MVC controller. To ensure that your payload from the MVC endpoint, ensure your project is using the Spring Boot starter web. You can use the following dependency to include spring boot starter web in your project. 

Top 5 Spring MVC Annotations for RESTful Web Services in Java

Hello guys, Spring framework is one of the most popular Java framework and Spring MVC is probably the most common way to develop web applications in Java, but things just doesn't end there. In the past a couple of years, Spring has become the best way to develop RESTful Web services in Java. Despite numerous RESTful Web Service frameworks in Java world e.g. Restlet, Jersey, RESTEasy, and Apache CFX, Spring MVC has maintained its position as the leading framework for creating RESTful APIs in Java, and there are multiple reason why Spring is the best framework for Java developers for creating RESTful solutions and we will look one of them in this article. 

How to test a Spring Boot Application using JUnit, Mockito, and @SpringBootTest? Example Tutorial

Hello guys, if you are wondering how to test your Spring Boot application then you are at the right place. In the past, I have shared several Spring and Spring Boot resources like best Spring boot coursesbest Spring Boot booksSpring Boot Interview questions and even Spring Boot projects and in this article, I am going to share how to test your Spring Boot application using @SpringBoot annotation. This article will teach you essential concept for testing Spring Boot applications. It's expected that you are know about essentially the fundamentals of Java, Maven and Spring Boot (Controllers, Dependencies, Database Repository, and so on).

What is @SpringBootTest Annotation in Java and Spring? How to use it? Example Tutorial

Hello guys, if you want to learn what is @SpringBootTest annotation and how to use this annotation to test your Spring Boot application then you have come to the right place. The @SpringBootTest annotation is a powerful annotation in Spring framework which is used to load entire application context for Spring Boot application and create integration test. It allows you to test your application in the same way as it runs on production. You can use this annotation to test your controller, service, repository classes and every other part of your Java Spring Boot application. Earlier, I have shared the best Spring Boot courses and Spring Boot Testing interview questions and in this article, I am going to explain to you about @SpringBootTest annotation. Before diving into how to use @SpringBootTest annotation. It is good to briefly introduce Testing in Spring boot. 

Spring Data JPA @Query Example - Tutorial

Hello guys, if you are learning Spring Data JPA framework or using Spring Data JPA in your project and are not sure how to use @Query annotation then you have come to the right place. Earlier, I have shared the best Spring Data JPA courses and Spring Data JPA Interview questions and in this article, I am going to show you how to use @Query annotation from Spring Data JPA to create dynamic SQL queries. Spring is a popular Java application framework for creating enterprise applications and Spring Boot is an evolution of the Spring framework which helps to create standalone applications in a minimal effort. In this tutorial, we are going to discuss how to create queries using Spring Data JPA with an example. So let’s have a look with a Spring data JPA @Query example.

How to validate HTTP POST Request Payload on Spring MVC controller? Example Tutorial

Hello guys, if you are wondering how to validate incoming request payload in Spring MVC based Java web application then you have come to the right place. You can use JSR-303 Bean Validation Framework and @Valid annotation in Spring MVC to check the request data on POST request.  Earlier, I have sharebest Spring MVC courses for Java developers and In this tutorial, we are going to discuss how to validate incoming payloads on the Spring MVC controller which is also can be defined as validating the request body in the RESTful web services. So first let's have a look at validating the request body in the RESTful web services. Think you have a JSON post request and you are going to consume it. There should be a validation to this post request as the requested input will be zero or in a not accepted format.

Thursday, May 18, 2023

How to fix "java.lang.SecurityException: Missing required Permissions manifest attribute in main jar" [Solved]

If you are working Java Web start application using JNLP and suddenly started throwing "java.lang.SecurityException: Missing required Permissions manifest attribute in the main jar", then check whether you have updated the Java or JRE on your machine. From JDK 1.7 update 51, Java has tightened the security further with a number of changes like

1) Block all self-signed and unsigned Java applications and Applets if you have opted for HIGH security in Java Control Panel, which is also the default one.

2) Require a "Permission" attribute for a High-security setting

3) Warning users of missing permission attributes for the medium security settings.

How to deal with Java.rmi.MarshalException: CORBA MARSHAL in Java? Solution

Java has some mysterious RMI exceptions one of them is java.rmi.MarshalException: CORBA MARSHAL, which was bothering me for the last couple of days while working. I thought to put this solution post similar to my earlier post How to solve OutofMEmoryError in Java and Fixing ClassNotFoundException in Java. RMI is still used in many places and many times it creates too many problems and chew-up your a lot of time to find the exact cause and solution.

How to fix java.io.IOException: Map failed and java.lang.OutOfMemoryError: Map failed? Example

While working with memory mapped file, you may get java.io.IOException: Map failed error, which is mainly caused by Caused by: java.lang.OutOfMemoryError: Map failed error as shown below. This error usually comes while mapping a big file in memory e.g. trying to map a file greater than 1 or 2GB

java.io.IOException: Map failed
 at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:888)
Caused by: java.lang.OutOfMemoryError: Map failed
 at sun.nio.ch.FileChannelImpl.map0(Native Method)
 at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:885)
 ... 6 more

How to fix "No Property Found for Type class " Exception in Spring Data JPA [Solved]

Hello guys, if you are struggling with "No property save found for type class" In while working with Spring Data JPA then you have come to the right place. Earlier, I have shared the best Spring Data JPA courses and in this tutorial, we are going to discuss how to fix Spring Data JPA - "No property found for type" exception. This is a common type of error that we can find on Spring applications because of many reasons. We are going to discuss some of the occasions where this error happens and it may help to solve the error. So we will go with examples of what kind of problems that the developer's might get related to the "No property found for type" exception in Spring Data JPA.

[Solved] How to fix VirtualBox - /sbin/mount.vboxsf: mounting failed with the error: Protocol error

Virtual box is a great tool for Java developer to run Docker and Linux on Windows Machine, especiall for them who need to develop and debug Java program in Linux environment. I use Oracle's virtual machine, VirtualBox to run the Linux operating system from my Windows machine. It's the most simple way to have two operating systems on your laptop or PC. Since I run most of the Java programs in Linux, VirtualBox gives me a nice interface to run UNIX commands right from the Windows box. This blog post is about the mounting of a shared folder failed error in Oracle's Virtualbox VM. It was working fine the day before yesterday and now, after I restarted my virtual box and tried to mount my shared folder, I was greeted by this error: "/sbin/mount.vboxsf: mounting failed with the error: Protocol error"

How to fix Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory in Java

This error means your code or any external library you are using in your application is using the SLF4J library, an open source logging library, but it is not able to find the required JAR file e.g. slf4j-api-1.7.2.jar hence it's throwing Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory. If you look at the error, you will see that it's saying it is not able to find the class org/slf4j/LoggerFactory or org.slf4j.LoggerFactory. The package name indicates that it's part of SLF4j, hence you need SLF4j JAR files e.g. slf4j-api-1.7.2.jar in your application's classpath. So, go ahead and download the JAR file from SLFj website or from Maven Central repository and restart your application.

How to fix invalid target release: 1.7, 1.8, 1.9, or 1.10 Error in Maven Build? Solution

If you are building your Java project using Maven, maybe in Eclipse or from the command prompt by running mvn install and your build is failing with an error like "invalid target release: 1.7" or "invalid target release: 1.8" then you have come to the right place. In this article, I'll show you the reason why this error occurs and how you can deal with these errors even with higher Java versions like Java 9, 10 installed on your machine, or maybe with Java 11 in the coming month. The root cause of the problem is that you have specified a higher Java version in your pom.xml file for the Maven compiler plugin than what Maven knows in your system, and that's why it's saying invalid target release.

How to Fix NullPointerException due to Space in HQL named queries in Hibernate? Example

If you are using Hibernate for implementing the persistence layer in Java and JEE application from a couple of years then you would have seen this notorious NullPointerException while executing HQL named queries, Exception in thread “main” java.lang.NullPointerException at org.hibernate.hql.ast.ParameterTranslationsImpl .getNamedParameterExpectedType (ParameterTranslationsImpl.java:63).  Hibernate has some poor logging in case of Exception, which has caused me hours to debug a simple problem. By looking at NullPointerException below (look full stack trace below), I had no clue that it's coming because of a missing space on the HQL (Hibernate Query language) query. 

How to Fix java.lang.UnsatisfiedLinkError: lwjgl64.dll : Access Denied Error? Minecraft Solution

You can resolve java.lang.UnsatisfiedLinkError: lwjgl64.dll : Access Denied error in Minecraft by disabling your anti-virus and run. Later you can whitelist the lwjgl64.dll so that your anti-virus will not block it again. I have talked about java.lang.UnsatisfiedLinkError a couple of times on this blog e.g. here and here. But, today I am going to show you one more real-life example of java.lang.UnsatisfiedLinkError, which is more interesting. We'll also learn and how to deal with that. This problem is related to Minecraft, one of the most popular games written in Java. Precisely, we are going to solve the "Exception in thread "main" java.lang.UnsatisfiedLinkError: lwjgl64.dll: Access denied" error.

How to Fix java.net.SocketException: Failed to read from SocketChannel: Connection reset by peer? Example

You might have seen the java.net.SocketException: Failed to read from SocketChannel: Connection reset by peer error while working with Java NIO based server which is using SocketChannel instead of InputStream for reading data from the network. In general, this can come at both client and server end of a client-server Java application which is using TCP/IP to connect each other. Though this exception usually comes at the server end and the client was complaining that they are not able to connect.  From the error message, it's quite clear that before the client or server could read the data from SocketChannel, another party has disconnected the session. Let's see the root cause of the problem and how to solve java.net.SocketException: Failed to read from SocketChannel: Connection reset by a peer in Java application.

How to fix java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer? [Solution]

The error message clearly says that the Java runtime is not able to find a class called ServletContainer for the Jersey library. This is the Servlet class you have specified in the deployment descriptor of your application. It's similar to DispatcherServlet of Spring MVC and this error is similar to the error you get when DisplayServlet was not in the classpath.
Anyway, java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer comes when you are trying to use Jersey but have not added required dependency on your classpath e.g. those JAR files which contain the class "com.sun.jersey.spi.container.servlet.ServletContainer".

Wednesday, May 17, 2023

Data Visualization with Tableau Specialization Review - Is it worth it?

In this modern age with large data and technology, data visualization is becoming a more important in-demand job among companies since they need to analyze that data and visualize them to get more information about their customers, revenue, and more. Data visualization is the process of converting a large amount of data into charts to have a more clear view of what’s going inside your company, as they say, a picture worth a thousand words. Learning these skills is a must in many job fields if you are going to be a data analyst, data scientist, machine learning engineer, and many other fields, just to name a few. There are many software and programming languages such as python and R to make data visualization.