(i) Java language Introductory Tutorial The composition of the Java class has always been like a slogan: The day is a seven days and another seven days. And what I'm trying to say is that Java is used as a class and class. Java is a target-oriented language, and the goal is to instantiate it by class. A Java application, whether simple or messy, is made up of several Java classes. Therefore, for beginners, it is necessary to know the composition of the Java class first.
The composition of the Java class is first and foremost 3: data members, structural methods, method members.
The first thing to look at is the code below, which is a shorthand Java class:
Package com.csst.vo;
public class Customer {
1. Data members
Private String CustName;
Private String pwd;
Private Integer age;
2. Structural approach
Public Customer () {
}
Public Customer (String custname, string pwd) {
This.custname = CustName;
This.pwd = pwd;
}
Free Membership Network
Public Customer (String custname, string pwd, Integer age) {
Super ();
This.custname = CustName;
This.pwd = pwd;
This.age = age;
}
3. Approach members
Public String Getcustname () {
return custname;
}
public void Setcustname (String custname) {
This.custname = CustName;
}
Public String getpwd () {
return pwd;
}
Free Membership Network
public void SetPwd (String pwd) {
This.pwd = pwd;
}
Public Integer Getage () {
return age;
}
public void Setage (Integer age) {
This.age = age;
}
}(ii) Java language Introductory Tutorial Java class Package Java application is made up of several classes. But logically, the questions that these classes deal with are different. For example, some classes handle database call queries, and some classes deal with security manipulation questions ... It's like we're checking the documents on the hard drive, and we're not going to put them all in a mess at the root of one of the hard drives, but instead classify them in a different way, and put them under the same folder. Java is also used in the same class, but also probably in accordance with the logic of classification, placed in a different directory, which is the concept of the package.
Despite the Java syntax itself, it is not necessary to explicitly specify the package name for a class, and it is possible to use the tacit package. However, in the process of developing a Java project, there is probably a package for any class. Specify a package name for a class, using the following syntax:
Package com.csst.db;
public class Customerdao {
}
Simply specify the package, and after compiling the Customerdao, the class file will exist under the Com/csst/db folder. Physically, the package is actually a folder. But the need to note is: Only one class specifies the package name, then the package name is a bit of the name space, that is to say, Customerdao.class's name is actually Com.csst.db.CustomerDAO, not Customerdao. Because of this, the use of this class, you have to specify a good name, such as:
Package com.csst.service;
Class CustomerService {
Private Com.csst.db.CustomerDAO DAO;
Note: If the package name of CustomerService is the same as the Customerdao package name, then the package name is not required.
In practice, no one is willing to write such lengthy names, usually using import key words, the different packages of the class to import.
Package com.csst.service;
Import Com.csst.db.CustomerDAO;
public class CustomerService {
Private Customerdao DAO;
}
Note: If you want to use many of the classes in the Com.csst.db package together, you can import multiple classes using import com.csst.db.* sentences.
All in all, the package is to depart from the logical general class. When Java class has a package in the Java class, not only can be very good to prevent the name of the question (the package is a bit of the name of the class, to ensure that the package name is not the same as simple), and also very good use of the Java language modifier, permission manipulation. (c) Various data in Java Classes This article is some of the various data in Java classes in the Java tutorial.
According to the location of the data declaration, the Java class can be divided into two categories, the declaration of the azimuth is different, the effect field is different.
1. Data members: Data declared in the class body, called data members.
2. Local variables: The data declared in the method is called a local variable, also known as a local variable, a method variable, an automatic variable. Local variables can only be used in this approach.
As shown in the following example:
Package com.csst.test;
Free Membership Network
public class TestData {
/**
* @param args
*/
1. Data members
private int x;
private int y;
public void test (int y) {
2. Local Variables
int z;
This.y=y;
SYSTEM.OUT.PRINTLN (x);//Output 0
System.out.println (z);//Compile fault
}
}
Next, summarize the differences between the data members and the local variables.
1. Call permission modifier: the access modifier can retouch the data member, but cannot retouch the local variable.
2.static retouch: The static modifier is capable of retouching data members, but cannot retouch local variables.
3. Data type: Data members and local variables can all use any data type.
4. Initial value: Data members can not assign the initial value, there are tacit values, such as the integer acquiescence is 0, floating-point type acquiescence is 0.0, the character type acquiescence is/u0000, Boolean acquiescence is false, all citation type acquiescence to false. and local variables must be assigned initial value before use, otherwise there will be compile fault.
5. Effect fields: Data members can be used throughout the class, with permission only, or in other classes through the object or class name (static member) call. Local variables can only be used in the current approach.
6. Life cycle: Data members are initialized with the loading of the class (static) or the creation of the target (non-static), destroyed by the destruction of the target or the destruction of the class. Local variables are temporarily initialized when the method is called, and the method is immediately retracted.
7. If you encounter a condition where the parameter is exactly the same as the data member, use this to differentiate, this indicates the citation at that time, and the data member is the point.
Beginners only need to know the above points, trust and look at the Java class of various data, will understand much. (iv) The data types in Java language and the first components of the String class Java classes are data members and method members. While the declaration of a data member is necessary to specify its data type, it is also necessary for the declaration of the method member to specify its return value type, if the method has formal parameters, it is also necessary to specify its parameter type. Therefore, it is very necessary for beginners to know the data types of Java speech.
The types of data in Java speech can be divided into two main categories: the fundamental data type (also known as the primitive type) and the citation type (also the person class type, the target type, etc.). Java speech is a goal-oriented language, most of the data are citation types, the fundamental type is primarily for mathematical operations. These two types of parting are described below.
1. Fundamental data types:
The fundamental data types in Java are divided into 4 major categories
Integral type: Byte,short,int,long
Floating point type: float,double
Character type: Char
Logical type (also called Boolean): Boolean (True, False)
It is worth noting that the data lengths of the fundamental data types in Java are cross-channel and are not different due to different channels of operation.
Other requirements note that the integer acquiescence is stored in 32-bit int, and the floating-point type is implicitly stored as a 64-bit double. As the following analogy:
Package Com.csst.test;public class Testtype {
/**
* @param args
*/
public static void Main (string[] args) {
Float f=1.0;//will have compile fault
}
}
The first line that renders the fault is caused by the transformation of the data type. 1.0 is a floating-point type, with the tacit consent of a double 64-bit storage, and the program will be 1.0 declaration bit 32 bits of float, will render compile fault. The fundamental principle is that high-precision numbers cannot be directly assigned to low-precision numbers. Fixed as follows:
float f= (float) 1.0;
Called forced type transformation.
2. Citation type:
It is possible to say that data other than the underlying data type are citation types. It can also be said that the citation type is the object, perhaps the target is the citation type. Many people will have a question about what type of string to count? Let's see that, in the 8 categories of the underlying type, there is no string, then it is possible to say that the string is a citation type. The next question, however, is that the citation type is the goal, and the goal is not all created with new? Why do we often see the following sentence:
String s= "Hello World";
In fact, in all classes, including our own creation of the class, as well as the API of the existing classes, just a string this kind of special, can directly use = To assign value, do not have to use the new key word. However, since the string is a target, it can also be created using new, such as:
String S=new string ("Hello World"); (v) structural approach in Java language after the introduction of the above 4 articles, we now know the basic concepts of Java class composition, Java language package, permission call Retouch character, data type. Java is the goal-oriented language, the running period, that is, a number of goals to interact with each other, the process of sending audio. For beginners, it is important to know the Java class, how to create a goal.
If there is a class named customer, it is necessary to use the New keyword to invoke the structure method to create the target of the class. For example, the customer class would have the following 3 structural approaches:
Public Customer () {
}public Customer (String custname, string pwd) {this.custname = Custname;this.pwd = pwd;} Public Customer (String custname, string pwd, Integer age) {this.custname = Custname;this.pwd = Pwd;this.age = age;}
Based on this analogy, the characteristics of the structural approach are summarized:
1. The name of the structure method must be the same as the class name, and the case must be exactly the same.
2. The structural approach can be used to retouch Furun ornaments with four privileges.
3. The structure method does not return a value type, note that even void is not.
4. The structural approach of a class can have multiple, primary by parameter differences.
Getting started with the Java language tutorial