Found 2616 Articles for Java

Difference between Object level lock and Class level lock in Java

Himanshu shriv
Updated on 21-Jan-2020 10:10:57

6K+ Views

In multithreading environment, two or more threads can access the shared resources simultaneously which can lead the inconsistent behavior of the system. Java uses concept of locks to restrict concurrent access of shared resources or objects. Locks can be applied at two levels −Object Level Locks − It can be used when you want non-static method or non-static block of the code should be accessed by only one thread.Class Level locks − It can be used when we want to prevent multiple threads to enter the synchronized block in any of all available instances on runtime. It should always be used ... Read More

Difference between Static binding and dynamic binding in Java

Himanshu shriv
Updated on 21-Jan-2020 10:07:31

13K+ Views

Binding is a mechanism creating link between method call and method actual implementation. As per the polymorphism concept in Java , object can have many different forms. Object forms can be resolved at compile time and run time. If linking between method call  and method implementation is resolved at compile time then we call it static binding or  If it is resolved at run time then it dynamic binding. Dynamic binding uses object to resolve binding but static binding use type of the class and fields. Sr. No.KeyStatic BindingDynamic Binding1Basic It is resolved at compile time It is resolved at run time 2    ... Read More

Difference between HashTable and ConcurrentHashMap in Java

Himanshu shriv
Updated on 29-Jul-2021 14:33:14

7K+ Views

Concurrent Hashmap is a class that was introduced in jdk1.5.  Concurrent hash map applies locks only at bucket level called fragment while adding or updating the map. So, a concurrent hash map allows concurrent read and write operations to the map. HashTable is a thread-safe legacy class introduced in the Jdk1.1. It is a base implementation of Map interface. It doesn't allow null keys and values. It is synchronized in nature so two different threads can’t access simultaneously. Hashtable does not maintain any order.Sr. No.KeyHashTableConcurrentHashMap1Basic HashTable is a thread-safe legacy class introduced in the Jdk1.1 ConcurrentHashmap is a class that was introduced in ... Read More

Difference between EnumMap and HashMap in Java

Himanshu shriv
Updated on 21-Jan-2020 07:59:49

641 Views

EnumMap is introduced in JDK5. It is designed to use Enum as key in the Map. It is also the implementation of the Map interface. All of the key in the EnumMap should be of the same enum type. In EnumMap , key can’t be null and any it will throw NullPointerException.As per java docs − EnumMap internally using as arrays, this representation is extremely compact and efficient.HashMap is also the implementation of the Map interface. It is used to store the data in Key and Value form. It can contain one null key and multiple null values . In HashMap, ... Read More

Difference between Collection.stream().forEach() and Collection.forEach() in Java

Himanshu shriv
Updated on 21-Jan-2020 08:02:10

698 Views

Collection.stream().forEach() and Collection.forEach() both are used to iterate over collection. Collection.forEach()  uses the collection’s iterator. Most of the collections doesn’t allow the structurally modification while iterating over them. If any element add or remove while iteration they will immediately throw concurrent modification exception. If Collection.forEach() is iterating over the synchronized collection then they will lock the segment of the collection and hold it across all the calls. Collection.stream().forEach() is also used for iterating the collection but it first convert the collection to the stream and then iterate over the stream of the collection therefore the processing order is undefined. It also throws ... Read More

How To Install Apache Maven on Ubuntu

Sharon Christine
Updated on 01-Mar-2024 13:56:26

191 Views

Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information. This article explains about how to install apache maven on Ubuntu.To install apache maven, it should require pre-installed java on Ubuntu. To verify java version, use the following command –$ java -versionThe sample output should be like this –openjdk version "1.8.0_111" OpenJDK Runtime Environment (build 1.8.0_111-8u111-b14-2ubuntu0.16.04.2-b14) OpenJDK 64-Bit Server VM (build 25.111-b14, mixed mode)If you wants to install java on Ubuntu, read this articleTo install ... Read More

XDM – The Download Manager for Linux that ramps up Your Speed to 500%

karthikeya Boyini
Updated on 17-Jan-2020 13:01:06

172 Views

Xtreme download supervisor (xdman) is an effective download supervisor for Linux, which is developed in Java programing language. It can increase download speeds of upto 500% and is an alternative for the windows IDM (Internet Download Manager). It is compatible with many popular internet browsers such as Firefox, Chrome, Opera.Before installing Xtreme Download supervisor, Check if Java is installed or not available by typing java -version in command line.$ java -versionThe sample output should be like this –openjdk version "1.8.0_91" OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~16.04.1-b14) OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)Installing Xtreme Download Manager in LinuxTo put the ... Read More

Print all permutation of a string using ArrayList in Java

sudhir sharma
Updated on 14-Jul-2020 07:27:07

589 Views

In this problem, we are given a string of size n and we have to print all permutations of the string. But this time we have to print this permutation using ArrayList.Let’s take an example to understand the problem -Input − string = ‘XYZ’Output − XYZ, XZY, YXZ, YZX, ZXY, ZYXTo solve this problem, we will be generating all permutations of the character of the string. We will use a recursive function and will return arrayList.ExampleThe following is ArrayList implementation of the algorithm − Live Demoimport java.util.ArrayList; public class Main{    static void printArrayList(ArrayList combo) {       combo.remove("");   ... Read More

Character class: union - Java regular expressions

Maruthi Krishna
Updated on 13-Jan-2020 06:52:15

462 Views

The character classes in Java regular expression is defined using the square brackets "[ ]", this subexpression matches a single character from the specified or, set of possible characters. For example the regular expression [abc] matches a single character a or, b or, c.The union variant of the character class allows you to match a character from one of the specified ranges i.e. the expression [a-z[0-9]] matches a single character which is either a small alphabet (a-z) or a digit (0-9).Example Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample1 {    public static void main(String[] args) {     ... Read More

Character class: range - Java regular expressions

Maruthi Krishna
Updated on 13-Jan-2020 06:49:55

93 Views

The character classes in Java regular expression is defined using the square brackets "[ ]", this subexpression matches a single character from the specified or, set of possible characters. For example, the regular expression [abc] matches a single character a or, b or, c.The range variant of the character class allows you to use a range of characters i.e the expression [a-z] matches a single character from the alphabets a to z and the expression [^A-Z] matches a character which is not a capital letter.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample1 {    public static void ... Read More

Advertisements