Hello World Java Swing example

In This post we will show you and example of Hello World using Java Swing . We will configures a JFrame and attach a JLabel to display a “hello world” centered in the JLabel component. The output : Also read : Java Basics

En Lire Plus

Convert Instant to ZonedDateTime in JAVA

In this tutorial , we will show a Java 8 example of how to convert from Instant to ZonedDateTime So the output will be : If we need to convert from ZonedDateTime to Instant The output will be : Also read : How to convert String to Date in Java ? References : JavaDoc mkYong

En Lire Plus

(SOLVED) convert String to Date in Java ?

In this tutorial, we will show you how to convert a String to java.util.Date. Many Java beginners Always find this problem of Date conversion. so we decided to post this solution !! let understand how to convert String Date in JAVA. java.text.SimpleDateFormat provide many date and time patterns : Letter Description Examples y Year 2013 […]

En Lire Plus

(SOLVED) How to get file extension in Java ?

In this tutorial , we will see how we can get the extension of file in Java. In the next example , we will use lastIndexOf to get the file extension of a file. The above process, will fail if the directory name or file path includes a dot or double dots AND the file […]

En Lire Plus

(SOLVED) how to Convert File to Path in Java ?

In this tutorial , we will see how we can convert file to path using Java ? The java.nio.file package includes Java virtual machine interfaces and classes for accessing files, file attributes, and file systems. Convert File to Path If we want to convert from java.io.File to java.nio.file.Path we can use toPath() Convert Path to […]

En Lire Plus

JAVA Map , HashMap , LinkedHashMap, TreeMap

Java Map : There are no duplicate values allowed in the map. A map object’s keys must be unique. HashMap, TreeMap, and LinkedHashMap are three groups that implement the Map interface in the Java collection system. SortedMap is a special interface for keeping all of the elements sorted. HashMap vs LinkedHashMap The ordering of the […]

En Lire Plus

Different ways iterate a list in Java

Iterate a list in Java : in this Post we will discover different ways to browse a list in Java. (ArrayList) List.toString() If we want to iterate over a list in java , we can do that by converting the list to a string using the toString() function, then outputting it Output : Using For […]

En Lire Plus

Difference between ArrayList and LinkedList in Java

ArrayList vs LinkedList : Both ArrayList and LinkedList implement the List interface, but what’s the difference then ? The main difference between ArrayList and LinkedList is in ArrayList which is implemented using an extensible array. As more items are added to ArrayList, its size dynamically increases. Its elements can be accessed directly using the get() […]

En Lire Plus

Comparator example Java 8 Lambda expression

We’ll show you how to write a Comparator to sort a List using Java 8 Lambda expressions in this example. Classic Comparator example Lambda expression equivalent. Sort without Lambda A comparison of Developer objects based on their age is an example. Normally, you use Collections.sort and pass an anonymous Comparator class like this : Output […]

En Lire Plus

(SOLVED) Minimum number of increment

Minimum number of increment, We’ve been given an array of n components. You can choose any one element and increase the rest of the n-1 elements by one at each operation. You must make all elements equal and replicate the process as many times as you like. Determine the smallest number of operations required. Examples: […]

En Lire Plus

forEach Java 8 Examples

To loop or iterate a Map, List, Set, or Stream in Java 8, we can use the new forEach method. Loop a Map 1,1 A standard method for looping a Map is shown below. 1.2 We can use forEach in Java 8 to loop through a Map and print out its entries. Output 1.3 The […]

En Lire Plus

Consumer Java 8 Examples, how to use ?

In Java 8, Consumer is a functional interface, it takes an argument and returns nothing. An interface with just one abstract method is referred to as a functional interface. They are limited to displaying only one type of feature. Lambda expressions can be used to describe a functional interface instance starting with Java 8. Some examples of […]

En Lire Plus

Tips to Learn Programming Faster

Tips to Learn Programming Faster The most frequently asked questions today are, “How long does it take to learn Java?” “How can I learn to code quickly and kick-off my career as a software developer?” Not only the freshmen but also a majority of coding auto-didacts are also in search of a quick and straightforward […]

En Lire Plus

JAVA : example of Arrays.sort()

Arrays.sort(): The class java.util.Arrays have many methods, one of these methods is the sort(), this method doesn’t return any value ! Syntax : In the next example we will show you how to sort an array of integers in ascending order ? Output : read also : How to find duplicate elements in a Stream […]

En Lire Plus

Multithreading in Java

Multithreading is a Java mechanism that allows concurrent execution of many block of a program for maximum utilization of CPU. Each block is called a thread. So, threads are light-weight processes within a process. To create Threads we have two ways:1. Extending the Thread class2. Implementing the Runnable Interface Example of extending the Thread class […]

En Lire Plus

Thread Class vs Runnable Interface in JAVA

Thread Class vs Runnable Interface ? To create a Thread we can extends Thread Class or we can implements Runnable Interface , so what is the difference between the two ways ? Answer 1. When we extend the Thread class, we cannot extend any other class because Java doesn’t support multiple inheritance. But, for the […]

En Lire Plus

How to use Synchronized in Java ? (Example)

Synchronized in Java : To make sure that only one Thread can access to the resource at a given point of time, we use Synchronized !! In many time, Multi-threaded programs provide a situation where multiple threads try to access the same resources and finally produce erroneous result ! To solve this problem , Java provides […]

En Lire Plus

(SOLVED) How to find duplicate elements in a Stream (Java 8) ?

In Java 8 Stream, filter with Set.Add() is the fastest algorithm to find duplicate elements, because it loops only one time. The Collections.frequency is the slowest because it compares each item with a list – Collections.frequency(list, i). If we increase the size of the list, the performance will get slower.

En Lire Plus

(SOLVED) regex match for alphanumeric string

If you need to check whether a password is alphanumeric or not using regex try this Java Solution : what is the difference between login.getPassword().matches(“[0-9a-zA-Z]*”); and login.getPassword().matches(“[0-9a-zA-Z]”); ? Answer : The .matches(“[0-9a-zA-Z]”) will only return true if the whole string contains just 1 digit or letter. The * in [0-9a-zA-Z]* will allow an empty string, […]

En Lire Plus

Les Bases du langage JAVA [FR]

Introduction Au début des années 90, Sun travaillait sur un projet visant à concevoir des logiciels simples et performants exécutés dans des PDA (Personnal Digital Assistant). Le langage C++ a été retenu pour la programmation de ces logiciels, mais le langage C s’est avéré peu performant , notamment en ce qui concerne la sécurité et […]

En Lire Plus