1) for the = = operatorIf the variable that is acting on the base data type, compares the value of its stored values directly for equality;If you are acting on a variable of a reference type, the address of the object to which you are pointing is compared
There are 8 basic data types in the middle of Java:Float type: float (4 byte), double (8 byte)Integer: Byte (1 byte), short (2 byte), int
On the surface, this is just a few basic problems. When you really understand it, you will find that: Ah, it was the same thing! The following are several Java puzzles. Mistakes will occur without careful analysis.
Equals or not?
See the following code:
Code snippet 1
publicstaticvoidmain(finalString[]args){
Integera=newInteger(100);
Integerb=100;
System.out.println(a==b);
}
What is the
conflicts in Java. This method is called the chain address method, because it uses a linked list to store elements within the same bucket. Usually the situation hashmap,hashset,linkedhashset,linkedhashmap,concurrenthashmap,hashtable, Both Identityhashmap and Weakhashmap use this approach to handle conflicts.
Starting with JDK 8, Hashmap,linkedhashmap and Concurrenthashmap use the balance tree to replace th
The Hashcode method Returns the hash code value of the object. This method is supported to provide some advantages to the hash table, for example, the Hashtable provided by Java.util.Hashtable.The general agreement of Hashcode is:During Java application execution, when the Hashcode method is called multiple times on th
The world is always a picture more than tens of thousands of words!The following 8 images are from the program Creek Java tutorial, which is currently the most popular article on the site.I hope this article will help you to review the knowledge you already know. If the picture is not clear enough, you may need to read a detailed article or search.1. Properties of the string object that cannot be changed(pl
1.string invarianceHere's a picture showing what this code does
12
String s = "abcd";s = s.concat("ef");
2.the difference between the Equals () method, the Hashcode () methodHashcode is designed to improve performance. The difference between the Equals () method and the Hashcode () metho
. Today, interfaces look more and more like the functions of abstract classes.Default methodJava 8 also allows us to add a non-abstract method implementation to the interface, just using the default keyword, which is also called the extension method. When the interface is implemented, the default extension method can be used directly on subclasses, which are used in a manner similar to non-abstract member methods in abstract classes. However, the exte
Original link: Top 8 diagrams for understanding JavaTranslators: AnchorTranslation time: October 29, 2013The world is always a picture more than tens of thousands of words!The following 8 images are from the program Creek Java tutorial, which is currently the most popular article on the site.I hope this article will help you to review the knowledge you already kn
A picture wins thousands of words, the following illustrations are from the Program Creek Web site Java tutorial, currently they have the most votes.1. String invarianceHere's a picture showing what this code doesString s = "ABCD"; s = S.concat ("EF");2. The difference between the Equals () method and the Hashcode () methodHashcode is designed to improve performa
A picture wins thousands of words, the following illustrations are from the program Creek Web site Java tutorial, currently they have the most votes. If the plot does not explain the problem, then you can use its title to get a glimpse of it.1. String invarianceHere's a picture showing what this code does
12
String s = "abcd";s = s.concat("ef");
2. The difference between the Equals
A picture wins thousands of words, the following illustrations are from the program Creek Web site Java tutorial, currently they have the most votes. If the plot does not explain the problem, then you can use its title to get a glimpse of it.1. String invarianceHere's a picture showing what this code does
12
String s = "abcd";s = s.concat("ef");
2. The difference between the Equals
1. String invarianceHere's a picture showing what this code does
12
String s = "abcd";s = s.concat("ef");
2. The difference between the Equals () method and the Hashcode () methodHashcode is designed to improve performance. The difference between the Equals () method and the Hashcode ()
A picture wins thousands of words, the following illustrations are from the program Creek Web site Java tutorial, currently they have the most votes. If the plot does not explain the problem, then you can use its title to get a glimpse of it.1. String invarianceHere's a picture showing what this code does
12
String s = "abcd";s = s.concat("ef");
2. The difference between the Equals
A picture wins thousands of words, the following illustrations are from the program Creek Web site Java tutorial, currently they have the most votes. If the plot does not explain the problem, then you can use its title to get a glimpse of it.1. String invarianceHere's a picture showing what this code does
12
String s = "abcd";s = s.concat("ef");
2. The difference between the Equals
method and static method do not affect the contract of the function interface. They can be used at will, that is
Function interfaces can contain static methods. One or more static methods do not affect the SAM interface as a function interface, and static methods can provide method implementation.
The default method that can be modified by default. This keyword is added in Java 8 to implement some interfac
are equal. You may often have to decide if today is a special day, such as birthdays, anniversaries, or vacations. Sometimes, you will be given a date to check whether it is a day, for example, a holiday. Here's an example that will help you complete this task in Java 8. As you can imagine, localdate rewrites the Equals method to compare dates, as follows:
Loca
date created is what we wrote, January 14, 2014.Example 4 How to check if two dates are equal in Java 8When it comes to the actual task of dealing with time and date, it is common to check that two dates are equal. You may often come across to determine if today is a special day, such as birthdays, anniversaries, or vacations. Sometimes, it will give you a date to let you check if it is not a certain day, say holiday. The following example will help
OriginalFirst look at the instructions above:/** * A container object which may or could not contain A non-null value. * If A value is present, {@code isPresent ()} would return {@code true} and * {@code get ()} would return the value. *optional is a container object that may or may not contain a non-null value, and if this value exists, the Ispresent method will return the True,get method will return it itself * And look at the class:Public final class OptionalHere is a final classThis is a v
Java Class Design
Implement Encapsulation
Implement inheritance including visibility modifiers and composition
Implement polymorphism
Override hashcode, Equals, and ToString methods from Object class
Create and use singleton classes and immutable classes
Develop code that uses static keyword on initialize blocks, variables, methods, a
and so on. The date is WYSIWYG, as shown in the following example, January 14, without any hidden organs.Localdate dateOfBirth = Localdate.of (2010, 01, 14); System.out.println ("Your Date of Birth is:" + dateOfBirth);Output:your Date of birth is:2010-01-14You can see that the created date is exactly what you expected, exactly as you wrote January 14, 2010.Example 4, determining whether two dates are equal in Java 8A class of time in real life is to
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.