JAVASE basic knowledge Note 4

Source: Internet
Author: User

Java SE 9
1. Three basic features of object-oriented programming: Inheritence, Encapsulation, and Polymorphism
(Polymorphism)
2. encapsulation: A class contains data and methods. Placing data and methods in a class constitutes encapsulation.
3. How to define a class?
Modifier class Name
{
// Class content (including attributes and methods)
}
4. method. How to define a method?
Modifier return type method name ([parameter 1, parameter 2, parameter 3…])
{
// Method body
}
5. The main method is the entry point of the entire Java program. If the class definition does not contain the main method, the program cannot be executed.
6. The method definition cannot be nested, so that another method cannot be defined in a method. Methods can only be defined in classes.
7. About method execution: first define the method, and then you can use the method (call method ).
After use, the method can return values. Whether the return value of a method is determined by the method definition.
8. How to generate objects? Generate objects through classes (usually use the new keyword to generate objects ).
Public class Person
{
}
Class name variable name = new Class Name ();
Person person = new Person ();
Person person2 = new Person ();
Person person3 = new Person ();
9. The method call must be completed through an object. The method call form is:
Object variable. Method Name ([parameter value 1, parameter value 2, parameter value 3...]);
10. Notes about the method:
1) In the method definition, the return type of the method is consistent with the variable or constant type after return.
2) When calling a method, the parameters passed to the method must be consistent with the parameters in the method definition (number of parameters 1 ).
).
3) The return type of the method definition must be the same as the variable type of the method returned value.
11. public int add (int a, int B)
{
Return a + B;
}
The parameter used for method definition is a formal parameter.
Int a = test. add (8, 3 );
The specific value assigned to a method call is the actual parameter.
12. The keyword void indicates that the method does not return a value.
13. If the method does not return a value, use the void keyword when declaring the method. There are two methods in the method definition:
Situation implementation does not return values:
A) do not use the return statement.
B) return is used, but there is no value or variable behind return. return is followed by a semicolon, indicating
Exit the method and return to the call end of the method.
Usage:
Return;
 
Java SE lecture 10
1. the attribute in the class is also called the member variable. The attribute is expressed as property or
Attribute.
2. An Object is also called an Instance ). The process of generating an object is also called Instantiation.
3. Naming Conventions
A) Class: the first letter is capitalized. If a class name consists of multiple words, the first letter of each word is capitalized,
No connector is used in the middle. For example, the Person class and the MemberTest class.
B) method: lowercase letters. If a method consists of multiple words, all the letters of the first word are full.
All are in lower case, starting from the second word, and the first letter of each word is in upper case. For example, add or addThreeInt.
C) attributes: The naming conventions and methods are the same. For example, age, ageOfPerson.
4. Attributes must be defined in the class, also known as member variables, and variables defined in methods are called local variables.
5. How to define attributes?
Public class Person
{
Modifier type attribute name;
}
How to use attributes? Use the. operator like the method. First, you need to generate a class instance and then use the instance + "."
To use properties.
For example:
Person person = new Person ();
Person. age
6. Before using local variables, you must declare and assign the initial values. Before using member variables, you must declare them, but do not assign the initial values.
7. Relationship and difference between member variables and local variables:
A) whether it is a member variable or a local variable, it must be declared (defined) before use ).
B) for local variables, Initialization is required before use; for member variables, before use
Start-up. If you do not initialize a member variable, each type of member variable has
Default Initial Value
The initial values of the I. byte, short, int, and long types are 0.
Ii. The initial values of float and double types are 0.0.
Iii. Initial Value of the char type '\ u000000'
The initial value of the iv. boolean type is false.
8. reference type: The reference type is used on objects. An object can be referred to by multiple references
Direction, but at the same time, each reference can only point to a unique object. If an object is pointed to by multiple references,
No matter which reference modifies the object attributes, it will be reflected in other references.

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.