20177100106 Dongwen "Object-oriented Programming (Java)"

Source: Internet
Author: User
Tags arithmetic operators bitwise operators float double logical operators mathematical functions java se

20177100106"Object-oriented programming (java)" Second week study summary

Part I: Theoretical Knowledge learning Section

1. Identifiers:

① identifiers consist of letters, underscores, dollar signs, and numbers, and the first symbol cannot be a number.

The ② identifier can be used as: class name, variable name, method name, array name, file name, and so on.

2. Notes:

There are three ways to annotate Java:

①//comment content from//until the end of this line.

②/* and * * Define a comment block.

③/** Start, */end this annotation method can be used to automatically generate the document.

3. Data structure:

(1) Integer type:

① integer constant means: decimal: 123, 6000

Octal: 077, 065

Hex: 0x234, 0XAB12

The data type of the ② integer variable is divided into four types: int short long byte

The range of integers in ③java is independent of the machine running Java code.

There is no unsigned type in ④java.

(2) floating-point type:

There are two kinds of floating-point types in ①java: float double

② of floating-point constants: decimal notation 430.2

Scientific counting 4.302E2

③ represents three special floating-point values for overflow and error: positive infinity

Negative infinity

NaN (non-numeric)

(3) Boolean type:

① constant True, false

The definition of the ② variable is Boolean x; Boolean x, Y;

The ③ definition can also be assigned a Boolean x=true, Y=false;

④ in Java, Boolean values and integers cannot be converted to each other.

4. Initialization of variables:

① A variable declaration, it must be explicitly initialized with an assignment statement-never use the value of an uninitialized variable.

② in Java, variable declarations can be made anywhere in the 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.

5. Various operators:

① arithmetic operators

② increment operator and self-decrement operator

③ Relational operators

④ logical operators

⑤ Bitwise operators

6. Mathematical Functions and constants:

① mathematical functions are included in the math class.

– Power function

– Trigonometric Functions

– Exponential function and its inverse function, etc.

The ②java also provides two constants.

–math.pi

–math.e

③ If you do not want to prefix the math method name with the constant name "math.", you can add the following code at the top of the source file.

–import static java.lang.math.*;

7. Type conversions:

8. String:

The ①java string is a sequence of Unicode characters that is the basic data structure for organizing characters, similar to a character array. ② has a built-in string type, but instead provides a Java predefined class string in the standard Java class library.

In Java, strings are treated as objects.

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;

The build string StringBuilder class is allowed to make changes and changes after creation.

9. String constants:

① uses "" to define the string.

"ABC", "Welcome to Java" are all strings.

②java automatically generates a string class of objects for the strings constants, so you can initialize the string object directly.

such as: String s = "Hello world! ”

Ten. String class

① uses "" to define the string.

"ABC", "Welcome to Java" are all strings.

②java automatically generates a string class of objects for the strings constants, so you can initialize the string object directly.

such as: String s = "Hello world! ”

11. Read input:

When ① is entered through the console, a scanner object needs to be constructed and associated with the standard input stream system.in. –scanner in = new Scanner (system.in);

② because the scanner class input is visible, it does not apply to reading passwords from the console. Java SE 6.0 specifically introduces the console class for this purpose.

12. Formatted output:

① uses System.out.print (x) to output the value x to the console, which prints out x the maximum number of non-0 digits allowed by the data type that corresponds to X.

②java SE 5.0 follows the printf method in the C library function, System.out.printf ().

The conversion character for printf

Flags for printf

Formatted output of date and time in the ③printf method

Date and time of the conversion character

13. File input and output:

① to read a file, you need to construct a scanner object with the Files object.

For example: –scanner in = new Scanner (New File ("MyFile.txt"));

② to write to a file, you need to construct a PrintWriter object, in the constructor, simply provide the file name:

–printwriter out = new PrintWriter ("MyFile.txt");

14. Note the following:

The value of the ① expression value, constant I, is integer and cannot be a string.

② constant I! = constant J

③ execution: Evaluates the expression first, if it is the same as the constant I, then executes the statement sequence I; if it is not the same, the statement sequence n+1 is executed.

④ Note the break!! after the case clause

15. Looping statements:

Circular statements are divided into three types: while

Do-while

For

16. Interrupt Control Flow Statement

①break effect: Ends the execution of the entire loop and goes to the next statement.

②continue effect: End this cycle and start the next cycle.

Note: (1) There is no goto statement in Java!!!

(2) A tagged break statement is provided in Java to jump out of multiple nested loop statements.

17. Return Statement:

The return statement of the ①java is closely related to the Java method, which returns to the previous-level method as soon as the program executes to this statement.

② format: return value;

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

19. Value:

The ① array is a data structure that is a collection of ordered data, with the same data type for each element in the array. ② the determination of an element is implemented by the array name and its subscript,

such as A[0] represents the first element of array A,

A[1] Represents the second element of array A, and so on.

20. Declaration of the array:

① one-dimensional array format: array element type array name []; array element type [] array name;

② two-dimensional array format: array element type array name []; array element type [] [] array name;

③ where the array element type can be any type in Java, including the base type and the composite type

21. Initialization of one-dimensional arrays:

① initializes the elements of an array while declaring it,

For example: int[] Smallprimes = {2, 3, 5, 7, 11, 13};

② will automatically follow the number of initial values given, calculate the length of the array, and allocate the corresponding space.

③ in Java, you can initialize an anonymous array.

For example: New int[] {17, 19, 23, 29, 31,37}

④ uses this syntax form to reinitialize an array without creating a new variable.

For example: Smallprimes = new int[] {17, 19, 23, 29, 31,37};

22. Initialization of multidimensional arrays:

The ① system automatically calculates the size of the array based on the initial value.

For example: int[][] magicsquare={{16, 3, 2, 13}, {5, 10, 11, 8}, {9, 6, 7, 12}, {4, 15, 14, 1}};

In ②java language, a two-dimensional array is treated as an array of arrays and an array as an object.

23. Multidimensional Arrays:

① in programming, if you need to store two-dimensional tabular data, where each data type is the same, you can use a two-dimensional array.

② the assignment of each element of a two-dimensional array is typically done through nested double loops.

24. Irregular array:

①java can use an irregular array, that is, each row of an array has a different length.

② when creating irregular arrays, allocate space for each dimension array starting from the highest dimension.

Example: String a[][]=new string[2][];

A[0]=new string[2];

A[1]=new String[3];

A[0][0]=new String ("good");

A[0][1]=new String ("luck");

A[1][0]=new String ("to");

A[1][1]=new String ("your");

A[1][2]=new String ("Family");

25. Summary of the array:

To determine the size of the ① array before use, you can dynamically generate the array as needed in your program (such as calculating the size with an expression).

②biginteger and BigDecimal. These two classes can handle numeric values that contain a sequence of arbitrary lengths.

③ the properties of the array-length: the number of array elements.

An array in ④java is an object type that can be used as a parameter to a method, and a reference to an array is simultaneous by a method call.

The ⑤valueof method converts a normal value into a large value.

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)

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

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 experimental results 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 experimental results are 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 experimental results are 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;

The experimental results are as follows:

(2) test Bigintegertest.java, master the use of large numerical classes;

The experimental results are as follows:

(3) test Lotterydrawing.java, master the use of arrays;

The experimental results are as follows:

(4) test Compoundinterest.java, master the use of multidimensional arrays;

The experimental results are as follows:

(5) Test Lotteryarray.java, master the use of irregular arrays.

The experimental results are as follows:

4. Experiment Summary:

By studying the third chapter I am more familiar with some ways of Java programming, and some syntax. and further familiar with the basic steps of Java Program development under the command line mode; Mastering the process of importing Java source programs in the Eclipse integrated development environment; Mastering the basic syntax of the Java language Construction Basic program data types, variables, operators, types of expressions, input and output, Process control , and mastered the use of the string class, the StringBuilder class number, and also learned some ways to deal with large values.

In general the third chapter of the knowledge point is quite many, although some things I am not very familiar with, I will continue to study the textbook knowledge, and do the corresponding programming. I believe that the contents of chapter three will be fully mastered soon.

20177100106 Dongwen "Object-oriented Programming (Java)"

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.