King Tai 201771010131 "object-oriented programming ( Java ) The second week of study summary
Part I: Theoretical Knowledge learning Section
Chapter III
The main content of the third chapter is the basic syntax of Java language, the main contents are as follows
1. Basic knowledge
1.1 Identifiers
A) identifiers can be used as class names, variable names, method names, array names, file names, and so on.
Note: The first symbol cannot be a number, that is, you cannot start with a number.
1.2 Key Words
A) keywords are words that have been given a particular meaning in the Java language.
b) Common: class, public, try, catch, if, float, import, void, and so on.
Note: keyword does not make variable name
1.3 Notes
A)//comment content from//until the end of this line.
b)/* and/* Define a comment block.
c)/** Start, */end this annotation method can be used to automatically generate the document.
2. Data type
A) each variable in Java must declare the type of the variable before it is used
b) large to divide into four types, refinement there are eight types, namely: integer type (int, short, long, byte) floating-point type (float, double) character type (char) Boolean type (Boolean)
c) The Boolean and byte types in Java are not in the C language.
D) It is worth mentioning that the encoding type of Java is not the ANSI code used in C, but the Unicode code. Unicode (Uniform Code, Universal Code) is an encoding specification that meets the requirements of cross-language, cross-platform text conversion and processing.
Note: There is no unsigned type in Java;
Boolean and integer cannot be converted to and from one another in Java
3. Variables
A) in Java, each variable belongs to a type. When declaring a variable, the variable belongs to the type before the variable name.
b) A row can declare multiple variables, but this is not recommended. Declaring each variable individually can improve the readability of the program.
Note: After a variable declaration, it must be explicitly initialized by an assignment statement;
The declaration of a variable is as close as possible to the place where the variable was first used, which is a good program writing style.
In Java, two variables with the same name cannot be declared within the same scope.
3.1 Constants
A) in Java, use the keyword final to indicate constants. General constant names are capitalized. Such as: Final double cm_per_inch=2.54;
b) The keyword final indicates that a value can only be assigned once, and its value cannot be changed once it is set.
c) in Java, you often want a constant to be used in more than one method in a class, and we call these constants class constants. You can declare a class constant by using the keyword Staticfinal (class constants).
4. Operators
A) in Java, various operators are related to object-oriented
b) Java provides two special operators
–new This is an operator that is used to create an object.
–instance of Returns a Boolean value that indicates whether an object is a specific class or an instance of its subclass.
c) Precedence of the operator
d) Mathematical functions are included in the math class. The power function, the trigonometric functions, the exponential function and its inverse function, etc. Java also provide two constants. Math.PI MATH.E
5. Type conversion
A
b) Coercion type conversion
One of the two operands is of type double, and the other is converted to a double type.? One of two operands is of type float and the other is converted to float type.
One of the two operands is of type long and the other is converted to a long type.
Otherwise, the two operands are converted to the int type.
6. String
A) in Java, strings are treated as objects.
b) The strings that need to be used in the program can be divided into two main categories:
Immutable strings that are not modified and changed after the creation of the string class
Build string StringBuilder class that allows changes and changes after creation
c) Use "" to define the string
7. Input and output
A) when entering via the console, a scanner object needs to be constructed and associated with the "standard input stream" system.in.
b) using System.out.print (x) to output the value x to the console, this command will print output x as the maximum number of non-0 digits allowed by the data type of x.
8. Control process
9. Large values
A) if the basic integer and floating-point data do not meet the required precision, you can use the two classes in the Java.math package, BigInteger and BigDecimal.
b) These two classes can manipulate arbitrary long numbers
The BigInteger class implements an integer operation with arbitrary precision
BigDecimal enables floating-point arithmetic with arbitrary precision
10. Arrays
A) An array is a data structure that is a collection of ordered data, with the same data type for each element in the array.
B) The determination of an element is implemented by the array name and its subscript, such as A[0], which represents the first element of array A, a[1] represents the second element of array A, and so on.
Part II: Experimental part
Experiment two Java Basic program design (1)
Experimental Time 2018-9-6
1, the purpose and requirements of the experiment
(1) Further familiar with the basic steps of Java Program Development in command line and IDE two ways;
(2) Mastering the process of importing Java source program under Eclipse integrated development environment;
(3) Mastering the basic Grammar of the basic program of Java language construction, such as data type, variables, operators, various expressions, input and output, and process control;
(4) Mastering the use of the string class, the StringBuilder class, and the array class.
2. Experiment contents and steps
Experiment 1: write the Java application and output the values of the following 4 expressions.
int i=1; Double d=1.0; (1) 45+45*50%i-- (2) 1.5*3+d++ (3) (true) && (3>4) (4) (i>0) | | (i<0) |
The specific code of the experiment is as follows:
1 Packagetest1;2 3 Public classTest0 {4 5 Public Static voidMain (string[] args) {6 intI=1;7 Doubled=1.0;8System.out.println (45+45*50%i--);9System.out.println (1.5*3+d++);TenSystem.out.println ((true) && (3>4)); OneSystem.out.println ((i>0) | | (i<0)); A - - } the -}
The experimental results are as follows:
Experiment 2: Write a Java application that contains the following code fragment, outputting the value of the String class object S3.
String s1= "hello!"; String s2= "World"; String s3=s1+s2; |
The specific code of the experiment is as follows:
1 Packagetest1;2 3 Public classtest4 {4 5 Public Static voidMain (string[] args) {6String S1 = "Hello";7String s2 = "world!";8String s3 = S1 +S2;9 System.out.println (S3);Ten One } A -}
The experimental results are as follows
Experiment 3: change experiment 2 s1, S2, S3 as StringBuilder class object, observe the program running results and compare with experiment 2 results, understand the difference between the string class object and the StringBuilder class object.
The specific code of the experiment is as follows:
1 Packagetest1;2 3 Public classtest4 {4 5 Public Static voidMain (string[] args) {6StringBuilder S1 =NewStringBuilder ("Hello");7StringBuilder s2 =NewStringBuilder ("world!");8S1.append (S2);//call the Appand method to append the S2 to the S1, and the S1 will be expanded9 System.out.println (S1);Ten One } A -}
The experimental results are as follows:
Experiment 4: run the following program in command-line mode to understand the use of Java Application command-line parameters.
public class Message { public static void Main (string[] args) { if (Args[0].equals ("-H")) System.out.print ("Hello"); else if (args[0].equals ("-G"); System.out.print ("Goodbye,"); for (int i=1;i<args.length;i++) System.out.print ("+args[i"); SYSTEM.OUT.PRINTLN ("!"); } } |
The results of the experiment are as follows:
Lab 5: In the Eclipse Environment, import the 3rd chapter of the sample program Inputtest.java steps:
(1) New Java project such as:
(2) Select File->import->file ystem->next, open the File import window such as, click on the above browse select Import source program and select, click on the below browse to select the source program import location for the new project inputtest/ SRC location, click Finish to complete the import.
(3) Open the default package of the Inputtest Project Src folder, and double-click Inputtest.java to open the file in the IDE's source program editing area.
(4) Right-click on the Inputtest.java file name to open the shortcut menu, choose Run As->java application running the program, in conjunction with the program run results, understand the code scanner class object usage, master the Java console input method.
The results of the program run as follows:
Experiment 6: Follow the procedure of Experiment 5, Import Writereadfiletest.java sample program, understand program code with program running result, observe the contents of file MyFile.txt under project folder, master the input and output operation of file.
The results of the program run as follows:
MyFile.txt content is as follows:
Experiment 7: Follow the procedure of Experiment 5, import the 3rd Chapter sample program, each sample program summarizes the learning content from the syntax and algorithm two angles.
(1) test Retirement.java,retirement2.java,lotteryodds.java to master the cyclic control structure;
Retirement.java test results are as follows
The Retirement2.java test procedure is as follows
The Lotteryodds.java test procedure is as follows
(2) test Bigintegertest.java, master the use of large numerical classes;
(3) test Lotterydrawing.java, master the use of arrays;
(4) test Compoundinterest.java, master the use of multidimensional arrays;
(5) Test Lotteryarray.java, master the use of irregular arrays.
Part III: Experimental summary
The third chapter is the basic knowledge of Java grammar, as the teacher said, 80% or 90% of the content is the same as we have learned the basic C language grammar, so for us already have a C Foundation, learning this chapter content is not as hard as the computer language. So through the study of this chapter, the equivalent of reviewing the C language of the basic grammar. Because of the basis of C language, this chapter is not so difficult to learn. In this chapter of learning, I learned to use Java operators to construct a variety of expressions, mastered the Java Process Control technology, but the use of string and array classes are somewhat deficient, but in the spare time I will do my best to learn and digest this part of the content. Through the teacher class for us to comb the knowledge of the context, and after the lesson of their own reading on the machine learning, successfully completed the second experiment content. Although a lot of bugs appeared in the experiment, but the teacher's tips and help the teaching of a successful debug. And in this week the teacher transition class, gradually adapted to the class mode.
Through this week's study, I more understand the importance of learning in practice, for example, in the experiment four in the command of the debugging program, must read the program to correctly debug the results, and if only theoretical learning, to my level can not see the array of cross-border problems, but the appropriate parameters to enter the normal operation. This is also a question that the TA has repeatedly suggested. I think in this week I learned much more than last week's study content, and in the next time I will continue to study hard, improve their programming level.
King Tai 201771010131 "object-oriented Programming (Java)" Second week study summary