0% found this document useful (0 votes)
35 views

Dictionary Properties Concurrent Classes in Java

The document discusses dictionaries, properties, and concurrent collections in Java. It defines dictionaries as an abstract class that represents key-value pairs like maps. Properties are subclasses of hashtable that store data in key-value pairs as strings in properties files. Concurrent collections were introduced in Java 5 to provide thread-safe collection classes for multithreaded applications, since traditional collections are not synchronized.

Uploaded by

jhadhruv09
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Dictionary Properties Concurrent Classes in Java

The document discusses dictionaries, properties, and concurrent collections in Java. It defines dictionaries as an abstract class that represents key-value pairs like maps. Properties are subclasses of hashtable that store data in key-value pairs as strings in properties files. Concurrent collections were introduced in Java 5 to provide thread-safe collection classes for multithreaded applications, since traditional collections are not synchronized.

Uploaded by

jhadhruv09
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Smart Programming : Channel

An investment in Knowledge pays the best interest….

Dictionary, Properties &


Concurrent Classes in Java
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

=> Dictionary :-
 Dictionary is an abstract class which is present
in java.util package
 Dictionary represents the key-value pair similar
to Map interface
 Syntax : public abstract class Dictionary { - }
 As Dictionary is an abstract class, thus we
cannot create an object of it

 Methods :-
1. abstract public int size();
2. abstract public boolean isEmpty();
3. abstract public Enumeration keys();
4. abstract public Enumeration elements();
5. abstract public Object get(Object key);
6. abstract public Object put(Object key, Object
value);
7. abstract public Object remove(Object key);

1
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

 Dictionary was introduced in JDK 1.0 version


 Since java does not support multiple
inheritance, if any class extends the Dictionary
class, then it will not be able to inherit any other
class and due to this reason, Map interface was
created.
 Dictionary class is not used that much as Map
interface.

=> Properties :-
 Properties is the child class of Hashtable which
is present in java.util package
 Syntax : public class Properties extends
Hashtable { - }
 Properties is the file which stores the data in
key-value pair
 Properties can contain "key-value pair in the
form of String type only"
2
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

 When we should use Properties :-


o Whenever there is any data which can
change frequently in future then we should
not embed that data in our java application.
Instead of that we have to create properties
file and provide the data in key-value pair so
that we dont need to recompile, rebuild,
redeploye and even no need to restart the
server
o For example validations, database
connection, exception handling etc

 Constructors :-
1. public Properties() { - }
2. public Properties(Properties defaults) { - }

 Methods :-
1. void load(InputStream is)
2. String getProperty(String pname)
3. String setProperty(String pname, pvalue);
4. void store(OutputStream os, String comments)
3
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

=> Concurrent Collections :-

 Why Concurrent Collections were introduced :-


o Most of the classes that we have used till
now (traditional collections) are non-
synchronized for example ArrayList,
LinkedList, HashSet, HashMap etc
o If any class is non-synchronized then it does
not guarantee for data consistency which
can ruin our application
o Some of the synchronized collection like
Vector or Stack have low performace
o In traditional collections, if a thread is
iterating a Collection object and if another
thread try to add new element in that
iterating object, then it will provide an
exception saying
"ConcurrentModificationException"

4
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

 Due to above problems, traditional Collections


were not good for multithreaded applications
and due to this, concurrent collections were
introduced

 The concurrent Collections were introduced in


JDK 1.5 version
 These Concurrent Collection classes are
present in java.util.concurrent package

 Hierarchy of Concurrent Collection :-

5
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

6
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

Company Links & Contacts

Company Name: Smart Programming (+91 62838-30308)

Address : Chandigarh & Mohali (Punjab), India

Websites: https://www.smartprogramming.in/
https://courses.smartprogramming.in

Android App:
https://play.google.com/store/apps/details?id=com.sma
rtprogramming

YouTube Channel:
https://www.youtube.com/c/SmartProgramming

You might also like