First, the Java development platform
Javase standard Java application Application Gobang, calculator, QQ
Java EE Enterprise Linux Enterprise application
Javame Mini-Device Android replaces
Second, Java terminology
JDK Java Development Kit
JRE Java Runtime Environment
JVM Java Virtual machine
GC Java Memory object garbage collection mechanism automatic lazy lazy recovery
API application programming interface corresponding to Javadoc documentation
Java.lang.string class String Class
Java.lang.System class System Class
IDE Integrated Development Environment MyEclipse8.5 (the higher the version, the more memory)
Third, Java programming steps
1. Download and install the JDK
2. Configure the system environment variables
Installation path for Java_home JDK
Search path of the path command javac java command
Search path for the CLASSPATH class
Can be used repeatedly on the command line after configuration (only configuration in sequence.
3. Editing
4. Compile Javac hello.java->hello.class start compiler
5. Run Java Hello to start the virtual machine
Iv. Java Annotations Comment
Code and Documentation (note) are equally important
1) Single-line comment//
2) Multi-line Comment/* * *
3) Document Comment/** */
V. variables
Variable name corresponds to the value of the variable, with the data type
Declaring a variable for the first time must explicitly specify the data type
String name = "Zhang San Fung";
Name = "Zhang San";
int high = 180;
High= 190;
Project, describe the project size: 30 people/month
30 people * 1 months
1 People *30 Month
5 people *6 Month
On average no one writes 10 classes a day, one months and 20 days;
Altogether: 5*10*20*6=6000 class *.class
Use of MyEclipse
Java Package Keyword Packages
1, meaning:
Package is like the usual directory, a layer of packages corresponding to a layer of directory structure, the benefits of subcontracting: the ability to classify. Class management.
Create a new text document under D:\
2. Grammar
Valid position in the first line of the source code:
Package name;
Specification of package name: All lowercase, used between multiple packages. Separated
Once you have a package name for your class, you need to use the full name (fully qualified name) package name. Class Name
Package day01;
The package hierarchy in the project is deep:
Package company domain name. The name of the project. Module name. sub-module name;
Example 1, Souhu Java first day of code: Package Com.sohu.javase.day01;//com.sohu is the domain name
Code for the next day: Package com.sohu.javase.day02;
Package com.sohu.javase.day01;
Class hello{//classes name Com.sohu.javase.day01.Hello
}
Example 2, IBM Company, employee Management system EMS, employee class EMP
Package com.ibm.ems.entity;//Entity Pack
Class emp{//classes name is COM.IBM.EMS.ENTITY.EMP
}
Example 3, Www.bypp.com.cms
Package com.bypp.cms.entity;
Class duck{
}
Example 4,
The declaration of a package can only be in the first row of the source code valid location
Package day01;
public class hello{
public static void Main (string[] args) {
System.out.println ("Hello");
}
}
Compile: D:\ javac-d. Hello.java
-D has two meanings:
1) make the compiled. The path to the class file. Current directory
2) If we specify a package, the level of the package will be automatically generated with the corresponding directory results
Running: Java Com.day01.Hello
Implementing Myinfo.java with MyEclipse
Tips for using the IDE:
1) Select Workspace
2) New Java Engineering (Java Project Java projects)
In the table of contents are:
SRC directory sourse source code file directory *.java
Bin directory binary byte-code file directory *.class
3) Create a new class under SRC
Click: File->new, class;
Package Name: DAY01;
Class Name: Hello
4) Edit Font
5) Finish editing
6) Compile save immediately compile Ctrl + s
If the compilation passes, there is no red underline;
If the compilation error occurs, the red underline appears;
Syntax error, insert ";" To complete blockstatements
7) Run
Right-click Java Application, Run as, source code
Note: ALT +/Quick prompt and generate fixed code
Main Master method
SYSO system output
Second, identifier identifier
Identifiers are used to represent the various names of code: package Name, class name, method name, variable name, constant name, and so on.
1, the identifier rules 5 must abide by, or compile error;
(1) must consist of letters, numbers, underscores, &, the first letter cannot be a number;
Letter: A-Z to 52;
Number: 0-9 10;
(2) cannot be a Java keyword; 50 + 3 self-par value
Keyword Features: all lowercase class, int, double, static, public ...
Literal value: True, False, NULL
(3) Case sensitivity (case sensitive)
String vs. string, int and int
(4) No limit on length
ArrayIndexOutOfBoundsException
(5) Support Chinese, but not recommended
int age = 23;
Problem:
2. Specification of identifiers 5 business habits
(1) class name, interface name each word the first letter name ;
(2) variable name, method name each word first letter lowercase , followed by the first letter of each word capitalized ;
(3) package name all lowercase , between package names. Separated
(4) The constants are all capitalized , the words are separated by _;
(5) See the meaning of the name
Name N1
Age A1
Arrayindexoutofboundexception Array decimal Bounds exception
Third, the Java keyword key words
Different features are represented in the language, all lowercase.
Exercise: Prompt from the console and enter name and age, and output
Package Name: Day02, class Name: Testtestscanner provides the Main method
Need to use a class: Java.util.scaner class, Scanner class
Java.util Package Kit Utilits (tool)
Created an object for the scanner class SC
Scanner SC = new scanner (system.in);
String name = Sc.next (); Enter string data to invoke the next () method of the Scanner object
Features: is a blocking method, waiting for the user's input, know that the user entered the data, the results returned before continuing to execute
Specific steps:
1, create the object of scanning class;
2, print "Please enter the name";
3, input anme;
4. Print "Please enter Age";
5, enter age;
6. Print out name and age;
Attention:
Using scanner, import statements are required
The import statement is used to declare the package under which the class is used.
The following do not have to write the import statement:
1) The class under the same package does not need import direct use;
2) The class under the Java.lang package does not need to be directly used by import;
3) Lang Packet Language language pack is too common, m default direct use
For example: Java.lang.String class, String class
Java.lang.System class, System class
Java.lang.Math class, Arithmetic class
Note: Import java.util.*; indicates that all classes under the Java.util package can be used, but not child packages (just one layer)
* is a wildcard, the proposed project requires a specific class name, high efficiency
The JDK provides a rich range of APIs (classes and interfaces) that are rich in functionality and are managed through different packages:
Java.lang.String class, String class
Java.lang.System class, System class
Java.lang.Math class, Arithmetic class
Java.util.Scanner class Scan Class
Corresponds to a document: Javadoc document/API document, is an HTML page format document.
Iv. data Types for Java
1, computer expression number: binary, every two into one, can represent 2^4=16 species,
2. Java representation number: positive, negative, and 0
The complement of the binary number is new, using the highest bit as the sign bit (leftmost)--0 is positive, 1 is negative
Positive complement: Is the original code, negative complement: the corresponding positive number of the original code, according to the position counter +1;
4-bit twos complement: capable of representing 2^4=16 species, indicating number ranges: -8-7,-2^3-2^3-1
8-bit twos complement: can represent 2^8=256 species, indicating number range: -128-127,-2^7-2^7-1;
01111111--127 1+2+4+8+16+32+64=127
......
00000000--0
11111111--( -1) 00000000+1=00000001-> 1->-1
......
10000000 ——-128
1) Known 8-bit binary complement 11111111, translated into decimal number, because the highest bit is 1, negative number, (bitwise negation + 1)
Example: 11111111 translated into decimal number, 00000000 + 1-> 00000001-> 1->-1;
2) Known decimal number-1 is converted to the complement of 8-bit binary number: (1 of the original code bitwise INVERSE + 1)
bitwise inversion with 1 binary digits + 1:00000001-> 11111110 + 1-> 11111111 (-1 complement)
4. Characteristics of Java data types
Java is a strongly typed language that declares a variable for the first time, must explicitly specify the data type, declares the variable for the first time, and must explicitly specify the data type.
Java syntax is more rigorous, secure, and prescriptive.
String name = "Tli"; String literals
Name = "Lili";
name = 123; Integer numeric value, type incompatible, compilation cannot pass
JavaScript is a weakly typed language:
var n1 = "Tli";
N1 = 123;
5. Classification of Java data Types (important)
(1) basic type , also known as simple type, native type (prime) 8 kinds
byte short int long char float double Boolean
Byte short integer integer Long integer character single-precision floating-point double-precision floating-point Boolean
Capable of representing data: byte short int long char float double;
Capable of representing integers: byte short int long char;
Ability to represent decimals: float double;
Capable of representing Boolean: Boolean (True, false);
Ability to represent characters: char;
Commonly used: int long double char Boolean;
Underlying storage: in bytes byte as unit, press bits to store.
(2) A reference data type, also known as a complex type, an object type of countless kinds, class can be continuously defined
Underlying storage: Reference (object memory address)--memory object (key-room--Thing)
It is divided into 5 types according to the form of expression:
Classes class Interface interface array string[]/int[] Enum callout
(3)void no return value type
Note: You cannot use a variable to define it, only the return value type of the method, which means that no results are returned.
public static void Main (string[] args) {...}
public void PlayGame () {...}
Exercises: Write Java program: Testempscanner.java
Prompt from the console and enter basic information about the employee and output all information at once in the console.
Name of employee, employee age, employee salary salary
Tip: You need to use the scanner class Java.util.Scanner
Thinking: The thought of process-oriented programming
Steps:
1. Creating the Scanner Object SC
2. Prompt and enter name
Main outline: Java programming steps
1, the command line development method
(1) Editing Java source program Hello.java
Plain text editor, such as Notepad, EditPlus, etc.
Package day01;
public class hello{}
(2) Compile javac-d. Hello.java
-->\day01\hello.class
(3) Run Java day01. Hello
2. Using IDE MyEclipse to improve development efficiency
(1) Edit
New class
(2) compiling
(3) Right-click the source code run As->java application
Second, Java annotations
Iii. identifiers: For JDK or programmer to name features in code
1 bytes = 82 binary 1byte = 8bit
Iv. keyword key words
Keywords all lowercase, indicating different functions
V. Java data types
In real life, the number of decimal digits; the number of binary digits in the computer; 16 binary, octal number is for the programmer more convenient to represent the binary number; Java uses the complement form of the binary number (the positive complement is the original code, negative number of the original code is the original code of its positive numbers to reverse + 1)
-5 of 8 is binary complement: 0000 0101-> 1111 1010 +1 = 1111 1011
MyEclipse Java Basics Using notes