Saturday, October 28, 2023

Java 8 Stream.filter() example Example with Null and Empty String

The filter() is a method on Stream class, which accepts a Predicate (a functional interface with a method which return boolean) and returns a stream consisting of the elements of this stream that match the given predicate. For example, if stream is obtained from a list containing "SONY", "APPLE" and "GOOGLE" and predicate is elements with length greater than 4, then filter will return another stream containing only APPLE and GOOGLE, leaving SONY out because its length is not greater than 4. Java 8 provides advanced filtering capability using lambdas and predicates. 

Tuesday, October 10, 2023

How to Create and Extract a ZIP File in Java? Unzip Example Tutorial

In Java, you can use ZipFile class to unzip a .jar and .zip file in Java. These classes are defined in and java.util.zip package. Unfortunately there is no ZipUtil class, which provides straightforward methods to decompress zip files, but thankfully there are enough tools available in JDK to write your own method to extract zip file in Java. There are mainly two steps to unzip a zip file in Java, first, create all directories inside of the zip file, because zip archive flattens all directory and second create all file which are inside .zip file. Sinze files in .zip file is not in specific order, you need to iterate twice to perform these steps individually.

Monday, October 9, 2023

How to implement Level Order Traversal of Binary Tree in Java? Example Tutorial

Hello guys, if you have worked in Java then you know that binary tree is one of the essential data structure and quite an important one for programmers, I even mentioned that on my 10 essential data structures for programmers articles.  Binary tree related question are also quite common on coding interviews and we are going to see one today but before that, let's revise what is binary tree? Binary trees are hierarchical data structures composed of nodes, each having at most two children: a left child and a right child. Traversing a binary tree in level order involves visiting nodes level by level, starting from the root. 

Saturday, October 7, 2023

Why is Java Considered a Secure Programming Language?

Hello guys, Security is a paramount concern in software development, and choosing the right programming language can play a crucial role in mitigating potential vulnerabilities and threats. Java has long been celebrated for its security features and practices, making it a preferred choice for building secure applications and systems. In this article, we'll explore why Java is considered a secure programming language and examine the features and practices that contribute to its security reputation.

Sunday, October 1, 2023

Difference between Queue and Deque in Java? Example Tutorial

Hello guys, today I am going to share another interesting question from Java interview, what is difference between Queue and Deque in Java. This question was asked to one of my reader in a recent interview with JP Morgan Mumbai and this is also a popular Java collection interview question. While he was able to answer the question, he wasn't able to convince interviewer so he asked me how to answer this question. So I am writing this post to share my answer on Queue vs Deque in Java. In the vast world of Java programming, the need to manage data efficiently often leads developers to specialized data structures.