Object-oriented programming ( Java ) "First week of study summary
Part I: Course preparation section
Part II: Theoretical Knowledge Learning Section
Chapter III Java BASIC program design structure
1. Basic knowledge
(1) Identifiers
Identifiers consist of letters, underscores, dollar signs, and numbers, and the first symbol cannot be a number.
(2) Keywords
Keywords are some of the words in the Java language that have been given a specific meaning. Keyword does not make a variable name.
(3) Notes
Note the contents from/to the end of this line.
/* and/* Define a comment block.
/** Start, */end this annotation method can be used to automatically generate documents.
2. Data type
There are 8 basic types of Java:
-Integer type (int,short,long,byte)
-Floating-point type (float,double)
-character type (char)
-Boolean type (Boolean)
3. Variables
In Java, each variable belongs to a type. When declaring a variable, the type to which the variable belongs is before the variable name.
–double salary;
–int vacationdays;
–long earthpopulation;
–boolean done;
In Java, a row can declare multiple variables. Declaring each variable individually can improve the readability of the program.
–int I,j;//both is INTEGERSL
Variable initialization
Once a variable is declared, it must be explicitly initialized with an assignment statement-never use the value of an uninitialized variable.
In Java, you can make variable declarations anywhere in your code.
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, you cannot declare two variables of the same name within the same scope.
4. Operators
Java provides two special operators: New (Create Object), Instanceof (returns a Boolean value that indicates whether an object is a specific class or an instance of its subclass).
5. Type conversion
Implicit type conversions: Most numeric conversions are done automatically by following the precedence relationship. The conversion principle is as follows: if one of the two operands is of type double, the other is converted to a double type. float, long type. Otherwise, the two operands are converted to the int type.
6. String
String: Immutable string
(a) String connection of String class (+) when a string and a non-string are concatenated, the latter is converted to a string.
(b) The Equals method can be used to detect the equality of two strings.
You cannot use = = to detect whether two strings are equal, it can only determine whether two strings are placed in the same position.
(c) Get the string representation of the object: All classes are specified considered to be subclasses or indirect subclasses of the object class in the Java.lang package----kindred ancestry, and all classes can enjoy some basic functionality.
StringBuilder: Build string that allows changes and changes StringBuilder
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. The scanner class is defined in the Java.util package, so it is necessary to load the corresponding package in.
(b) To read a file, you need to construct a scanner object with the Files object. Eg:–scanner in = new Scanner (New File ("MyFile.txt"))
(c) To write to a file, you need to construct a PrintWriter object, in the constructor, simply provide the file name: –printwriterout = new PrintWriter ("MyFile.txt")
8. Control process
9. Big Data
10. Arrays
Part III: Experimental part
- Experiment name: Experiment two Java Basic program design (1)
2. Purpose 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.
3. Experimental Steps and Contents:
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) |
Open the Eclipse software, write the program according to the above requirements and run the following results:
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; |
Open the Eclipse software, write the program according to the above requirements and run the following results:
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.
According to the above requirements, the experiment 3 of the program to do the following changes, the operation 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 ("!"); } } |
Write the complete program in Notepad as required above and save it in the new Java document named Message.java in the D drive.
Enter the Win+r key on the keyboard, and then click the step input in the input box to obtain the following results:
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.
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.
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;
(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) Testing Lotteryarray.java, mastering the use of irregular arrays
4. Experiment Summary:
Through this experiment, I was more familiar with the basic steps of Java Program development under the command line and IDE two ways, and mastered the process of importing Java source program in Eclipse integrated development environment and the Java language Construction Basic program data type, variables, operators, various expressions, input and output, The basic syntax of process control, as well as the use of the string class, the StringBuilder class, the array class.
Yang Ling 201771010133 "object-oriented Programming (Java)" Second week study summary