I. Java Fundamentals
1. Data type
Char One byte Chinese 2-3
String
int long short byte (127-128)
Float double
Boolean
2. Data conversion
Large to small section casts
Long time=199999888;
int timeint= (int) time;
Short age=90;
int ageint=age;
String agestr= "19";
int->integer Class
int Age1=integer.parseint (AGESTR);
String money= "20000.05";
Reference Class Float->float Class
Double->double class
float moneyfloat = float.parsefloat (Money);
String to Value
Example
‘
1. Enter a value (3-10) to figure out its factorial
BYTE b1=10;
Short s2= (short) b1+11;//error
float scope = 990.5f;
Decimal type default double integer default int
Numeric Type-string
21-> "21"
String s2str=string.valuueof (S2);
String scopestr=string.valueof (scope);
3. Object-oriented
Class:
Properties (member variables)
Method (member method, construction method)
Members of the class four access rights:
Public: Class object access
Default: Class object access under the same package
Protected: The subclass member method of the class can be accessed
Private: The member method of the class can access the
Grammar:
Class Name {
member variables;
Construction method;
Member methods;
}
Class Name: The first character must be uppercase, followed by the first character of each phrase is capitalized
Member variable: the first character is lowercase, followed by the first character of each phrase is capitalized
Constructor Method Name: = Class name does not have an identifier for the return type, access rights are public
Member method name (named) = Member variable. Composition: Access right return type method name {}
Class person{
private String name;
Public person () {
}
Public person (String name) {
This.name=name; (use of local variables)
}
public void Market (String tings) {
}
Public Sting GetName () {
return name;
}
}
Instantiation of the class:
Class reference = new Class construction method ();
Person P=new person ();
P.market ("fruit");
4. Common Classes
String, Math, Date,simpledateformmat
String:length ()
Replace (String ostr,string rstr)
SUBSTRING (int start)
substring (int start, int end)
Equals (String s)
Format (String pattern,object ...);
Math:double random ()//[0,1)
Create new Project:new SDK, select Jdk_home
Development environment: JAVA; 1.8/1.6 IntelliJ Idea (Eclipse)
Structure:
. idea
SRC (source information)/main App.java
iML
Shortcut keys:
Alt+[insert] Generate classes, packages, class members
alert+ enter [Enter] solve the problem key, guide package, type conversion, exception handling, etc.
Alt+ctrl+s Open Settings page
Alt+ctrl+shift+s Open the Project file Settings page
Set Font size: Setting->editor->color&fonts
->save
Basic Java Content