Why Core Java use?
We can see the java. util. Map interface has a technique, get:
public Object get(Object key)
Furthermore, we can see the java.util.concurrent.ConcurrentHashMap has a strategy, get:
public V getOrDefault(Object key, V defaultValue)
The getting strategy and the getOrDefault technique make something equivalent. It both returns the worth of the guide assuming that it exists, or returns the predefined default esteem on the off chance that the worth doesn't exist.
So why did Java Core designers make the point of interaction and technique having the same name, what is going on with this choice?
In the guide interface, the technique name is getting. The explanation is map is an assortment of keys and values. The strategy name gets to tell the name of a guide is "Get". If we take a gander at the getting technique in ConcurrentHashMap, the strategy name is getOrDefault. The explanation is ConcurrentHashMap is an execution of guide point of interaction and it does the two strategies in it. The strategy name is getOrDefault. Assuming that we take a gander at the getting strategy in TreeMap, the technique name is getting. This has neither rhyme nor reason. The strategy name gets to tell the guide is an assortment of keys and values. Assuming we take a gander at the getOrDefault technique in ConcurrentHashMap, the strategy name is getOrDefault.
To say that it's the equivalent thing, it's not.
In the map interface, it gets. In ConcurrentHashMap and TreeMap, it's getOrDefault. There is no get technique in ConcurrentHashMap or TreeMap.
In Java's APIs and libraries, it gets for guide, and it's got default for guide's executions. What's more, they have similar importance.
1.5.4 Collection interface
We can see the Collection interface has a technique, iterator:
public iterator()
What's more, we can see the ArrayList, LinkedList, and StackList has a strategy, iterator:
public iterator()
What's more, we can see the ConcurrentLinkedQueue has a strategy, iterator:
public iterator()
What's more, we can see the TreeSet has a strategy, iterator:
public iterator()
So why did Java Core engineers make the point of interaction and technique having the same name, what is going on with this choice?
Since Collection is an assortment of items. The strategy name is an iterator. The explanation is that all Java assortments have a strategy iterator to emphasize through each of the components in the assortment.
On the off chance that we take a gander at the Collections library, we can see there is no such strategy in it. For a superior library plan, the language planners ought to think before they plan the points of interaction and strategies.
In Java's APIs and library, it's an iterator for Collection. What's more, it's additionally iterator for Collection's executions. So it has a similar significance.
1.6 Class and Interface name
Here, I'd talk about how Java classes name plan. How about we take a gander at the point of interaction and class naming plan.
In Java Core, when we have another class, the name ought to be in CamelCase, for instance, Comparable. What's more, the name ought to have an action word name, like sort, contains, hasty.
On the off chance that you might want to look at it, we ought to analyze the point of interaction and the class name. Here is the java. util.Comparator interface:
We can see the class name is Comparator. The explanation is java. util. Comparator is a class. Furthermore, the class name ought to be Comparator because it's a class. If it's anything but a class, we ought to be java. util.Comparator. To contrast a point of interaction with a class, we ought to be Comparator, not Comparable.
So we shouldn't name a class with an action word, since it's anything but a class.
In Java's APIs and library, the names are in the camel case. For instance, Comparable. Furthermore, it has similar importance, however, it's a lot more obvious than Comparator. Furthermore, Java's APIs and library frequently utilize the action word name to name a class. For instance, HashSet and LinkedHashSet are the HashSet and linked HashSet individually.
If we have any desire to look, we ought to analyze the point of interaction and the class name. Here is the java. util.Collection interface:
We can see the class name is Collection. The explanation is java. util. The collection is a class. Furthermore, the class name ought to be Collection since it's a class. On the off chance that it's anything but a class, we ought to be java. util.Collection. To contrast a connection point with a class, we ought to be Collection, not Comparable.
So we shouldn't name a class with an action word, since it's anything but a class.
In Java's APIs and library, the names are in the camel case. For instance, List. What's more, it has similar importance, however, it's a lot more clear than Collection. Furthermore, Java's APIs and library frequently utilize the action word name to name a class. For instance, ArrayList and LinkedList are the ArrayList and LinkedList separately.
To look at this, we ought to analyze the point of interaction and the class name. Here is the java. util.List interface:
We can see the class name is List. The explanation is java. util. The list is a class. Furthermore, the class name ought to be List since it's a class. On the off chance that it's anything but a class, we ought to be java. util.List. If we have any desire to contrast a point of interaction with a class, we ought to be List, not Collection.
So we shouldn't name a class with an action word, since it's anything but a class.
In Java's APIs and libraries, the names are in the camel case. For instance, List. Furthermore, it has a similar significance, yet it's a lot more obvious than Collection. Also, Java's APIs and library frequently utilize the action word name to name a class. For instance, ArrayList and LinkedList are the ArrayList and LinkedList individually.
To think, we ought to look at the point of interaction and the class name. Here is the java. util.Collection interface:
We can see the class name is Collection. The explanation is java. util. The collection is a class. What's more, the class name ought to be Collection since it's a class. On the off chance that it's anything but a class, we ought to be java. util.Collection. To contrast a connection point with a class, we ought to be Collection, not Comparable.
So we shouldn't name a class with an action word, since it's anything but a class.
In Java's APIs and libraries, the names are in the camel case. For instance, List. Furthermore, it has similar importance, however, it's a lot more clear than Collection. Also, Java's APIs and library frequently utilize the action word name to name a class. For instance, ArrayList and LinkedList are the ArrayList and LinkedList separately.
If we have any desire to look, we ought to analyze the point of interaction and the class name. Here is the java. util.List interface:
We can see the class name is List. The explanation is java. util. The list is a class. Furthermore, the class name ought to be List since it's a class. If it's anything but a class, we ought to be java. util.List. If we have any desire to contrast a connection point with a class, we ought to be List, not Collection.
If you are willing to learn a Core Java course, Ready to get started today? Core Java Training Institutes in Chennai
To make your career development the best by learning this software course for more detail visit our other blog CORE JAVA.
Comments
Post a Comment