001
Source
Editor
Output
BYTE-code file
Jvm
New class file in Eclipse, and changes encountered with basic errors
public class a{
public static void Main (string[] args) {
System.out.printf ("Welcome to Beijing Lily")
}
}
Public ststic modifier
void return type is empty
Main Method Name
() parameter
String character type
[] Array
Args parameter value//modifiable
002 Write the Java source program with Notepad and run
JDK Download and environment variable configuration
Java-version Check that the environment variable is configured OK
Javac A.java compiling source files
Java A output byte-code file
003 Java's program structure
Writing Source files = Writing class files
class must be defined with the "keyword" class and specify the class name
Main is a fixed notation
Class: Teacher is Cindy
A class is a collection of objects of a certain type
Object must be a class
Class can instantiate an object
004 data Types for Java
Java Basic data types
A total of 8 (2 (Numbers and characters))
Integer: byte-128---+127
short-32768_+32767
int-2147483648_2147483647
Long
Decimals: float/double
Character type: char: ' A '
Boolean value True and False
Extended Data types
005 Constants
Constants: Data that is not changed during the process of computer processing.
Float Type constant: 1.5f
Double Type constant: 1.5
Char: ' 1 ', no single quote is number 1
Boolean:true, False
String constants: "HelloWorld"
006 variables
Principle:
1, the variable must have the type;
2, the variable must have a name;
001
Source
Editor
Output
BYTE-code file
Jvm
New class file in Eclipse, and changes encountered with basic errors
public class a{
public static void Main (string[] args) {
System.out.printf ("Welcome to Beijing Lily")
}
}
Public ststic modifier
void return type is empty
Main Method Name
() parameter
String character type
[] Array
Args parameter value//modifiable
002 Write the Java source program with Notepad and run
JDK Download and environment variable configuration
Java-version Check that the environment variable is configured OK
Javac A.java compiling source files
Java A output byte-code file
003 Java's program structure
Writing Source files = Writing class files
class must be defined with the "keyword" class and specify the class name
Main is a fixed notation
Class: Teacher is Cindy
A class is a collection of objects of a certain type
Object must be a class
Class can instantiate an object
004 data Types for Java
Java Basic data types
A total of 8 (2 (Numbers and characters))
Integer: byte-128---+127
short-32768_+32767
int-2147483648_2147483647
Long
Decimals: float/double
Character type: char: ' A '
Boolean value True and False
Extended Data types
005 Constants
Constants: Data that is not changed during the process of computer processing.
Float Type constant: 1.5f
Double Type constant: 1.5
Char: ' 1 ', no single quote is number 1
Boolean:true, False
String constants: "HelloWorld"
006 variables
Principle:
1, the variable must have the type;
2, the variable must have a name;
3, the variable has the size;
007-Piece Structure
If, else if, else
Meet specific conditions and execute the corresponding statement
008 Operators and expressions
Arithmetic operators: +-*/% (modulo-to-take remainder), + + 、--
y++//y=y+1;
Y--//y=y-1;
Assignment operators: =, + =,-=, *=,/=,%=
Relational operators:> < >= <=
The result of the operation is: true, False
Logical operator:& |! ^&& | |
& Bitwise AND: True on both sides true
| bitwise OR: true on one side
&& logic and: true on both sides
& and && difference???
& Around two times will be calculated, whether true or false
&& left calculation for false not calculated, direct short Circuit
! Logical non: not true or false
<< >> bit operations
? : Three mesh operator
Boolean z=y>3?true:false//
int Z=y>3?2:5
Assignment operators have the lowest precedence
009 for Loop
Loop statement: Do one thing over and over again
Expression is true all the time, false exit For loop
010 While Loop statement
Dead Loop:
while (x<=3) {
SYSTEM.OUT.PRINTLN (x);
}
Normal as follows
while (x<=3) {
SYSTEM.OUT.PRINTLN (x);
x + +;
}
do{
}while ();//execute the loop body before executing the judging condition
What is the difference between a while statement and a Do while statement?
While statement condition is not established, do not execute the loop body, exit the loop directly;
Do While statement to execute the loop body first
**break statement: Terminating a loop
**continue statement, encountered continue statement will jump directly to the condition judgment
011 values
1. An array is a set of data with the same type of data. An object that stores a set of data
2. Declaration of an array
3. Initialization of arrays
Statement:
An array declaration is like an empty bookshelf, not yet written;
Int[] x;
Float[] x;
Char[] x;
String[] x;//String type
*********
Methods for initializing arrays:
1.
Int[] x;
x= new int[5];//An array of length 5
X[0]=1;
...
x[4]=5;//put the value up.
2.
Int[] X=new int[5]
X[0]=1;
...
x[4]=5;
3, int[] x=new int[]{1,2,3,4,5};
012 Designing a real application
013 for the corresponding behavior state
Object is a known thing
Object performs an action
Class is the blueprint for an object
Existing classes, and then objects
014
Construction method Purpose: Used to initialize some instance or property value, member variable, no return type
Constructor method names are consistent with class names
015 Overloading of construction methods
Constructor method: Modifier + method Name
Overload:
There are multiple construction methods in a class,
The constructor method name can have the same name, but not identical
Construction parameter types can be the same, the order is not the same
016 Overloading of methods
Common methods:
Modifier Type method Name {
Output
Returns
}
* * Parameters cannot be the same
017 tell the object what to do-method to pass the parameter
1, the data type of the parameters must be consistent;
2, the transfer of parameters, the value of the parameter is passed;
3, the main method to pass the parameter analysis;
Main (string[] args)
Arguments to the args array
for (int i=0;i<args.length;i++) {
System.out.println (Args[i]);
}
Operation Note: After interpretation, the runtime passes in parameters. Such as
Java app2 "11" "33"
The return value of the 018 method
The composition of the method:
Modifier public
return value void or other
Method name
Parameter list
{} method body
Method type with return value, must have return
After the method returns the call, the main program can snap to the return value
019 creating an array of objects
Declares the length of an array; class []
Assign a value to each element;
020 The relationship between objects and objects
For example: computer, mouse are objects,
Relationship:
Depend on
Association
Polymerization
The car class includes the object of the engine class (has a)
The classes contained in can also exist independently
Combination
Cannot exist independently; For example, the head class contains the mouth class
Inherited
211 Objects How do I call another object?
* * First class, then object
* * Call an object to instantiate an object first
One main program, two association class files
Package a run:
Create a new manifest file: MANIFEST.MF (Input main-class: Main Program class name)
Jar CVFN Test1.jar manifest.mf teacher.class student.class test1.class
Java-jar Test1.jar
022 Inheritance of objects
Inheritance: Subclass Inherits Parent Class (base class)
Extends inheriting parent class member variables, methods, private non-inheritable
Subclasses copy an identical method from the parent class
023 overriding of methods
1. Coverage must occur within the inheritance
2. Subclass overrides the parent class with the same name method override
Principles of Coverage:
1, the parameters of the subclass method must be consistent with the parent class;
2. The scope of the modifier for the subclass method must >= the modifier of the method with the same name as the parent class
024 which method is called?? Polymorphic
Parent class object =new (); Polymorphism: A method that calls a subclass
A subclass object must never be a new parent class
A method declared by a parent class can only be a property and method overridden by a subclass;
A parent class can have more than one child class
025 Keywords: this and super
This refers to the current object.
The subclass object is conceived by calling the parent class construction method first
Super: Call the constructor method of the parent class to write the function first
Polymorphic
026-Do not change the initialized class
(Abstract Class)
1, the declaration must add the keyword abstract
2, Abstract method: No method Body method,
public void Eat () {}
3, the class has an abstract method, this class is abstract class
4, Purpose: Quilt class overrides overwrite
027 interface
Inheritance in abstract class is extends
The inheritance in the interface is implements
The methods in the interface are all abstract methods
Member variable in interface: Pulic static final
Must be initialized
Interface is the highest definition of abstraction
When a subclass implements an interface, it must overwrite all the methods in the interface
Java function Library
028 How to organize classes---packages
Package:java is called packing.
Location: Declaration Office
Javac a.java-d.//Specify directory, point as Directory
Java com.lily.pkg1.a
Purpose of Packaging: organizing class files
Keywords: package, import
class file, using a method from another directory, the import dependent path (the path of the package) is required
029 How to use the Java API
Api:application Programming Interface Application Interface
Note View: JDK API documentation (important)
030 String Functions
String is based on char type
1. The first letter of the custom class should be capitalized;
2. Each class in Java is an abstract data type
**substring (5) Start next mark, end at 5th position
SUBSTRING (5,8), start position, end position
Trim compress left and right spaces on both sides
3. The string class is the final class and cannot be inherited
**stringbuffer
**stringbuilder
031 Date function
Date class date-"Java.util package
Date class:
1, Date () construction method;
2. Calendar
032 Math function
Mathematical functions
Encapsulates a lot of mathematical operations;
E, PI (equivalent to constant, can only be assigned a value)
ABS Absolute
Ceil:Math.Ceil (3.5)
Floor:Math.Floor (3.5)
Random number
Round rounding
Aggregate functions
033 List
Collection: A collection of data.
is different from the array:
1. Data types can be different
2, the length can exceed 10
Implementing subclasses:
ArrayList
ArrayList () constructs an array of length 10
LinkedList
All of the above are for implementing the list interface;
The underlying implementation is different: An array of one link
Vector vectors
034 aggregate function set
Set interface: Does not contain a repeating function
Sub-class: TreeSet. The bottom layer is realized by binary tree
HashSet. The underlying is implemented by a hash table
TreeSet
There is no get method that needs to be converted into an iterator iterate iterator;
The difference: TreeSet is orderly
Set set automatic sorting
035 aggregate Function Map
A collection of mappings for key and value
Api-java.util.map
To map a key to a property of a value
Sub-class
TreeMap
Order of
HashMap
Traversal with Get method: Output value by key value
Hashtab
Controlling risk
036 Risky code-exceptions
* * In arithmetic operation, the divisor cannot be 0;
System. Out.println (5/0);
* * Array subscript out of bounds
Int[] X=new int[]{1,2,3};
for (int i=0;i<=3;i++) {}
* * NULL pointer exception
int x;
System.out,println (Test1.x.length ());
* * Catching and Handling exceptions
try{//monitoring may occur exception code
}catch () {
}
For example:
Try{}catch (NullPointerException e) {
Catch block
}
A try can be followed by multiple catch blocks, try to listen for exception Code,catch catch exception code
Exception Class-java.lang Package
Parent class for all exception classes
Inherited the Throwable.
* * NULL pointer: Call Empty Object
Subclass: RuntimeException Run exception
Exception
RuntimeException
NullPointerException
Indexoutexception
**try block in the code does not occur when the exception, do not walk the catch block, directly end
037 Finally block
Code location: Following the catch block;
Principle: The statement that must be executed. Whether or not the try/catch is abnormal
* * Close a Connection object
Problem: After Eclipse created the project, there is no src file?
Window-preferences-java-build path, you can choose Folders.
Java language Basics, learning notes