Wang Yan 201771010127 "Object-oriented Programming (Java)" Second week study summary

Source: Internet
Author: User
Tags arithmetic mathematical constants pow

Wang Yan 201771010127" Object-oriented programming (java)" second Week study summary

Part I: Theoretical Knowledge learning Section

3.1: Basic concepts.

1) Identifier: The identifier consists of a letter, a number, a dollar sign, and an underscore. And the first symbol cannot be a number. For example: Hello,$1234, program name,www_123 , etc. are all legal identifiers .

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

2) Keywords:words in Java that are given a particular meaning. Common keywords are class, public, catch, if, float, and so on.

The keyword cannot be used as a variable name.

3.2: Comment.

1)//: The contents of the note can be from the bank to the end.

2) when lengthy annotations are required, you can mark//in front of each line of comments , or use/* and/* to enclose a longer comment.

3) start with/** and/or end (there is no such comment in the C language) that can be used to automatically generate the document.

3.3: Data type.

in Java, there are eight basic types, including 4 integer, 2 floating-point, 1 character types for Unicode-encoded character cells, char, and a Boolean type to represent the truth.

1) shaping (int, short, Long, byte): Shaping is used to denote a numeric value without a decimal part, which allows a negative number.

2) floating-point type (float, double): A floating-point type is used to represent a numeric value with a decimal part.

The three special floating-point values in floating-point types that represent overflow and error conditions are: positive infinity, negative infinity, and NaN (not a number).

3) Char type: The char type is used to represent a single character.

4) Boolean type: The Boolean type has two values: false and True, which is used to determine the logical condition. There is no conversion between an integer value and a Boolean value.

3.4: variable.

in the In Java, each variable has a type, and the type of the variable is before the variable name when declaring the variable.

Double Salary;int vacationdays;

Long Earthpopulation;boolean done;

in the In Java, a row can declare multiple variables, and declaring each variable line by row can improve the readability of the program. In addition, you cannot use a Java reserved word as a variable name.

int i,j;//both is integers

3.4.1: Initialization of variables.

after declaring a variable, you must explicitly initialize the variable with an assignment statement, and never use an uninitialized variable.

in Java, you can place a declaration anywhere in your code and try to get close to where the variable was first used.

In Java, the Declaration and definition of variables are not distinguished.

3.4.2: constant (all caps are generally used).

in the In Java, the keyword final indicates a constant, and the keyword final indicates that the variable can only be assigned once.

in Java , you often want a constant to be used in multiple methods in a class, which typically

constants are called Class constants. You can use the keyword static final to declare a class constant ( class

Constants).

in Java , you must use final to define constants.

3.5: operator.

in the in Java, use the arithmetic operator +、—、*,/ to represent subtraction operations.

An integer that is 0 apart will produce an exception, and a floating-point number that is 0 will produce an infinity or NaN result.

1) Mathematical constants and functions.

in Java , there is no power operation. So take advantage of the Math class's Pow method.

Double Y=math.pow (x,a);

In addition,Java provides two approximate values to represent the PI and e constants:Math.PI and math.e.

2) conversion between numeric types.

when converting between numeric types, one of the operands is what type, and the other operand is converted to what type. Otherwise, both operands are converted to type int.

3) Coercion of type conversions.

The syntax format for forcing type conversions is to give the target type that you want to convert in parentheses, followed by the variable name with the transformation.

Double x=9.997;

int nx=(int)x;

4) combine assignments and operators.

such as x+=4; equivalent to x=x+4;

3.6: String.

the class used for the string is a standard class.

Java does not have a built-in string type, but instead provides a predefined class, called string, in a standard Java library. Each string enclosed in double quotation marks is an instance of the string class, such as:

String e= "";//an empty string

String greeting= "Hello";

1) substring:The substring method of the String class can extract a substring from a larger string. such as:String greeting="Hello";

String s=greeting.substring (0,3); created by the character " Hel "composed of strings.

2) splicing:The Java language allows the use of + to connect two strings.

3) detect the equality of characters: use the Equals method to detect whether two strings are equal.

* Be sure not to use the = = operator to detect equality of two strings. This operator can only determine whether two strings are placed in the same position. If the strings are placed in the same position, they are necessarily equal.

3.7: Input and output.

1) Read input: To enter through the console, you first need to construct a Scanner object and associate it with the "standard input stream"system.in .

Scanner in=new Scanner(system.in);

The Scanner class is defined in the java.util Package and must be used When the class used is not in the defined basic Java.lang package. The import indicator will load the corresponding package in.

2) formatted output: The value x can be output to the console using System.out.print (x).

3) file input and output.

3.8: Control process.

3.9: Large value.

* if the basic integer and floating point data do not meet the required accuracy, then you can use the Java.math package

of two classes, BigInteger and BigDecimal. These two classes can manipulate the number of long-term meanings.

The *biginteger class realizes the integer operation of arbitrary precision, andBigDecimal realizes the floating-point operation with arbitrary precision.

3.10: Array.

* if the basic integer and floating-point data do not meet the required precision, you can make

use the two classes in the Java.math package,BigInteger and BigDecimal. These two classes can be manipulated by a

as any an Italian-long figure.

The *biginteger class realizes the integer operation of arbitrary precision, andBigDecimal realizes the floating of arbitrary precision .

Point arithmetic.

Part Two: Experimental part.

Experiment One: Write A Java application that outputs the values of the following 4 expressions.

The input java program looks like this:

the values for the 4 expressions are:

Experiment Two: Write a Java application that contains the following code fragment , outputting the value of the string class object S3.

The input program looks like this:

S3 The resulting output is:

Experiment Three: change experiment 2 s1,S2,S3 as StringBuilder class object, observe program running result and compare with experiment 2 result, understand string class object and the difference between StringBuilder class objects.

Change to StringBuilder after the input program is as follows:

S3 The resulting output is:

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

First, in the new text document, save the following program, change the file name.

Open the command line, and the program displays the results as shown below.

Lab Five :Import Chapter 3 sample program Inputtest.java steps in Eclipse environment :

(1) new Java project such as:

(2) Select File->import->file ystem->next, open the File Import window like, click on the above browse Select Import source program and select, click Browse below After selecting 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.

Experiment Six: follow The procedure of Experiment 5, import the Writereadfiletest.java sample program, understand the program code with the program running result , Observe the contents of the file MyFile.txt under the project folder and master the input and output operation of the file.

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

1) test Retirement.java,retirement2.java,lotteryodds.java to master the cyclic control structure;

1.retirement.java:

Retirement2.java:

Lotteryodds.java:

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, and master the use of irregular arrays.

Experiment summary: Through last week's study of basic theory and the preliminary mastery of Eclipse application, in this experiment, the error rate of the program writing and format is much less than the last time. This experiment

further familiarity with command line and IDE Two ways to develop the basic Java program, learn how to import other folders in the program, the Java language constructs the basic program data types, variables,

Basic syntax for operators, types of expressions, input and output, and process control.

During the experiment, one of the experiments had an array out-of-bounds problem, so there was a case where the main class could not be loaded. With the help of the TA, I learned that only after passing the appropriate parameters to the main method, the process

order to run properly. Through this study, I found that it is important to know the identifier in Java, in addition, I have mastered more grammar, although all is still only the foundation, but I will continue to study hard, in the future study constantly improve their programming level.

Wang Yan 201771010127 "Object-oriented Programming (Java)" Second week study summary

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.