Yang Qiqu 201771010134 "Object-oriented Programming Java" Second week study summary

Source: Internet
Author: User
Tags arithmetic operators logical operators

Chapter III Java BASIC program design structure

Part I: (Theoretical knowledge part)

This chapter mainly studies: Basic content, data types, variables, operators, type conversions, strings, input and output, control flow, large values, and arrays.

1. Basic Concepts:

1) Identifier: Consists of letters, underscores, dollar signs , numbers, Chinese characters, and the first symbol cannot be a number. Identifiers can be used as: class name , variable name, method name, array name, file name, etc.

2) Keywords: keywords are some words in the Java language that have been given a certain meaning. Eg:class, public, void and so on. Note: keywords do not make variable names

3) Three ways to annotate :

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 documents.

2. Data type:

Java is a strongly typed language. This means that each variable must declare one as a type.
? There are 8 basic types of Java
– the integer type (int, short, long,byte)does not have a unsigned type in Java.
– Floating-point type (float, double)
– Boolean Type ( Boolean) in Java, Boolean values and integers cannot be converted to each other. Only a true, false two value.

– Character type (char) English quotation mark Java with Unicode character encoding set

1) Constants

2) Variables: define; Assign values at the same time

(3) Character set: Java uses a Unicode character encoding set, which is 16 bits and contains 65,536 characters.

(4) Escape character:

3. Variables

? 1) Declaring variables: In Java, each variable belongs to a type. When declaring a variable, the type that the variable belongs to precedes the variable name, and one row can declare multiple variables: such as; –int Vacationdays;–int i,j;

2) Variable initialization: After a variable declaration, it must be explicitly initialized with an assignment statement-never use the value of an uninitialized variable. In Java, you cannot declare two variables of the same name within the same scope. Once a variable is declared, it must be explicitly initialized with an assignment statement.

4. Operators (related to object-oriented operations):

1) Various operators: arithmetic operators; increment and decrement operators; relational operators; logical operators;

2) Precedence and binding of operators:

Precedence-Operator associativity
1 []. () (method call) from left to right
2! ~ + +--+ (unary) – (unary) () (Forced type conversion) New right-to-left
3 */% from left to right
4 +-From left to right
5 << >> (arithmetic right shift) >>> (logical right Shift) left to right
6 < <= > >= instanceof from left to right
7 = = = From left to right
8 & from left to right
9 ^ from left to right
10 | From left to right
&& from left to right
12 | | From left to right
13.: Right to Left
+ = = *=/=%= &= |= ^= <<= >>= >>>= right to left

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 (long byte to short byte conversion):

1) 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.

2) Forced type conversion

6. String

string: Immutable string

Basic Operation : (a) obtaining substrings of a string;

(b) String connection (+);

(c) Gets the length of the string;

(d) Detecting whether strings are equal;

(5) string retrieval;

Gets 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 functions.

StringBuilder: Build string StringBuilder that allows changes and changes.

7. Input and output:

1) Read input: When entering through 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.
? 2) Formatted output: You need to construct a PrintWriter object, in the constructor, just provide the file name.
? 3) file input and output: you need to construct a scanner object with a file object.

8. Control Flow: If, switch, for, while, Do-while.

Circular statements are divided into three types: while; do-while;for

Some notes:
? The value of the expression value, the constant I, is an integer and cannot be a string.
? Constant I! = constant J
? Execution: Evaluates the expression first, and if it is the same as the constant I, the statement sequence I is executed, and if it is not the same, the statement sequence n+1 is executed.
? Note the break!! after the case clause

9. Large values
? If the basic integer and floating-point data do not meet the required precision, then you can use the two classes in the Java.math package, BigInteger and BigDecimal. These two classes can manipulate arbitrary long numbers.
? The BigInteger class realizes the integer operation of arbitrary precision, and BigDecimal realizes the floating-point operation with arbitrary precision.

10. Array: The element is determined by the array name and its subscript implementation, such as A[0] represents the first element of array A, a[1] represents the second element of array A, and so on.
1)statement:
? One-dimensional array format:
Array element type array name [];
array element type [] array name;//Recommended Use
? Two-dimensional array format:
Array element type array name [];
array element type [] array name;//Recommended Use
Where the array element type can be any type in Java, including the base type and the composite type.

2) Create: format as follows: Array name =new array element type [number]

3) Initialization

Part II: (Experimental part)

1 , experimental purposes and requirements

(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 , experimental content and procedures

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)

Experimental code and debugging results such as:

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;

Experimental code and debugging results such as:

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.

Experimental code and debugging results such as:

Experiment 4: run the following program in command-line mode to understand the use of Java Application command-line parameters.

1  Public classMessage2 {  3  Public Static voidMain (string[] args)4   {     5   if(Args[0].equals ("-h ")) System.out.print ("Hello");6     Else if(Args[0].equals ("-g "); System.out.print ("Goodbye,");7    for(inti=1;i<args.length;i++)8System.out.print ("" +args[i]);9SYSTEM.OUT.PRINTLN ("!");Ten   } One}

Debug the results using the command line method as

Lab 5: In the Eclipse Environment, import the 3rd chapter of the sample program Inputtest.java steps:

(1) New Java project such as:

(1) 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.

(1) 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.

(2) 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.

Example code:

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.

1 ImportJava.io.File;2 Importjava.io.FileNotFoundException;3 ImportJava.io.PrintWriter;4 ImportJava.util.Scanner;5 Importjava.util.Arrays;6 7  Public classWritereadfiletest {8 9     /**Ten      * @paramargs One      * @throwsFileNotFoundException A      */ -      Public Static voidMain (string[] args)throwsFileNotFoundException { -  the         //Write file Demo -PrintWriter out =NewPrintWriter ("MyFile.txt"); -Out.println ("Name high Java data structure average total score"); -Out.println ("Zhang 320 30 40 0 0"); +Out.println ("Li 450 60 70 0 0"); -Out.close ();//Remember, the output is complete and requires close +          A          at         //read-in file demo -Scanner in =NewScanner (NewFile ("MyFile.txt"));//create a scanner in for myfile.txt this file -         intNumber = 1;//Line number -          while(In.hasnextline ()) {//determines whether the next line of the scanner is not read, and the loop reads each line of the file -String line = In.nextline ();//read out the next line of MyFile.txt -System.out.println ("+" + (number++) + "contents of line" + "=" +Line ); in              -Scanner Linescanner =NewScanner (line);//Create a scanner for the contents of each row toLinescanner.usedelimiter ("");//use spaces as separators +String name =Linescanner.next (); -String math =Linescanner.next (); theString java =Linescanner.next (); *String ds =Linescanner.next (); $String avg =Linescanner.next ();Panax NotoginsengString total =Linescanner.next (); -System.out.println ("name=" +name+ "math=" +math+ "java=" +java+ "ds=" +ds+ "avg" +avg+ "total=" +Total ); the         } +In.close ();//The read-in is complete, and you need to close it finally.  A  the  } +}

Follow the above steps to import the run as follows:

Lab 7: follow The procedure of Experiment 5, import the 3rd Chapter sample program, each sample program summarizes the learning content from two angles of syntax and algorithm.

(1) test Retirement.java,retirement2.java,Lotteryodds.java master the loop control structure;

1)

2)

3)

(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

Through this week's study, learned some basic Java content, recognized that its language is really very similar to C language, after learning C language is easy to understand some of the content, in the process of doing experiments on the theoretical knowledge part has a deeper understanding and experience. The language of each experiment deserves careful experience and pondering, especially in experiment 7, through the test Retirement.java,retirement2.java,Lotteryodds.java and other sample programs basic understanding In addition to the use of the loop control structure, the use of large numeric classes, the use of arrays, the use of multidimensional arrays and irregular arrays, the import and export of files is also familiar through several experiments. But with the deepening of learning, but also let me find more questions and doubts, I think I still need more time to ponder the language!

Yang Qiqu 201771010134 "Object-oriented Programming Java" Second week study summary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.