Java Articles - Page 376 of 540

LinkedBlockingQueue Class in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

200 Views

The LinkedBlockingQueue Class in Java has a blocking queue that is optionally bounded and based on linked nodes. This means that if the capacity is provided then the LinkedBlockingQueue is bound, otherwise it is not bound. Also, FIFO for ordering elements.A program that demonstrates this is given as follows −Example Live Demoimport java.util.concurrent.LinkedBlockingQueue; public class Demo {    public static void main(String[] args) {       LinkedBlockingQueue lbQueue = new LinkedBlockingQueue();       lbQueue.add("Amy");       lbQueue.add("John");       lbQueue.add("May");       lbQueue.add("Harry");       lbQueue.add("Anne");       System.out.println("The elements in LinkedBlockingQueue are: " ... Read More

ConcurrentLinkedQueue in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

209 Views

The ConcurrentLinkedQueue class in Java is used to implement a queue using a concurrent linked list. This class implements the Collection interface as well as the AbstractCollection class. It is a part of the Java Collection Framework.A program that demonstrates this is given as follows −Example Live Demoimport java.util.concurrent.*; public class Demo {    public static void main(String[] args) {       ConcurrentLinkedQueue clQueue = new ConcurrentLinkedQueue();       clQueue.add("Amy");       clQueue.add("John");       clQueue.add("May");       clQueue.add("Harry");       clQueue.add("Anne");       System.out.println("The elements in ConcurrentLinkedQueue are: " + clQueue);    } ... Read More

ArrayBlockingQueue Class in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

212 Views

A bounded blocking queue that is backed by an array is known as a ArrayBlockingQueue Class in Java. The size of the queue is fixed in the class and it uses FIFO for ordering elements. The ArrayBlockingQueue Class is a member of the Java Collections Framework.A program that demonstrates this is given as follows −Example Live Demoimport java.util.concurrent.ArrayBlockingQueue; public class Demo {    public static void main(String[] args) {       int n = 10;       ArrayBlockingQueue abQueue = new ArrayBlockingQueue(n);       abQueue.add(7);       abQueue.add(2);       abQueue.add(6);       abQueue.add(3);   ... Read More

Difference between Synchronized ArrayList and CopyOnWriteArrayList in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

2K+ Views

Synchronized ArrayList and CopyOnWriteArrayList are useful for synchronizing the ArrayList. This is necessary for a multi-threaded environment to make sure thread safety is achieved.The differences between Synchronized ArrayList and CopyOnWriteArrayList are given as follows −Synchronized ArrayListCopyOnWriteArrayListSynchronized ArrayList is used to synchronize the ArrayList.CopyOnWriteArrayList is used to synchronize the ArrayList.The Java 1.2 version first introduced the Synchronized ArrayList.The Java 1.5 version first introduced the CopyOnWriteArrayList.The Synchronized ArrayList should be used when there are more write operations than reading operations in ArrayList.The CopyOnWriteArrayList should be used when there are more read operations than write operations in ArrayList.This iterator is a fail-fast iterator.This ... Read More

Custom ArrayList in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

1K+ Views

A custom ArrayList can have multiple types of data and its attributes in general are based on the user requirements.A program that demonstrates a custom ArrayList is given as follows −Example Live Demoimport java.util.ArrayList; public class CustomArrayList {    int n = 5;    class Employee {       int eno;       String name;       Employee(int eno, String name) {          this.eno = eno;          this.name = name;       }    }    public static void main(String args[]) {       int eno[] = {101, 102, 103, ... Read More

AbstractSequentialList in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

181 Views

The Java Collection Framework contains the AbstractSequentialList class. This class is used to create and implement an unmodifiable list. Also this class implements the Collection interface and the AbstractCollection class.A program that demonstrates this is given as follows −Example Live Demoimport java.util.*; public class Demo {    public static void main(String[] args) {       AbstractSequentialList list = new LinkedList();       list.add("John");       list.add("Martha");       list.add("Sally");       list.add("Susan");       list.add("Harry");       System.out.println("The elements are: " + list);    } }The output of the above program is as follows ... Read More

Java Program to mark the current position in this input stream

Alshifa Hasnain
Updated on 30-Dec-2024 19:14:42

602 Views

In this article, we will learn to mark and reset the current position in a file input stream in Java. Marking the current position in an input stream is a crucial functionality provided by Java’s InputStream class. It enables developers to reset the stream to a previously marked position, facilitating efficient data handling, especially in scenarios like re-reading or backtracking within a file. Key Concepts Following are the key concepts we need to know to mark the current position in this input stream − InputStream Class: The InputStream class is an abstract class that represents ... Read More

Get the Current Working Directory in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

8K+ Views

The method java.lang.System.getProperty() is used to obtain the system property. This system property is specified by the key which is the parameter for the method. To obtain the current working directory, the key used is user.dir.A program that demonstrates this is given as follows −Example Live Demopublic class Demo {    public static void main(String[] argv) throws Exception {       String currentDirectory = System.getProperty("user.dir");       System.out.println("The current working directory is " + currentDirectory);    } }The output of the above program is as follows −OutputThe current working directory is c:\JavaProgramNow let us understand the above program.The current ... Read More

How to disable “Establishing SSL connection without server's identity verification is not recommended” warning when connecting to MySQL database in Java?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

13K+ Views

To disable the warning while connecting to a database in Java, use the below concept −autoReconnect=true&useSSL=falseThe complete syntax is as follows −yourJdbcURL="jdbc:mysql://localhost:yourPortNumber/yourDatabaseName?autoReconnect=true&useSSL=false";Here is the warning message if you do not include “useSSL=false” −Wed Feb 06 18:53:39 IST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore ... Read More

How to add the JDBC MySQL driver to an Eclipse project?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

12K+ Views

To add the JDBC MySQL driver to an Eclipse project, you need to follow the below steps.The first step is as follows:Step1: Create a dynamic web project with some name in Eclipse.Step2: After pressing the Dynamic Web Project, a new window will open. Now give the project name. The screenshot is as follows:After clicking the Finish button, you will get a project structure. The screenshot is as follows:Therefore, I have a project name JDBCJarFiles and in WEB-INF, there is a lib folder. You can add JDBC jar files in lib folder. Now, paste the jar files here. The screenshot is as ... Read More

Advertisements