Headfirst one of the Java Learning Notes: Basics section (5.7)

Source: Internet
Author: User

First, into the world of Java

1. What you need to do:

Write source code Party.java-"Compile: Javac party.java, generate Party.class file (Eclipse is automatically compiled,. class file is stored under path Path)-" Execute on a JVM: Java party

2. Some basic Java syntax things:

(1) Integer and Boolean are not compatible in Java, so it is not possible to use integral type as a condition to judge, only a Boolean value. For example, the following wording is wrong.

1 int x = 1; 2  while (x) {3    // 4 }

(2) The difference between print and println: println inserts a newline in the last face.

Second, visit the target village

(1) The difference between class and object

(2) Garbage collection mechanism: When an object is created, it is stored in an area of memory called the heap. Java has a memory recovery mechanism. When it detects that an object is no longer being used, it is labeled recyclable. When memory is low, it is cleaned up.

(3) Public, static, final: Any program in any class can access the public static method. Any variable with public, static, and final will become a globally available constant.

Iii. Cognitive variables

(1) Type of variable: Primitive and object reference type.

There are 8 types of primitive Master data: Boolean, Char, Byte, short, int, long, float, double.

The object reference variable holds the method of accessing the object, so b=c is just the way to pass the accessor, so that C also points to the object that B points to. PS: Arrays are also objects, regardless of whether they contain primitive or object reference types.

(2) When creating an array of objects, it is easy to make an error:

1 New books[]; 2 mybooks[0].title = "Harry.potter";

However, at this time mybook[0] does not reference an object, it can be understood as our mybooks reference a bookshelf, but there is no book to you to quote it ~

1 New books[]; 2 New Books (); 3 mybooks[0].title = "HP";

Iv. behavior of the object

(1) Real participation formal parameter (argument and parameter): The argument is the value passed to the method, and when it is passed into the method it becomes a formal parameter.

(2) Java is passed by value, that is, copy delivery.

(3) Data hiding: can be accessed by the. Symbol direct access to instance variables such as Cat.height, which is dangerous, it is best to force the getter and setter, and then to mark the instance variable as private.

(4) Initialization: The number of primitive presets is 0, including char oh. The Boolean preset is False, and the object reference is null.

(5) The difference between an instance variable and a local variable (a variable declared in a method): The most important point is that the local variable has no default value and a compilation error occurs if the variable is not initialized before it is used.

(6) = = and Equals (): When determining whether the two primitive primary data types are equal, use = =, when judging whether two reference variables refer to the same object on the heap, with = =, when it is necessary to know whether two objects are really equal, use equals ().

Headfirst one of the Java Learning Notes: Basics section (5.7)

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.