HTML

How to Convert Stream to ArrayList in Java 8 - Collectors.toCollection() Example, Tutorial

You can use Collectors.toList(), toSet() and toMap() to get all elements of Stream into any Collection e.g. List, Set or Map, but if you want to get a particular collection e.g. ArrayList, then you need to use Collectors.toCollection(ArrayList::new) method. This method first creates an ArrayList using method reference and then adds all elements of Stream into the ArrayList. It's very useful if you have a long list of String and you want to create a smaller list containing only String starting with the letter "b" e.g. "Bluehost". All you need to do is first get the stream from List by calling stream() method, then call the filter() method to create a new Stream of filtered values and finally call the Collectors.toCollection(ArrayList::new) to collect those elements into an ArrayList.

3 Examples to Loop Through a List in Java 8

3 ways to Loop through a List in Java
There are multiple ways to traverse or loop through a List in Java e.g. by using an Iterator, by using an enhanced for loop of Java 5, and not the forEach() method of Java 8. Given a List is an index based collection if you know the index you can retrieve an object from List and because of this, you can also use traditional for loop which keeps count for iterating List. Now the question is whether should you use the Iterator or enhanced for loop, or the forEach() method of Java 8 for looping over List in Java. Well, it depends on what you are doing with the object, if you need to remove some objects from List than iterating using Iterator is best choice to avoid ConcurrentModificationExceptionbut if you are not removing any element and just doing some operation with each element than enhanced for loop is much cleaner ways to do that. 

5 Free HTML and CSS Courses to Learn Front End Web Development Online

HTML and CSS are two pillars of web development, they are used to create web pages you see every day. HTML provides the structure to your web page and CSS provides them the style to look better. If you want to become a front-end web developer or web designer then a good knowledge of HTML and CSS is a must. Even though modern day web development is all about framework and library e.g. Angular and React, you still need to know HTML and CSS to understand what's going on and troubleshoot any issue you face while developing a web application. Btw, JavaScript is another pillar of web development but we'll not discuss this article. I have already shared some good books and courses to learn JavaScript before

How to Remove Objects or Elements while Iterating over ArrayList in Java - The Right way

One of the common problems many Java Programmers face is to remove elements while iterating over ArrayList in Java because the intuitive solution doesn't work e.g. you just cannot go through an ArrayList using a for loop and remove an element depending upon some condition. Even though java.util.ArrayList provides remove() methods e.g. remove (int index) and remove (Object element), you cannot use them to remove elements while iterating over ArrayList in Java because they will throw ConcurrentModificationException if called during iteration. The right way to remove objects from ArrayList while iterating over it is by using the Iterator's remove() method.

What is double colon (::) operator in Java 8 - Example

The double colon (::) operator is known as the method reference in Java 8. Method references are expressions which have the same treatment as a lambda expression, but instead of providing a lambda body, they refer to an existing method by name. For example, to print all elements of the list you can use the forEach() method as follows

list.stream.forEach( s-> System.out.println(s));

but here you can replace lambda expression with method reference to improve readability as shown below:

list.stream.forEach( System.out::println);

You can use method reference or double colon operator to refer a static method, an instance method, or a constructor.

Default Methods, Multiple Inheritance and Diamond Problem in Java 8

Ever since Java 8 introduced default and static methods in JDK 8, it's become possible to define non-abstract methods in interfaces. Since in Java, one class can implement multiple interfaces and because there can be concrete methods in interfaces, the diamond problem has surfaced again. What will happen if two interface has methods o the same name and a Java class inherit from it? Many Java programmer also asks me the question that, is Java 8 is also supporting multiple inheritances of classes? Well, it's not but the doubt is genuine because interface with methods is similar to abstract class or in that any Class in Java.

How to Convert Stream to Array and ArrayList in Java 8 - Tutorial Example

It's relatively easy to convert a Stream to an array in Java 8 by using the toArray() method of java.util.Stream class. By using this method you can convert any type of Stream to a corresponding array like a Stream of Strings can be converted into an array of String, or a Stream of integers can be converted into an array of Integers. The Stream.toArray() method is also overloaded, the one which doesn't take any parameter returns an Object[] which might not be very useful, particularly if you want to convert Stream of T to array of T. On the other hand, the overloaded version of toArray(IntFunction[] generator) returns an array containing the elements of this stream, using the provided generator function to allocate the returned array, as well as any additional arrays that might be required for a partitioned execution or for resizing.

Top 5 Free jQuery Online Training Courses for Web Developers - Best of Lot

Hello guys, if you are thinking to learn jQuery and looking for some awesome free resources e.g. books, tutorials, and online courses then you have come to the right place. In this article, I am going to share some of the best free jQuery courses from Udemy and Pluarlsight which you can take to learn this awesome JavaScript library. In the past, I have also shared some free books and tutorials on jQuery, which complements these courses. You can also take a look at then while learning different parts of jQuery.  Before I share these free courses, let me brief you about what jQuery is and why you should learn it? Well, jQuery is a JavaScript library but unlike any other library it is very powerful and makes the client side scripting really easy.

Java 8 StringJoiner Example - How to join multiple Strings with delimiter in Java

While everyone was looking at the lambda expression and Stream API, JDK quietly sneaked some of the exciting methods on its API. There are a lot of hidden gems on JDK 8 and I have uncovered many of them already in this blog and today we'll talk about one of such gems which you can use in your day to day programming activities like joining much String together. The Java 8 has added a new class called StringJoiner to join Strings. The java.util.StringJoiner can be used to join any number of arbitrary String, a list of String, or an array of String in Java. You can choose any delimiter to join String like comma, pipe, colon or semi-colon. This class also allow you to specify a prefix and suffix while joining two or more String in Java.

Top 5 Free R Programming Courses for Data Scientists and ML Programmers

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

How to debug Java 8 Stream Pipeline - peek() method Example Tutorial

I have been writing about some important methods from Java SE 8  like map(), flatMap(), collect() etc from quite some time and today I'll share my experience about another useful method peek() from java.utill.stream.Stream class. The peek() method of Stream class can be very useful to debug and understand streams in Java 8. You can use the peek() method to see the elements as they flow from one step to another like when you use the filter() method for filtering, you can actually see how filtering is working e.g. lazy evaluation as well as which elements are filtered. the peek() method returns a stream consisting of the elements of this stream and performs the action requested by the client.

Java 8 filter + Stream Code Example

In the last couple of Java 8 tutorials, you have learned how to use map(), flatMap(), and other stream methods to get an understanding of how Java 8 Stream and Lambda expressions make it easy to perform the bulk data operation on Collection classes like List or Set. In this Java 8 tutorial, I am going to share how to use the filter() method in Java 8, another key method of Stream class.  This is the one method you will always be used because it forms the key part of Stream pipeline. If you have seen some Java 8 code, you would have already seen this method a couple of time. The filter() method as its name suggests is used to perform filtering based upon some boolean conditions.  The condition is applied to each element of Stream and those who pass the condition moves to the next stage and those who don't get filtered out.

Top 5 Free JDBC Courses for Java Programmers - Best of Lot

If you are a Java programmer and looking for some free JDBC courses to start learning database access in Java then you have come to the right place. In this article, I am going to share some of the free online JDBC (Java Database Connectivity) courses from popular sites like Udemy and Pluarlsight to give you a head-start in your long journey of writing real-world Java application which interacts with the database. Since Data is the utmost important part of any Java application, it's imperative to have a good knowledge of how to interact with the database from Java application and JDBC is the first step in that direction.

How Join Multiple String into One in Java 8 - String.join() Example

I have been writing about new features of Java SE 8 from quite a sometime. Initially, my focus areas on much talked about lambda expressions and streams, but slowly I realized that Java 8 is not just about them, it's much more than that. It has many more new features and API enhancements which will help Java developers in their day-to-day job as much as lambdas and streams. One of such less talked feature is the ability to join multiple String objects into one separated with any delimiter. It has added a class called StringJoiner in the java.util package which we have seen earlier, but it has also added a new method on String class, the join() method, which finally allows you to join Strings in Java.

Top 5 Free Ruby and Rails Courses to Learn Online - Best of Lot

Hello guys, welcome to this post, here you will find some of the best free courses to learn Ruby programming language and Ruby on Rails framework online. If you don't know what is Ruby and what is Rails framework then let me tell you that its one of the simplest programming language with little to no syntax. If you are new to programming or never coded before then also developing a Ruby application will be much easier than choosing any other programming language like Python or Java. When it comes to developing web development, the Ruby on Rails also makes your job easy by making several useful assumptions based upon convention, which means you can do more by writing less code.

How to convert Date to LocalDateTime in Java 8 - Example Tutorial

The LocalDateTime class has introduced in Java 8 to represents both date and time value. It's local, so date and time are always in your local time zone. Since the java.util.Date has been widely used everywhere in many Java applications, you will often find yourself converting java.util.Date to LocalDate, LocalTime and LocalDateTime classes of the java.time package. Earlier I have shown you how to convert Date to LocalDate and today, I am going to teach you how to convert Date to LocalDateTime in Java 8. The approach is the same. Since the equivalent class of java.util.Date in new Date and Time API is java.time.Instant, we first convert Date to Instance and then create LocalDateTime instance from that Instant using System's default timezone.

Top 5 Free PHP and MySQL Online Courses to Learn Web Development

If you want to build web applications in quick time then PHP and MySQL is a good choice. PHP and MySQL are incredibly powerful open source technologies that allow programmers and web developers to create functional websites and apps that go way beyond basic HTML. PHP is specially created to generate interactive and dynamic websites and also known as server-side scripting language while MySQL is one of the leading relational databases along with Oracle and Microsoft SQL server. While it may seem intimidating to create a website using PHP and MySQL, especially for someone who has no experience in coding, it's not that difficult. With the right guidance and resources e.g. books and courses you can put together a PHP MySQL website in a week or so.

10 Examples of Stream in Java 8 - count + filter + map + distinct + collect

The Java 8 release of Java Programming language was a game changer version. It not only provided some useful method but totally changed the way you write programs in Java. The most important change it brings in the mindset of Java developers was to think functional and supported that by providing key features like lambda expression and Stream API, which takes advantage of parallel processing and functional operations like filter, map, flatMap etc. Since then a lot of Java developers are trying their hands to learn those major changes like lambda expression, method reference, new Date and Time classes, and more importantly, Stream API for bulk data operations.

Top 5 Free Selenium Web Driver Courses to Learn Automation Testing in Java

Testing is an integral part of software development and we have long been relied on manual testing by testers and QA professional to ship quality software and find bugs, but that's not sustainable anymore. There is an increased focus on automation testing nowadays and Selenium is leading the way with its web drivers. If you don't know what is selenium, it's a free automation testing tool for web applications. It can work with different web browsers like Chrome, Firefox, Internet Explorer, Opera and simulate human-like behavior. By using Selenium you can programmatically interact with all the different elements in a webpage. You can click on them, input text, extract text and so much more.

How to Convert a List or Set of String to Comma Separated String (CSV) in Java 8

Before Java 8, it was not straightforward to convert a list of String to a comma separated String. You have to loop through the collection or list and join them manually using String concatenation, which can take up more than 4 lines of code. Of course, you could encapsulate that into your own utility method and you should but JDK didn't provide anything useful for such a common operation. Btw, things have changed. From Java 8 onwards you can do this easily. JDK 8 has provided a utility class called StringJoiner as well as added a join() method into String class to convert a List, Set, Collection or even array of String objects to a comma separated String in Java.

Top 5 Free TypeScript Courses for Angular Developers to Learn Online - Best of Lot

If you are interested in learning TypeScript or Angular, one of the popular JavaScript framework for developing front-end, which uses TypeScript and looking for some resources e.g. 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 which augments JavaScript's programming syntax by adding some new features which help in object-oriented application development, particularly introduction of Types.

Java 8 Comparator Example Using Lambda Expressions

Hello guys, After Java 8 it has become a lot easier to work with Comparator and Comparable classes in Java. You can implement Comparator using lambda expression because it is a SAM type interface. It has just one abstract method compare() which means you can pass a lambda expression where a Comparator is expected. Many Java programmer often ask me, what is the best way to learn lambda expression of Java 8?  And, my answer is, of course by using it on your day to day programming task. Since implementing equals(), hashcode(), compareTo(), and compare() methods are some of the most common tasks of a Java developer, it makes sense to learn how to use the lambda expression to implement Comparable and Comparator in Java.

How to use Multiple Threads in Java - Example

Hello guys, Multithreading is one of the biggest strength of Java, which allows you to divide a task and execute faster by using more than one threads. In order to use multiple threads in Java, you need to first define the task which will be executed by those threads. In order to create those task, you can either use Runnable or Callable interface. If you are just learning Java chose the Runnable interface, it's simpler one, but if you are familiar with Java multithreading and want to leverage additional features offered by Callable like it can throw an exception and it can also return value, then go ahead and use the Callable interface. Once you have task ready, you need to create an instance of the Thread class.

6 Websites to Learn JavaScript Online - Best of Lot

We live in the world of internet which is full of resource. You can learn whatever you want and that too without spending too much money. If you want to learn JavaScript there are plenty of websites where you can learn JavaScript online for FREE. You don't need to pay any fees, but you must have a good internet connection to take full advantage of these online resources. Out of so many websites which offer free tutorials, articles, blog post, videos, and podcasts, I have chosen these six websites to recommend to anybody who wants to learn JavaScript.

Difference between Heap and Stack Memory in Java JVM

One of the many traits of a good programmer is how well he understands the fundamental and if you want to check the fundamentals of Java programmer than asking the difference between heap and stack memory is a good choice. Even though both are part of JVM and both consumers memory allocated to the Java process, there are many differences between them e.g. 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 size of heap space is much bigger than the small size of Stack in Java. Even if you know this much information about heap and stack in Java, you are one of the better candidates, but let's see some more details to impress the interviewer.