Liu Zhimei 201771010115. Object-Oriented Programming (Java) The second week of learning summary

Source: Internet
Author: User

Experiment two Java Basic Program Design (1)

experimental Time 2018-9-6

The first part: Theoretical Knowledge learning

3.1 A simple Java application

The keyword public is called an access modifier, and these modifiers are used for the level of access to the code in other parts of the control program;

The keyword class indicates that All content in a Java program is contained in a class, and the keyword cannot be a variable name;

Identifier The first symbol cannot begin with a number, consisting of letters, underscores, dollar signs, and numbers, used for class name, variable name, method name, array name, file name;

in Java methods, there can be no parameters or one or more parameters;java is case-sensitive;

The source code must have the same name as the public class and a. java extension;

The Java compiler automatically names the bytecode file as Firstsample.classandstores it in the same directory as the source file;

in Java each sentence must end with a semicolon, specifically, passing is not the end of the statement.

3.2 Notes

Javathree ways to annotate: 1The most common way is to use//, its comment content is from//start to the end of the bank. 2When lengthy annotations are required, they can be marked before the comments on each line//, you can also use/*and the*/surround a long comment. 3used to automatically generate documents to/**Start,*end.

3.3 Data Types

Java is a strongly typed language, and one type must be declared for each variable,andJava has an arithmetic package that can represent arbitrary precision, often called a large value.

1. Integral type

integers are used to denote numbers that have no decimal parts, are allowed to be negative, and the range of integers is independent of the machine running Java Code, because java programs must ensure that the same results are available on all machines. Therefore, the numeric range of the various data types must be fixed; The number of bytes occupied by all data types in Java is platform Independent.

2. Floating-point types

all floating-point numeric calculations follow IEEE754 specification, there are three special floating-point values used to indicate overflow and error conditions: positive infinity, negative infinity,NAN(not a number);

A value of type float has a suffix f or F, and a floating-point value without a suffix f defaults to Double type;

3. char type

The Char type originally represents a single character, and The literal value of the char type is enclosed in single quotation marks .

4. Unicode and char types

Unicode characters exceed 65536 ;

A code point is a coded value that corresponds to a character in the encoded table.

5. Boolean type

The Boolean type has two values:false and true, used to determine the logical condition;

An integer value and a Boolean value cannot be converted to and from each other.

3.4 Variable

variables must be defined before they are used, the declaration and definition of variables are not differentiated in Java, and the keyword final indicates the constant, the keyword final indicates that the variable can only be assigned once, once assigned, it cannot be modified, the constant name is used to use all uppercase.

3.5 operator

Operators are related to object-oriented operations; The syntax format for forcing type conversions is to give the target type that you want to convert in parentheses, followed by the name of the variable to be converted, because the operator changes the value of the variable, so their operands cannot be numeric, operators have two forms: prefix and suffix, and operator-position mode processing.

3.6 String

As Object processing in Java, a predefined class is provided in the Java Standard class library, called string, using string the Length () method in the class can get the lengths of a string, and the string used in the program is divided into two classes, including the immutable string and the string , Changed and mutable string StringBuilder.

3.7 input/Output

to read the "standard input stream"system.in first need to build a Scanner object, and with "standard input stream"systam.in associated because the input is visible, so Scanner class does not apply to reading passwords from the console; To read a file, you need a File object constructs a Scanner To write to a file, you need to construct a PrintWriter object.

3.8 Array

An array is a data structure used to store a collection of values of the same type, allowing an array variable to be copied to another array variable in Java, at which point two variables will refer to the same array , and the Java application's Main method, the program name is not stored in the args the array.

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

(3) Master the Java Language constructs the basic program data type , the variable , the operator, each kind of expression, the input output, the flow control the basic grammar;

(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, output the values of the following 4 expressions and experiment results.

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;

Experimental results:

Experiment 3: Change Experiment 2 s1,S2,S3 as StringBuilder class object, observe the program running result and experiment 2 results are compared to understand the difference between a string class object and a StringBuilder class object.

Experimental results:

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

}

}

Lab 5: 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 such as, click on the above Browse Select Import source program and select, click 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.

(1) Right-click 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, mastering 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 the file.

Experimental results:

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 master the loop 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) test Lotteryarray.java, master the use of irregular arrays.

The experimental results are as follows: 1.

2.

3.

4.

5.

6.

7.

Experimental summary: In the third chapter of the study, know the data types, variables, type conversion and input and output, etc. through this experiment, I learned to import the sample program in Eclipse environment and run the results, in the previous experiment, I understand the difference between the string and the StringBuilder class object In the experiment computer operation process encountered a problem, by asking classmates, read a book to solve; Through this experiment I realized that I have a great lack of writing Java programs, need to constantly learn and actively knock code, which also helps to understand the theoretical knowledge, long-term persistence to see the obvious progress.

Liu Zhimei 201771010115. Object-Oriented Programming (Java) The second week of learning 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.