20145320 Summary of the 3rd week of Java Programming (chapter fourth)

Source: Internet
Author: User
Tags class definition

20145320 "Java Programming" 3rd Week Study Summary (fourth) Textbook Learning content Summary

Object: The specific entity that exists, with a definite state and behavior

Class: A set of objects that have the same properties and behavior, a mechanism for combining operations and properties common to each object

Objects from a class: A class definition can be treated as a template for objects with similar attributes and common behavior that can be used to produce objects

Classes from objects: The generation of classes, from a few instances, to a large number of similar instances of the abstraction process (abstraction)

A class is a design diagram of an object that is an instance of a class that is defined first.

Class 4.1 and object definition classes using Class

After defining an instance, such as: Clothes c1=new Clothes () generates objects on the heap, C1 can be approximated as pointers to objects, implement lists in the data structure, C uses pointers, and Java uses references. You can specify a specific variable using a c1.color-like approach
string is the definition string, using "",%s
Char is a defined character, using ',%c
The constructor method determines how the class generates objects with this, new
Encapsulation = class + access control (Public,protected,private ... )

Object equality

Due to the relation of floating-point number error, in order to get better accuracy, use the Java.math.BigDecimal class
This class provides operation plus ()/add (), substract (), multiply (), divide ()
= = differs from equals: = = The address of the object being compared, equals is logically equal
For example, two defined
BigDecimal a =new BigDecimal(“0.1”); BigDecimal a =new BigDecimal(“0.1”);System.out.println(a==b);//显示错误
System.out.println(a.equals(b));//显示正确

4.2 Basic Type Packaging

To make Java basic types like classes, use Int-integer, Long-long, Byte-byte, Float-float, double-double, Boolean-boolean
Integer a = new Integer (10);
The action integer is returned as a double type
System.out.println(a.doubleValue()/3);//打印3.3333333...
CompareTo (), same return 0, less than return-1, otherwise return 1
System.out.println(a.compareTo(a));

4.3 Array objects

In Java, an array is an object
How to define Arraysint[] a;
Unlike the C language, Java checks array boundaries, which can trigger arrayindexoutofboundsexception exceptions
Can be used to a.length view the length of a array

There is a fill () method in the Java.util.Arrays class that assigns the same value to all the numbers in the array, using the following methodArrays.fill(a,60);

Array replication

There is a quick array copy method in the Java.util.Arrays classArrays.copyOf(a,a.length);

4.4 String Object

Defining strings using String
A.charat (0)//display first character
A.touppercase ()//display string
Turn a character group into a string
char[] cs={‘n‘,‘a‘,‘m‘,‘e‘};String name =new String(cs);
or use the ToCharArray () method of Stringchar[] cs2=name.toCharArray();

Problems in teaching materials learning and the solution process 1.

In fact, this chapter is not a good understanding of the beginning, because there is no concept of the object. So read several times the book also do not understand, think of code hosting, so the book on the code copied over. In the process of tapping the code, there is a new understanding, to read hundreds of books also go miles.

2.

When I first touched the object, I felt like a struct in C. C language is process-oriented, Java is object-oriented, but Java is more powerful class, after all, Java is built on the C language, classes can also define functions, very powerful.

Problems in code debugging and the resolution process

1

No problem

Other (sentiment, thinking, etc., optional) 1.

In Java.util.Scaaner there is a C-like scanf to let the user input, use the way
Scanner scanner =new Scanner(System.in); guess=scanner.nextInt();
This is the user input the next integer number, you can change the nextint to Nextlong, nextdouble, etc.
If you get the previous string directly, use Next ()
To get the entire line of text entered by the user, use Nextline ()

2.

Enhanced for language for(int score:scores) this is to remove the first element in the scores assignment to score and execute the statement, then take out the second element in the scores to score and execute the statement until all is done.
Enhanced for statement to visit two-dimensional arraysfor(int[] row:cords){for(int value:row){}}

Learning progress Bar

Lines of code (new/cumulative)

Blog volume (Add/accumulate)

Learning time (new/cumulative)

Important growth

Goal

3500 rows

28 Articles

300 hours

First week

200/200

1/1

10/10

Second week

300/500

1/2

20/30

Third week

300/800

2/4

20/50

Week Four

Week Five

Resources
    • Java Learning Notes (8th Edition)
    • Java Learning Note (8th Edition) Learning Guide
    • ...

20145320 Summary of the 3rd week of Java Programming (chapter fourth)

Related Article

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.