Java basic knowledge trap (2)

Source: Internet
Author: User

Java basic knowledge trap (2)
This article is published on my blog. The last time I talked about some string-related knowledge, it was quite basic. This time I also talked about object address issues, such as passing parameters. First read the following code: public void changeInt (int a) {a = 3;} int a = 1; changeInt (a); System. out. println (a); I believe this beginner knows the result and the value is passed. Let's take a look at the process: public void changestr (String str) {str = "www. luoliang. me ";} String s =" luoliang. me "; changestr (s); System. out. println (s); I believe many people know the result, however, when asked about the specific process, some people do not know what to do, including the one or two simple words that I did not talk about at all about the string pool and other ideas. This describes the memory conversion of strings. First, we know that a function changestr with the String parameter is declared, and then this "luoliang. me "(Judgment), after the creation is complete, the changestr method is called to put the s address in the string pool" luoliang. me "Address to the str variable, this function is changed to point the str variable to another" www. luoliang. of course, this process needs to determine whether the string pool exists. After the modification, the address of s is printed as the address of "luoliang. me. In this process, all the strings have not changed, because they are constants and only change the address pointed to by the variable! Now I want to understand the following code: copy the code public class Test {public static void changePoint (Point point) {point. x = 3; point. y = 4;} public static void main (String [] args) {Point point = new Point (1, 2); System. out. println ("x =" + point. x + "; y =" + point. y); changePoint (point); System. out. println ("x =" + point. x + "; y =" + point. y) ;}} class Point {int x; int y; public Point (int x, int y) {this. x = x; this. y = y ;}}

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.