The road of embedded system depends on daily drip
--- Ajie sends code online
catalogue
Differences between javase, EE and me
Simple analogy with previous learning
2, Programming practice: from C to process oriented
Variable definition and output
Selection control flow (exactly like C language)
Loop control (exactly like C language)
Definition and traversal of array
Call of method (function): use of analogy c language structure
1, Conceptual literacy
Differences between javase, EE and me
Specific differences
Java SE(Java Standard Edition)
SE (Standard Version) is mainly used for desktop programs and console development (JFC)
Java EE(Java Enterprise Edition)
EE (Enterprise Edition) enterprise level development (JSP,EJB): website development and programming based on b/s mode
Java ME(Java Mobile Edition)
ME (mini version) embedded development (mobile phone, small appliances): mobile phone software game programming
Simple analogy with previous learning
SE is like the first stage, C language, which is the foundation.
EE is like the second phase, FTP cloud disk project, mainly Web Services
ME is like the third stage, the development of ARM devices. Mainly electronic products and embedded equipment
JRE
The Java Runtime Environment (JRE) is a software that allows a computer system to run Java applications. There is a Java Virtual Machine (JVM) and some standard class libraries in JRE.
The reason why java is cross platform is because there is JRE, so long as there is JRE, java can run.
JDK
JDK(Java Development ToolKit) is a java language development toolkit. JDK is the core of the whole Java, including the Java runtime environment, a bunch of java tools (javac/java/jdb, etc.) and java basic class libraries (that is, Java API s include rt.jar).
Without JDK, you cannot compile java programs (refer to java source code. java files). If you want to run only java programs (refer to class or jar or other archive files), make sure that the corresponding JRE is installed.
Start with these simple things to understand java. It's enough to write down the examples that the teacher told in class. They are all very simple.
2, Programming practice: from C to process oriented
main + Alt + /: you can get the following main function framework:
public static void main(String[] args) {
}
Variable definition and output
public class test { public static void main(String[] args) { System.out.println("hello world");//ln is a print with a carriage return symbol //= System.out.print("hello world\n"); int a; //This is how variables are defined a = 10; int b; b = 20; System.out.println("a="+a); System.out.println("b="+b); int c = a + b; System.out.println("c="+c); System.out.println("a="+a + " b="+b + " c="+c); //In C language: printf ("% d +% d =% d", a, B, c); System.out.println(a +"+"+ b +"="+ c); float f = (float) 0.1; //In this environment, decimals are all recognized as double types, and you are not assigned a value to float, so you need to cast double d = 0.2; System.out.println("f="+f); System.out.println("d="+d); } }
Operation results:
hello world
a=10
b=20
c=30
a=10 b=20 c=30
10+20=30
f=0.1
d=0.2
syso + Alt + /: System.out.println();
Selection control flow (exactly like C language)
public class test { public static void main(String[] args) { int a = 1; if(a > 0){ System.out.println("It is a positive integer"); if(a == 1){ System.out.println("It's a positive integer. It's 1"); }else{ System.out.println("It is a positive integer, not 1"); } }else{ System.out.println("a Is a non positive integer"); } switch(a) { case 1: System.out.println("This is 1"); break; case 2: System.out.println("This is 2"); break; default: System.out.println("Not 1, not 2"); break; } } }
Operation results:
It is a positive integer
It's a positive integer. It's 1
This is 1
Loop control (exactly like C language)
public class test { public static void main(String[] args) { int i; for(i=0;i<20;i++){ System.out.println("Ajie online delivery code"); } while(i>0){ System.out.println("Ajie sent the code online again"); i--; } } }
Definition and traversal of array
public class array { public static void main(String[] args) { //Initialization when defined //int[] score = {1,2,3};// Case is not allowed when defining //Open up space and wait for input int[] num = new int[3]; //Do not specify int num [] //int []a = null;// Null in Java is lowercase //a = new int[3]; int i; //Array traversal also uses subscripts for (i=0;i<num.length;i++){ //No more sizeof(num)/sizeof(num[0]), which is the charm of object-oriented num[i] = i; } for(i=0;i<num.length;i++){ System.out.println(num[i]); } } }
Operation results:
1
2
4
0
1
2
array.length is like sizeof(array)/sizeof(int) in our C language
Call of method (function): use of analogy c language structure
(functions are called methods in JAVA)
/* * How to call when declaring a method without adding static * Similar to the following C language structure function pointer call struct Student{ int score; int age; void (*myPrintf)(); }; int main() { struct Student stu1; stu1.myPrintf(); } */ public class test { //When you declare a method, you will not report an error without adding static. But in this case, you will report an error when calling directly (so this direct call needs to be declared with static) static void myPrintf() { System.out.println("Ajie online delivery code"); } static void putInt(int a) { System.out.println("Output a number:"+a); } //When declaring a method, without adding static void addB(int b) { b = b + 1; System.out.println("b++The value of is"+b); } public static void main(String[] args) { //When you declare a method, you will not report an error without adding static. But in this case, you will report an error when calling directly (so this direct call needs to be declared with static) myPrintf(); putInt(100); //How to call when declaring a method without adding static test t = new test(); t.addB(5); } }
Operation results:
Ajie online delivery code
Output a number: 100
The value of b + + is 6
Input data: Scanner
import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //This is a class, which can be understood as the structure in C. There are implemented functions in the class for you to call //The structure must define a variable to open up a space for browsing from the input of the system //scanner doesn't know because there is no package //If it is not imported, enter the package by ctrl+shift+o (the package is placed in the system) int a; String str; float f; double d; System.out.println("Please enter an integer"); a = sc.nextInt(); System.out.println("Please enter a string"); sc.nextLine(); //The carriage return above should be absorbed, otherwise str = carriage return, directly jump to the input floating point number str = sc.nextLine(); System.out.println("Please enter a floating point number"); //sc.nextLine(); Then why don't you absorb the car here? f = sc.nextFloat(); System.out.println("Please enter another decimal"); d = sc.nextDouble(); //There is no need to absorb the carriage returns from above. Do you only need to absorb the first carriage return? System.out.println("a="+a); System.out.println("str="+str); System.out.println("f="+f); System.out.println("d="+d); } }
Operation results:
Please enter an integer
5
Please enter a string
ajie
Please enter a floating point number
3.5
Please enter another decimal
3.5
a=5
str=ajie
f=3.5
d=3.5