Learn Java DAY3 from scratch

Source: Internet
Author: User
Tags array definition

System.out.print () Last output no carriage return

System.out.println () The last output has a carriage return

System.out.print ()

The output format is splicing type

such as output 1+2=3

System.out.print (1+ "+" +2+ "=" +3);

Three types of formal parameters

Int,double/float,boolean

Array definition

Int[] A = new int[5]

Int[] A = new int[]{1,2,3,4}

The length of the array a.length

A is present in the stack, the array is stored in the heap, and a gets the 0-bit address value in the array

(Local variables are present in the stack, global variables exist in the heap)

The heap opens up space, can be saved, the stack is run once and disappears

But when the entire file is executed, the memory of the array's heap is freed

Java is better than C + + for memory optimizations, Java has a garbage collection mechanism, and C + + requires programmers to do it manually

If I now define a = = null (lowercase) then nothing points to the array, and the garbage collection mechanism frees the space at an irregular time.

1. So if I now define a int[] b = A;a = = NULL

Output B[1] Results returned 2

2. Definition int[]b = A; A[1] = 5;

Output B[1] Results returned 5

Because A or B is obtained is the address of the array's 0-bit, if change the current a[1] then the equivalent at this address changed the value

Unlike defining int b = a[1], changing the value of a[1],b again does not change

About classes

Class is equivalent to a separate function

Sample Example

Class car{    String  color = "Red";    static int num = 4;    public static int run ()    {       //System.out.print (num);        return num;    }} Class test{public    static void Main (string[] args)    {    car c = new Car ();    C.color = "Blue";    System.out.print (C.run ());}    }

In this case, static meaning is the equivalent of opening a space, and here the int is a local variable, only exists in the stack, can not be conducted

Learn Java DAY3 from scratch

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.