Friday, April 29, 2022

How to create an ArrayList from array in Java? Example

One of the common problems faced by junior and less experienced Java develoeprs is converting an arrray to ArrayList e.g. they are getting an array from somewhere in their code and then want to create an ArrayList out of that, so that they can add more elements and use other library methods which operates with ArrayList or List. The simplest way to convert an array to ArrayList is by usign the Arrays.asList() method, which acts a bridge between Collection classes and array data structure. This method returns a List which contains elements from array.

Thursday, April 28, 2022

Difference between Proxy and Decorator Pattern in Java

Though both Proxy and Decorator pattern looks very similar to each other structurally, there are some key differences between them. Main difference between Decorator and Proxy patterns comes from their Intent. Proxy word has a long standing meaning and in software world also a Proxy class stands for its implementation class, which presents lots of options to programmer, resulting in different kinds of proxy objects like remote proxy, virtual proxy, and protection proxy. On the other hand, Decorator pattern is used to add new functionality into existing object without modifying it's class. So their usage is entirely different.

Wednesday, April 27, 2022

Unix command to find IP address from hostname - Linux example

The IP address from hostname in UNIX
In this Unix command tutorial, we will see how to find the IP address of any host in a UNIX based system, like Linux, Solaris, or IBM AIX. In general hostname and IP address are two important things about any host in a UNIX based network.  You always need either a hostname or IP address to connect to any host. Sometimes you want to find the IP address of the localhost, sometimes the IP address of another host on the network, etc. We have shown some techniques to find the IP address from hostname in UNIX and here we will see is a particular list of UNIX commands to get the IP address of local host or host on which you are working along with any other host for which we know hostname.

How to find Files with Matching String in Linux? grep -l command Example

The grep command from Linux is one of the powerful commands to find files containing some text, but when you use grep, it not only print the file name but also the line, which is including the matching text. This is actually required and needed in most situations. Still, sometimes you only want to grep to show just filename and path and not the matching text. For example, when you are searching for some configurations like a Linux or database hostname across all configuration files in your application host, then you just want to see which file has contained those references.

6 Essential Data Structures Java Programmer should Learn

Hello guys, Data Structure is a building block of programs. It's even said that  "Data Structure + Algorithms= Program". That's why a good knowledge of data structure is very important for any programmers, including Java developers. Data structure gives you the option to store your data so that you can access it based on your requirement. For example, if you want a fast search based upon the username then you can use HashMap, but that's only possible if you know data structure and their implementations in the programming language you are using, and that's what you will learn in this article. 

13 Java Serialization Interview Questions with Answers for 3 to 5 Years Experienced

There is no doubt that Java is vast and there are some Java topics which many Java developers rarely explore in work but they are important from a Java interview point of view. Serialization is one of them which is rarely used in practice but quite popular during Java interviews. It's also one of the difficult topics to master and that's why I am going to share some frequently asked Java Serialization interview questions in this article.  I don't know why people ask so many questions from Serialization if not everyone uses it but I have always seen some questions from Java realization. These are also the toughest and confusing questions to answer and more likely cannot be answered by an average Java developer.

Tuesday, April 26, 2022

10 Regular Expressions Every Java Programmer Should Learn

Regular Expression or regex or regexp is used for String or text matching. You specify a regular expression and then run input String to see if any String matches with your regular expression. There are a lot of use cases of regular expression e.g. you can do find and replace and you can actually search in a big log file for the expression or text you are looking it. Regular expression is not just limited to any programming language like Java but it present everywhere. You use Regular expression in Linux for pattern matching like with grep, find, sed and awk command. Even VI editor allows you to search words using regular expression and popular Windows text editor like Notepad++ and Edit Plus they also support regular expression for search and replace.

Top 70 Java Interview Questions for Junior Developers [1 to 2 Years Experienced]

Java Developer Interviews are very different than traditional software developer interviews. You can clear a Java interview without even writing a single line of code, Yes, this is true, you can become a Java developer without someone asking you to write a function in a Java interview. Though it's not the case everywhere and many companies are increasingly including a coding test in their Java developer interview process, but there are many companies and start-ups where you can get a Java job without writing a single line of code. All you need to do is learn those popular Java questions, which have been asked for ages, and mostly test whether a candidate is familiar with essential Java concepts or not like abstract class and interface. 

Top 5 Free JavaScript Books for Beginners - Download PDF or Read Online

The internet is full of good things, and one of them is free eBooks and PDF. Programmers can almost run anything by these free books. Earlier I have shared some of the free JavaScript tutorials, and in this article, I am going to share 5 good books to learn JavaScript, which are open to read online or allow you to download PDF for offline reading. JavaScript is probably another language I recommend someone who knows Java, Why? Because it's really ubiquitous. There is almost no website that is not using JavaScript in one or another format.

Difference between Set, List and Map in Java - Interview question

Set, List and Map are three important interfaces of the Java collection framework, and the difference between Set, List, and Map in Java is one of the most frequently asked Java Collection interview questions. Sometimes this question is asked as When to use List, Set and Map in Java. Clearly, the interviewer is looking to know that whether you are familiar with the fundamentals of the Java collection framework or not. In order to decide when to use List, Set or Map, you need to know what are these interfaces and what functionality they provide. List in Java provides ordered and indexed collection which may contain duplicates. 

Difference between Heap and Stack Memory in Java? [Explained]

One of the many traits of a good programmer is how well he understands the fundamentals and if you want to check the fundamentals of a Java programmer then asking the difference between heap and stack memory is a good choice. Even though both are part of JVM and both consumer's memory allocated to the Java process, there are many differences between them like Heap memory is shared by all threads of Java application but Stack memory is local to each thread. Objects are created in heap memory but method frames are stored in Stack memory, and the size of heap space is much bigger than the small size of Stack in Java.

Monday, April 25, 2022

Top 80 Core Java Interview Questions with Answers

Hey Java programmers, if you are preparing for a Core Java interview and looking for some frequently asked Java interview questions for quick revision then you have come to the right place. Earlier, I have shared the best books and best courses for Java interviews.  I have also shared many posts about Java Interview Questions and in this article, I will share Java Interview questions and answers especially for junior Java programmers, someone with 1 to 3 years of experience. This includes college graduates, who are looking for the job, Java programmers who have 1 to 2 years of experience in Java, and junior developers who have 2 to 3 years of experience in Java, C++, etc. 

10 Free Java Programing Books for beginners - download, pdf and HTML

Every Java programmer loves free eBooks on Java, don't you? When I shared my collection of top 10 Java programming books, one of my readers asked me to share some free Java books as well. Doing a quick search on the internet reveals lots of free books, resources, and tutorials to learn Java. I have chosen some of the good Java books, which are FREE, available for download or you can read it online in HTML or PDF format. These books are an excellent resource for any Java beginners, as well as an experienced programmer, and since they are free, it makes absolute sense to have a look on this before buying any other book in Java.

Wednesday, April 20, 2022

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

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

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

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

Monday, April 18, 2022

How to use CountDownLatch in Java? Example

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

Saturday, April 16, 2022

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

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

Monday, April 11, 2022

How to use CompletableFuture in Java? Example Tutorial

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

Saturday, April 9, 2022

How to Print Floyd's Triangle in Java - Example Tutorial

Hello guys, In the last article, I have taught you how to print Pascal's triangle and in today's article, I'll teach you how to print Floyd's triangle in the Java program. Floyd's triangle is easier to print than Pascal's triangle because you don't need to take care of formatting the numbers as Floyd's triangle is a right-angle triangle. It is named after American computer scientist Robert Floyd, who has also contributed Floyd–Warshall algorithm, which efficiently finds all shortest paths in a graph, and Floyd's cycle-finding algorithm for detecting cycles in a sequence. 

Matrix Multiplication in Java using Scanner, Class, and Function [Example]

Hello guys, if you are looking for a matrix multiplication example in Java using the scanner for user input, and using class and object-oriented programming then you have come to the right place. In this Java tutorial, I will show you how to multiply matrix in Java using an array, scanner, and object-oriented programming. We will create a class to represent matrix and then define a multiplication method to multiply two matrices in Java. I first learned about matrix in class 12th and I first wrote the program to multiply two matrices on my first semester of engineering, so, when I thought about this program, It brings a lot of memories from the past. 

Thursday, April 7, 2022

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

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

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

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

Post order traversal Algorithms for Binary Tree in Java with example

In the last couple of articles, you have learned about pre-order and in-order tree traversal algorithms in Java, and today, you will learn about the post-order traversal in a binary tree. It is the toughest of all three tree traversal algorithms and programmers generally struggle to implement this when asked in a coding interview. Hence it makes sense to understand and practice this algorithm before going for the interview. The post order traversal is also a depth-first algorithm because you go deep before you visit other nodes on the same level.