Java programming philosophy 02-everything is an object (basic knowledge point)

Source: Internet
Author: User
1. Although Java is based on C ++, Java is a more purely object-oriented programming language. 2. Everything is regarded as an object

Although everything is regarded as an object, the Operation identifier is actually a reference of the object, which can be considered as the relationship between the remote control and remote control. Use the remote control (reference) to operate the TV set (object ). Without a TV, the remote control can also exist independently.

3. Where is the storage?

Register: This is the fastest storage zone, because it is inside the processor, but the number is limited.

STACK: It is located in the general-purpose RAM (random access to the storage area), but can be directly supported from the processor through the stack pointer. If the stack pointer moves down, it allocates new memory. If it moves up, it releases memory.

Heap: a common memory pool (located in the ram zone) used to store all Java objects.

Constant storage: directly stored in the code.

Non-ram storage: Stream object: The object is converted to a byte stream, which is usually sent to another machine. Persistent objects: objects are stored on disks, and they can remain in their own State even if the program is terminated.

4. Basic Java types

Basic Type

Size (BIT)

Range

Packaging

Boolean

---

---

Boolean

Character

16

0 à 216

Character

Byte

8

-128*127

Byte

Short

16

-216 à (216-1)

Short

Int

32

-232 à (232-1)

Integer

Long

64

-264 à (264-1)

Long

Float

32

-232 à (232-1)

Float

Double

64

-264 à (264-1)

Double

Void

---

---

 

5. High-Precision numbers

Java provides two classes for high-precision computing: biginteger and bigdecimal.

Biginteger supports Integers of any precision, which can accurately represent integer values of any size without any information loss.

Bigdecimal supports the number of points with any precision.

6. Java Array

One of the main goals of Java is security. Java ensures that its array is initialized and cannot be accessed outside of its scope. This range check is at the cost of a small amount of memory overhead for each array and subscript check for the runtime. However, security and efficiency are improved. Therefore, it is worthwhile to pay these costs.

7. Never destroy objects.

Although the following code is valid in C ++ and C, it is not allowed in Java.

{

Intx = 12;

{

Intx = 23; // illegal

}

}

Java has a garbage collection mechanism to monitor all objects created with the New Keyword and identify objects that will no longer be referenced. You only need to create objects and they will disappear once they are no longer needed.

8. Default Value of basic members

If a member of a class is of the basic data type, Java ensures that it has an initial value even if it is not initialized. However, this is only the case when the variable is a member of the class. If it is used as a class method, an error will be reported during compilation.

Other Default values are either null, 0, or false. Let's not talk about it.

9. An object call method is called to send a message to an object. 10. One of the most powerful advantages of Java is that it has a large set of standard libraries. (Below is a small example)
package Chapter02;public class Demo01 {    public static void main(String[] args) {        System.getProperties().list(System.out);        System.out.println("*" + System.getProperty("user.name"));        System.out.println("*" + System.getProperty("java.library.path"));    }}
11. Compile and run

Javac demo. Java

Java demo

12. Example 1:

package Chapter02;//: object/HelloDate.javaimport java.util.*;/** * The first Thinking in java example program. *  * Displays a String and today`s date. */public class HelloDate {/** * Entry point to class & application. *  * @param args *            array of string arguments */public static void main(String[] args) {System.out.println("Hello, it`s:");System.out.println(new Date());}}/* * Output: (55% match) *  * Hello,it`s: *  * Wed Oct 05 14:39:36 MDT 2005 */// :~
Example 2:

Package chapter02;/** A annotation demo class */public class demo02 {/** a variable */Public int X; /** @ author Wang yuchao * // *** @ Param A * parameter A * @ Param B * parameter B * @ return blank * @ version 1.0 * @ throws 13. Encoding Style

I learned too much about this, so I won't talk about it. It is summarized as "camper style ". This is a standard.

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.