Java Program to Implement SimpleBindings API Last Updated : 05 Aug, 2021 Comments Improve Suggest changes Like Article Like Report SimpleBindings is an implementation of bindings that are supported by HashMap or any other map which is specified by the programmer. Constructors of SimpleBindings API: SimpleBindings(): It is a default constructor that uses a HashMap to store the values.SimpleBindings(Map<String, object> m): Overloaded constructor uses an existing HashMap to store the values. Syntax: public class SimpleBindings extends Object implements Bindings Implementation of SimpleBindings API : Java // Java Program to Implement SimpleBindings API import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import javax.script.SimpleBindings; public class SimpleBindingsAPIExample { // reference of SimpleBindings class private SimpleBindings simpleBindings; // Default constructor will use a HashMap public SimpleBindingsAPIExample() { // object creating of SimpleBindings class simpleBindings = new SimpleBindings(); } // Overloaded constructor uses an existing HashMap to // store the values public SimpleBindingsAPIExample(Map<String, Object> map) { simpleBindings = new SimpleBindings(map); } // Clear all the values from the map public void clear() { simpleBindings.clear(); } // Returns true if the map contains value for the // specified key public boolean containsKey(Object key) { return simpleBindings.containsKey(key); } // Return true if the map contains values as specified public boolean containsValue(Object value) { return simpleBindings.containsValue(value); } // Returns the set of values contained in the map public Set<Map.Entry<String, Object> > entrySet() { return simpleBindings.entrySet(); } // Returns the values if specified key is exist in the // map else will return null public Object get(Object key) { return simpleBindings.get(key); } // Returns whether the map is empty or not public boolean isEmpty() { return simpleBindings.isEmpty(); } // Returns a set of the keys public Set<String> keySet() { return simpleBindings.keySet(); } // Insert the specified value associated with the // specified key public Object put(String key, Object value) { return simpleBindings.put(key, value); } // Copy all the values from another map into this map public void putAll(Map<? extends String, ? extends Object> map) { simpleBindings.putAll(map); } // Removes the value associated with the specified key public Object remove(Object key) { return simpleBindings.remove(key); } // Return the number of key-value pairs exist in the map public int size() { return simpleBindings.size(); } // Returns a collection of the values contained in map public Collection<Object> values() { return simpleBindings.values(); } } class SimpleBindingsImpl { public static void main(String[] args) { SimpleBindingsAPIExample map = new SimpleBindingsAPIExample(); map.put("1", "Ram"); map.put("2", "Shyam"); map.put("3", "Sita"); Map<String, Object> anotherMap = new HashMap<String, Object>(); anotherMap.put("4", "Geeta"); anotherMap.put("5", "Tina"); map.putAll(anotherMap); System.out.println("The key set of the map is : "); Set<String> keySet = map.keySet(); Iterator<String> itr = keySet.iterator(); while (itr.hasNext()) { System.out.print(itr.next() + "\n"); } System.out.println(); System.out.println("The values of map is : "); Collection<Object> collectionOfValues = map.values(); Iterator<Object> itrOfValues = collectionOfValues.iterator(); while (itrOfValues.hasNext()) { System.out.print(itrOfValues.next() + "\n"); } System.out.println(); System.out.println("The entry set of the map is "); Iterator<Entry<String, Object> > itrOfEntrySet; Set<Entry<String, Object> > entrySet = map.entrySet(); itrOfEntrySet = entrySet.iterator(); while (itrOfEntrySet.hasNext()) { System.out.println(itrOfEntrySet.next()); } System.out.println(); // Returns true if map contains the key 2 boolean check = map.containsKey("2"); System.out.println("The map contains key 2 ? " + check); System.out.println(); // Return true if map contains the value snigdha check = map.containsValue("Tina"); System.out.println("The map contains value Tina? " + check); System.out.println(); // Return the size of map int result = map.size(); System.out.println("The number of key-value pairs in the map are : " + result); System.out.println(); // Clear the map means delete all the key-value // pairs from the map map.clear(); // Return true if map is empty check = map.isEmpty(); System.out.println( "After clear the map, the map is empty ? " + check); System.out.println(); } } OutputThe key set of the map is : 1 2 3 4 5 The values of map is : Ram Shyam Sita Geeta Tina The entry set of the map is 1=Ram 2=Shyam 3=Sita 4=Geeta 5=Tina The map contains key 2 ? true The map contains value Tina? true The number of key-value pairs in the map are : 5 After clear the map, the map is empty ? true Comment More infoAdvertise with us Next Article Java Program to Implement SimpleBindings API snigdha_yambadwar Follow Improve Article Tags : Java Java Programs Practice Tags : Java Similar Reads How to implement a Simple DNS Resolver in Java? DNS stands for Domain Name System. For the implementation of the simple DNS resolver in Java is allowed to translate the domain names into the corresponding IP addresses in the programmatically. Domain Name System (DNS) plays a crucial component of internet communication and translates human-readabl 3 min read Java Swing | Create a simple text editor To create a simple text editor in Java Swing we will use a JTextArea, a JMenuBar and add JMenu to it and we will add JMenuItems. All the menu items will have actionListener to detect any action.There will be a menu bar and it will contain two menus and a button:Â File menuopen: this menuitem is used 6 min read Java Swing | Simple User Registration Form Swing is a part of the JFC (Java Foundation Classes). Building Graphical User Interface in Java requires the use of Swings. Swing Framework contains a large set of components which allow a high level of customization and provide rich functionalities, and is used to create window-based applications. 5 min read Java Networking Programs - Basic to Advanced Java allows developers to create applications that can communicate over networks, connecting devices and systems together. Whether you're learning about basic connections or diving into more advanced topics like client-server applications, Java provides the tools and libraries you need. This Java Ne 3 min read How to create a PApplet Project in Eclipse Processing An applet is a small program that is intended not to be run on its own, but rather to be embedded inside another application. An applet can be embedded into a web page. It runs inside the web browser and works at client side. In this article, we will discuss how to create an applet in Java in eclips 4 min read How to Copy Text to the Clipboard in Java? We will be going through some source code for a Java method that lets you copy texts to the clipboard of your operating system. Java provides a class called Clipboard, which is found in java.awt.data transfer. Clipboard provides important functionalities of the Graphical User Interface(GUI), namely 3 min read Conversion of JSON Object Array to Java POJO In this article, we will learn how to use the widely used Jackson JSON library to map an array of JSON items to a Java POJO class instance. PrerequisitesA basic understanding of Java programming.A JSON library for Java, such as Jackson, Gson, or org.json, depending on your preference.Implementation 3 min read How to Resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException? The java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException occurs in Java applications when there is a runtime condition that cannot find a class definition at runtime. The above exception refers to the class method javax.xml.bind.JAXBException does not exist in Java Architecture in the XML Bu 2 min read Jackson Annotations For Java Application Java has immense application in the coding world, and almost all of us know this fact. One of its features is the Jackson annotations. Although that is a very familiar term with the people involved in the coding world, it is less known. Jackson is a popular and very efficient JAVA library used to ma 8 min read SimpleBindings get() method in Java with Examples The get() method of SimpleBindings class is used to return the value to which this SimpleBindings object maps the key passed as parameter.if the SimpleBindings object contains no mapping for this key then method return null. Syntax: public Object get(Object key) Parameters: This method accepts only 2 min read Like