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

Source: Internet
Author: User
Tags mathematical functions

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

A Theoretical Knowledge Learning Section

3.1j Simple Java Application

Identifiers consist of letters, underscores, dollar signs, and numbers, and the first symbol cannot be a number. Identifiers can be used as: class name, variable name, method name, array name, file name, and so on. Part II: Theoretical Knowledge Learning Section

3.2 Key Words

Some words in the Java language that have been given a particular meaning. L Common: class, public, try, catch, if, float, import, void and so on. Keyword does not make a variable name.

3.3 Data types

Integer: Indicates a number with no decimal point, four types, int type, short type, long type, byte type (Java-specific)

Floating point: A value representing a decimal part, with two types; float type; double type

Char type: Represents a single character

Escape sequences for special characters: "\b" backspace, "\ t" tab, "\ n" line break, "\ r" carriage return; "\" "double quotation mark;" \ "" single quotation mark; "\ \" Backslash

Unicode and Char types:

Boolean type: Used to determine the logical condition, there are two values of false and True

Variable

Variable initial value: The variable must be explicitly initialized with an assignment statement after declaring a variable

Constant

Use the keyword final to indicate a constant: The keyword final indicates that the variable can only be assigned once, and once it is assigned, it cannot be changed

3.5 operator

Mathematical Functions and constants

Functions in the Math class: Math.sin (Trigonometric functions), math.exp (inverse function), Math.pow (Power operation)

Conversions between values

When necessary, the value of the int type is automatically converted to the value of double, and sometimes it is necessary to change the value of the double type to int type. This is done by forcing type conversion (CAST).

Self-increment and decrement operators

I++:i=i+1, use the value before I:

I--:i=i-1, use the value before I;

++i:i=i+1, use the value after I;

--i:i=i-1, use the value after I;

3.6 string

SUBSTRING: The substring method of the string class extracts a substring from one of your larger strings.

Stitching: The Java language allows the use of + stitching two strings

Immutable string: The String class does not provide a method for modifying a string.

Check that the strings are equal: detected using the Equal method.

empty string and null string empty strings "" are strings of length 0

Build string: Use StringBuilder to build

3.7 Input and output

Formatted output: Use System.out.print (x) to output the value x to the console.

File input and output: you need to build an object with a Flie object

3.8 Control Process

Block Scope: A block (compound statement) is a number of simple Java statements enclosed in a pair of curly braces.

Conditional statement: A condition is a true execution of multiple statements.

Loop: When the condition is ture, the while loop executes a statement.

Determine loops: The FOR Loop statement is a common structure that supports iterations, using counters updated after each iteration or similar variables to control the number of iterations.

Multiple statements: The Swich statement starts at the case label that matches the option value until the break statement is encountered, or until the end of the Swich statement is executed.

Interrupt Control Flow statement: The break statement used to exit the Swich statement can be used to exit the loop statement as well.

3.9 Large values

Java can be used if basic integers and floating-point numbers are dissatisfied. The BigInteger and BigDecimal in the math package can handle numeric values that contain sequences of arbitrary lengths.

3.10 Arrays

Array: A data structure used to store a collection of values of the same type.

For Each loop: Each element in the array can be processed one at a time, and no subscript value should be established.

Array initialization and anonymous arrays: This notation creates a new array and initializes the values of the array with the values provided in parentheses as the number of initial values. You can use this syntax form to reinitialize an array without creating a new variable.

Command parameter line: Each Java application has a main method with a string argue[] argument. This parameter means that the main method will accept an array of strings.

Multidimensional arrays: Array elements will be accessed using multiple subscripts it is suitable for representing tables or more complex permutations,

irregular arrays; Java does not actually have multidimensional arrays, only one-dimensional arrays. Multidimensional arrays are interpreted as "arrays of arrays".

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) Master the process of importing the Java source program into the Eclipse integrated development environment;

3) Master the basic syntax of the Java language Construction Basic program data types, variables, operators, various types of expressions, input and output, flow 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)

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;

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 ("!");

}

}

Experiment 5:eclipse Environment to import the 3rd chapter of the example 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;

Reterement.java

The results of the Retirement2.java are as shown

Lotteryodds.java results as shown

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

(3) Lotterydrawing.java, mastering the use of arrays

(4) Compoundlnterest.java Mastering the use of multidimensional arrays

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

4. Experiment Summary: Through the study of this chapter, further understand the C language and Java differences, input and output of different, class name, data type, the Java development environment has a further understanding and understanding, learned how to use the existing text resources, how to import text documents into the program.

201771010126 Wang Yan "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.