Found 7442 Articles for Java

CopyOnWriteArraySet Class in Java

Samual Sam
Updated on 19-Jun-2020 14:45:11

693 Views

Class declarationpublic class CopyOnWriteArraySet    extends AbstractSet implements SerializableCopyOnWriteArraySet class uses CopyOnWriteArrayList internally for all of its operations and thus possesses the basic properties of CopyOnWriteArrayList.CopyOnWriteArraySet is a thread-safe.CopyOnWriteArraySet is to be used in Thread based environment where read operations are very frequent and update operations are rare.Iterator of CopyOnWriteArraySet will never throw ConcurrentModificationException.Any type of modification to CopyOnWriteArraySet will not reflect during iteration since the iterator was created.Set modification methods like remove, set and add are not supported in the iteration. This method will throw UnsupportedOperationException.CopyOnWriteArraySet MethodsFollowing is the list of important methods available in the CopyOnWriteArraySet class.Sr.No.Method & ... Read More

CopyOnWriteArraySet Class in Java

Samual Sam
Updated on 19-Jun-2020 14:45:11

693 Views

Class declarationpublic class CopyOnWriteArraySet    extends AbstractSet implements SerializableCopyOnWriteArraySet class uses CopyOnWriteArrayList internally for all of its operations and thus possesses the basic properties of CopyOnWriteArrayList.CopyOnWriteArraySet is a thread-safe.CopyOnWriteArraySet is to be used in Thread based environment where read operations are very frequent and update operations are rare.Iterator of CopyOnWriteArraySet will never throw ConcurrentModificationException.Any type of modification to CopyOnWriteArraySet will not reflect during iteration since the iterator was created.Set modification methods like remove, set and add are not supported in the iteration. This method will throw UnsupportedOperationException.CopyOnWriteArraySet MethodsFollowing is the list of important methods available in the CopyOnWriteArraySet class.Sr.No.Method & ... Read More

Counting number of characters in text file using java

karthikeya Boyini
Updated on 19-Jun-2020 13:10:12

6K+ Views

We can read characters in a file using BufferedReader class of Java. See the example below −ExampleConsider the following text file in the classpath.test.txtThis is Line 1 This is Line 2 This is Line 3 This is Line 4 This is Line 5 This is Line 6 This is Line 7 This is Line 8 This is Line 9 This is Line 10Tester.javaimport java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; public class Tester {    private static final String FILE_PATH = "data.txt";    public static void main(String args[]) throws IOException {       ... Read More

Counting number of characters in text file using java

karthikeya Boyini
Updated on 19-Jun-2020 13:10:12

6K+ Views

We can read characters in a file using BufferedReader class of Java. See the example below −ExampleConsider the following text file in the classpath.test.txtThis is Line 1 This is Line 2 This is Line 3 This is Line 4 This is Line 5 This is Line 6 This is Line 7 This is Line 8 This is Line 9 This is Line 10Tester.javaimport java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; public class Tester {    private static final String FILE_PATH = "data.txt";    public static void main(String args[]) throws IOException {       ... Read More

Counting number of paragraphs in text file using java

karthikeya Boyini
Updated on 19-Jun-2020 13:13:30

648 Views

We can read paragraphs in a file by reading it in a string and then spilting based on "\r" pattern. See the example below −ExampleConsider the following text file in the classpath.test.txtThis is Line 1 This is Line 2 This is Line 3 This is Line 4 This is Line 5 This is Line 6 This is Line 7 This is Line 8 This is Line 9 This is Line 10Tester.javaimport java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Tester {    public static void main(String args[]) throws IOException {       FileUtil fileUtil = ... Read More

Counting number of paragraphs in text file using java

karthikeya Boyini
Updated on 19-Jun-2020 13:13:30

648 Views

We can read paragraphs in a file by reading it in a string and then spilting based on "\r" pattern. See the example below −ExampleConsider the following text file in the classpath.test.txtThis is Line 1 This is Line 2 This is Line 3 This is Line 4 This is Line 5 This is Line 6 This is Line 7 This is Line 8 This is Line 9 This is Line 10Tester.javaimport java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Tester {    public static void main(String args[]) throws IOException {       FileUtil fileUtil = ... Read More

CountDownLatch in Java

Janani Jaganathan
Updated on 13-Oct-2022 11:25:00

4K+ Views

For a concurrent execution, CountDownLatch in Java is an important class that ensures one or more threads are in the queue for other threads to complete their set of operations. To better understand CountDownLatch in Java, in this article, you will learn the working of CountDownLatch with an example and methods of CountDownLatch. CountDownLatch in Java and its Working Process Based on the count value, the CountDownLatch is used for several purposes, which are as follows − When we begin the CountDownlatch with count value 1, it will simply work as an on/off latch or gate. On the other ... Read More

Coupling in Java

karthikeya Boyini
Updated on 19-Jun-2020 13:22:22

5K+ Views

Coupling refers to the usage of an object by another object. It can also be termed as collaboration. This dependency of one object on another object to get some task done can be classified into the following two types −Tight coupling - When an object creates the object to be used, then it is a tight coupling situation. As the main object creates the object itself, this object can not be changed from outside world easily marked it as tightly coupled objects.Loose coupling - When an object gets the object to be used from the outside, then it is a loose coupling ... Read More

Coupling in Java

karthikeya Boyini
Updated on 19-Jun-2020 13:22:22

5K+ Views

Coupling refers to the usage of an object by another object. It can also be termed as collaboration. This dependency of one object on another object to get some task done can be classified into the following two types −Tight coupling - When an object creates the object to be used, then it is a tight coupling situation. As the main object creates the object itself, this object can not be changed from outside world easily marked it as tightly coupled objects.Loose coupling - When an object gets the object to be used from the outside, then it is a loose coupling ... Read More

Database operations in Java

karthikeya Boyini
Updated on 19-Jun-2020 13:27:08

2K+ Views

This article provides an example of how to create a simple JDBC application. This will show you how to open a database connection, execute a SQL query, and display the results.Creating JDBC ApplicationThere are following six steps involved in building a JDBC application −Import the packages: Requires that you include the packages containing the JDBC classes needed for database programming. Most often, using import java.sql.* will suffice.Register the JDBC driver: Requires that you initialize a driver so you can open a communication channel with the database.Open a connection: Requires using the DriverManager.getConnection() method to create a Connection object, which represents ... Read More

Advertisements