Found 9150 Articles for Object Oriented Programming

What is AbstractList Class in Java?

Nancy Den
Updated on 30-Jul-2019 22:30:25

741 Views

The AbstractList class provides an implementation of the List interface.For an unmodifiable listProgrammer needs to extend this class and provide implementations for the get(int) and size() methods.For a modifiable listProgrammer must override the set(int, E) method. If the list is variable-size the programmer must override the add(int, E) and remove(int) methods.The following is the syntax:public abstract class AbstractList extends AbstractCollection implements ListTo work with the AbstractList class, import the following package:import java.util.AbstractList;The following is an example to implement AbstractList class:Example Live Demoimport java.util.LinkedList; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList myList ... Read More

The removeAll() method of AbstractSequentialList in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

94 Views

The removeAll() is a method inherited from AbstractCollection class. It removes all the elements of this collection that are also contained in the specified collection.The syntax is as follows:public boolean removeAll(Collection c)Here, the parameter c is the collection having elements to be removed from this collection.To work with the AbstractSequentialList class in Java, you need to import the following package:import java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList removeAll() method in Java:Example Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo {      public static void main(String[] args) {       AbstractSequentialList absSequential = new LinkedList();       absSequential.add(210); ... Read More

The containsAll() method of AbstractSequentialList in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

115 Views

The containsAll() method of the AbstractSequentialList checks for all the elements in this collection. It returns TRUE if all this collection contains all the elements in the specified collection i.e. if the two collections are same.The syntax is as follows:public boolean containsAll(Collection c)Here, c is the collection to be checkedTo work with the AbstractSequentialList class in Java, you need to import the following package:import java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList containsAll() method in Java:Example Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo {    public static void main(String[] args) {       AbstractSequentialList absSequential = new LinkedList();   ... Read More

The toArray(T[]) method of AbstractSequentialList in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

188 Views

The difference between toArray() and toArray(T[] arr) is that both the methods returns an array containing all of the elements in this collection, but the latter has some additional features i.e. the runtime type of the returned array is that of the specified array.The syntax is as follows:public T[] toArray(T[] arr)Here, arr is the array into which the elements of this collection are to be stored, To work with the AbstractSequentialList class in Java, you need to import the following package:import java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList toArray() method in Java:Example Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class ... Read More

How to set auto-increment to an existing column in a table using JDBC API?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

639 Views

You can add/set an auto increment constraint to a column in a table using the ALTER TABLE command.SyntaxALTER TABLE table_name ADD id INT PRIMARY KEY AUTO_INCREMENTAssume we have a table named Dispatches in the database with 7 columns namely id, CustomerName, DispatchDate, DeliveryTime, Price and, Location with description as shown below:+--------------+--------------+------+-----+---------+-------+ | Field        | Type         | Null | Key | Default | Extra | +--------------+--------------+------+-----+---------+-------+ | ProductName  | varchar(255) | YES  | UNI | NULL    | | | CustomerName | varchar(255) | YES  |     ... Read More

How to drop constraint on a column of a table in a database using JDBC API?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

347 Views

You can drop a constraint on a column of a table using the ALTER TABLE command.SyntaxALTER TABLE table_name DROP CONSTRAINT MyUniqueConstraint;Assume we have a table named Dispatches in the database with 7 columns namely id, CustomerName, DispatchDate, DeliveryTime, Price and, Location with description as shown below:+--------------+--------------+------+-----+---------+-------+ | Field        | Type         | Null | Key | Default | Extra | +--------------+--------------+------+-----+---------+-------+ | ProductName  | varchar(255) | YES  | UNI | NULL    | | | CustomerName | varchar(255) | YES  |     | NULL    | ... Read More

How to add a NOT NULL constraint to a column of a table in a database using JDBC API?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

411 Views

You can add a not null constraint to a column of a table using the ALTER TABLE command.SyntaxALTER TABLE table_name MODIFY column_name datatype NOT NULL;Assume we have a table named Dispatches in the database with 7 columns namely id, CustomerName, DispatchDate, DeliveryTime, Price and, Location with description as shown below:+--------------+--------------+------+-----+---------+-------+ | Field        | Type         | Null | Key | Default | Extra | +--------------+--------------+------+-----+---------+-------+ | ProductName  | varchar(255) | YES  |     | NULL    |       | | CustomerName | varchar(255) | YES  |     | NULL   ... Read More

How add a unique key constraint to a column of a table in a database using JDBC API?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

616 Views

You can add a unique constraint to a column using the ALTER TABLE commandSyntaxALTER TABLE table_name ADD CONSTRAINT MyUniqueConstraint UNIQUE(column1, column2...);Assume we have a table named Dispatches in the database with 7 columns namely id, CustomerName, DispatchDate, DeliveryTime, Price and, Location with description as shown below:+--------------+--------------+------+-----+---------+-------+ | Field        | Type         | Null | Key | Default | Extra | +--------------+--------------+------+-----+---------+-------+ | ProductName  | varchar(255) | YES  |     | NULL    | | | CustomerName | varchar(255) | No   |     | NULL ... Read More

How to add a primary key constraint to a column of a table in a database using JDBC API?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

741 Views

You can add a primary key constraint to a column of a table using the ALTER TABLE command.SyntaxALTER TABLE table_name ADD CONSTRAINT MyPrimaryKey PRIMARY KEY (column1, column2...);Assume we have a table named Dispatches in the database with 7 columns namely id, CustomerName, DispatchDate, DeliveryTime, Price and, Location with description as shown below:+--------------+--------------+------+-----+---------+-------+ | Field        | Type         | Null | Key | Default | Extra | +--------------+--------------+------+-----+---------+-------+ | ProductName  | varchar(255) | YES  |     | NULL | | | CustomerName | varchar(255) | ... Read More

How to delete a column from an existing table in a database using JDBC API?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

787 Views

You can delete a column in a table using the ALTER TABLE command.SyntaxALTER TABLE table_name DROP COLUMN column_name;Assume we have a table named Sales in the database with 7 columns namely id, CustomerName, DispatchDate, DeliveryTime, Price and, Location as shown below:+----+-------------+--------------+--------------+--------------+-------+----------------+ | id | productname | CustomerName | DispatchDate | DeliveryTime | Price | Location     | +----+-------------+--------------+--------------+--------------+-------+----------------+ | 1  | Key-Board   | Raja         | 2019-09-01   | 08:51:36     | 7000  | Hyderabad      | | 2  | Earphones   | Roja         | 2019-05-01   ... Read More

Advertisements