1. In the interview today encountered a problem, the code is as follows:
public class Test2
{public
static void Main (string[] args)
{
int[] arr=new int[5];
Assigning value to an array member
arr[0]=2;
arr[3]=5;
for (int i = 0; i The output results are as follows:
Show:2
show:0
show:0
show:5
show:0You will find that no assigned member, the output default value is: 0;
Reason: Because int is th
modified functions, each operation is a new object, so special Treatment. Can be considered as a pass Value.Integer is the same as String.The class variable that holds the value is the final attribute, cannot be modified, and can only be re-assigned/generated new Object. When an integer is passed into the method as a method parameter, its assignment causes the reference of the original
References: http://www.360doc.com/content/07/1122/09/9426_838237.shtml
In Java, only values are passed, but references are not passed. However, the passed value can be a specific value or an object reference. You can use this sentence to describe "Java functions pass values, and Ja
object, so the object is passed by reference, is there a problem?The output of the program run is:Good afternoon.This shows that S2 and s are the same object.One thing to clarify here is that the object is actually a value, because the object is a pointer, and this assignment is the assignment between pointers, so in Java it is said to be a reference. (What is a reference?) No, it's an address. What is the
the other is the value passed.According to common sense, should be passed the address of the object, is this because of the automatic boxing and unpacking, the compiler to help you do this result in the final value is passed?Take this problem first to see the class file's anti-compilation code:////Source code recreated from a. class file by IntelliJ idea//(Powered by Fernflower Decompiler)// Public classTe
When I first learned Java, I had this suspicion, but has not been validated; recently in Oschina to see someone in answer to the question also said so, and began a look at the idea of the--java.lang.object.hashcode () return value is not the object memory address.(Incidentally, a review of JNI) hashcode contract
Speaking of this question, everyone's first reaction must be the same as me-to check the source
First, Java does not reference and pass this.
Java only supports value passing, All passed values,The value is transmitted for the basic data type, and the address value is transmitted for the reference type.
Let me take a look at the relationship between rice noodles and fa
How to pass the value of "Java"When you ask most programmers whether Java is a value or a reference, you may get one of two answers:(1) Java passes the original type data using the method of passing the value, when passing the obj
Tag: Cannot perform reflection ring PAC his private SSE constructorWe all know that using Java reflection can dynamically change the behavior of an object at run time, even private final member variables, but not all cases, you can modify the member variable. Give a few small examples today.
Basic data types
String type
Integer type
Summarize
First look at the basic types of modif
amount of stored data.
è load factor: The ratio of actual objects in the hash table, 75% most suitable
6. "Key-value" pairs of the canonical--hashtable class
in the Java "key-value" Pair-type collection class, the implementation details of using hash function to optimize the data search efficiency and to deal with data conflicts in hash table are already encaps
not affect the integer outside, because the value in the "memory unit" of interger1 and interger2 will not change, the object type it points to has not changed.//// Here we need to explain a problem, that is, the stringbuffer type object. Because its content can be changed, the "Pointer" in the change function changes the stringbuffer object through operations similar "*".//// Itself, it is obvious. (The s
,不会改变实际参数的值String test1="Hello";pk.change(test1);System.out.println(test1);//StringBuffer和StringBuilder等是引用传递StringBuffer test2=new StringBuffer("Hello");pk.change(test2); System.out.println(test2.toString());}public void change(String str){str=str+"world";}public void change(StringBuffer str){str.append("world");}}
The output is:HelloHelloworldThe operation of string and StringBuffer produces different results.4. ConclusionIn conjunction with the above analysis, the conclusion about
test1="Hello";pk.change(test1);System.out.println(test1);//StringBuffer和StringBuilder等是引用传递StringBuffer test2=newStringBuffer("Hello");pk.change(test2);System.out.println(test2.toString());}publicvoidchange(String str){str=str+"world";}public voidchange(StringBuffer str){str.append("world");}}
The output is:HelloHelloworldThe operation of string and StringBuffer produces different results.4. ConclusionIn conjunction with the above analysis, the conclusion about
called up.Two:For this return type, use it flexibly. For example, or the above question, what if I want to output a string of type strings?1. first, when defining a function, the return type will be string;The value returned by 2.return must also be of type string3. The data type when the function is called again is the string typeThe code is as Follows:It does not lie in: integer type after the operation
, through with the operator bar integer value of the high 16 bits set to 0, and then the right to move 8 bits, the resulting number is the third IP. 4, with the operator bar integer value of the high 24 bits set to 0, the resulting number is the fourth IP. publicclassiptolong{// Converts an IP address in the form of
classesSuch as:Object object= New Integer (1); To define a Interger classInteger i= (integer) object; In order to cast this object into the Interger classThe String:string class represents a string, and all string literals (such as "ABC") in a Java program are implemented as instances of this class. Check the order of the sequenceCharacters, compare strings, sea
Similar to C #, Java also encapsulates basic types, int encapsulates integer classes, and Boolean encapsulates Boolean classes. In this way, the basic type breaks through the value type restriction and gains the benefits of object-oriented. However.. NET is different. The encapsulation class in Java is a real reference
= fis.read (buffer, 0, 1024x768))! =-1) {
Md.update (buffer, 0, length);
}
Fis.close ();
//Convert and return a byte array containing 16 elements, returning a numeric range of 128 to 127
byte[] md5bytes = Md.digest ();
StringBuffer hexvalue = new StringBuffer ();
For (int i = 0; i
int val = ((int) md5bytes[i]) 0xFF; Explanation See the bottom
if (Val ) {
/**
* If less than 16, then the 16 binary form of the Val value
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.