201771010121 Tang "Object-oriented Programming (Java)" Second week study summary

Source: Internet
Author: User

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

Part I: Theoretical Knowledge learning Section

Chapter III Java BASIC program design structure

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

(a) Basic content:

(1) Identifier: Consists of letters, underscores, dollar signs, numbers, Chinese characters, and the first symbol cannot be a number. eg:hello,$842, Project, www_939.

Identifiers can be used as: class name, variable name, method name, array name, file name, etc.

(2) Keywords: keywords are words that have been given a particular meaning in the Java language. Eg:class, public, try, catch, if, float, import, void, and so on. Note: Keywords do not make variable names

(3) Note:

There are three ways to annotate Java:

1.//note content is from//until the end of this line.

2./* and * * Define a comment block.

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

(4) Basic type:

There are 8 basic types of Java

1.– integer type (int, short, Long, byte) – floating-point type (float, double) – character type (char) – Boolean type (Boolean)

The byte in the integer type and the Boolean type (Boolean) are unique in Java and not in C + +. There is no unsigned type in java.

Three special floating-point values that indicate overflow and error in floating-point types:

Positive infinity, negative infinity, NAN (not a number)

Data for floating-point types should be noted in calculations (P33-P34):

Note in Boolean types: in Java, Boolean values and integers cannot be converted to each other

-character type (char):

(a) Constants ' a ', ' a ', ' 8 ', '? '

variable definition char q; Char c, type, cat;

Defines both assignable Char c= ' a ', type, cat;

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

(c) Escape character: The prefix \u represents a Unicode value, whereas a hexadecimal 4-digit number indicates which Unicode character is specific. Escape sequences of some special characters, eg:\b,\n,\\, etc.

3. Variables

In Java, each variable belongs to a type. When declaring a variable, the type to which the variable belongs is before the variable name.

In Java, a row can declare multiple variables. Declaring each variable individually can improve the readability of the program.

Once a variable is declared, it must be explicitly initialized with an assignment statement.

Note: In Java, two variables with the same name cannot be declared within the same scope

Constants: The final indicator constants are used in Java. It is customary to capitalize the constant name.

Eg:final Double cm_per_inch=2.54

Final can only be assigned to variables once and cannot be changed.

Class constants are static final declarations: a constant can be used in multiple methods within a class.

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

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

Precedence of the operator:

5. Type conversion (long byte to short byte conversion):

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.

6. String (treated as Object in Java):

String: Immutable string

(a) String connection (+) of the strings class:

See Experiment 2;

When a string and a non-string are concatenated, the latter is converted to a string.

(b) The Equals method can be used to detect the equality of two strings.

such as s.equals (t); Note: S and T can be string variables or string constants.

You cannot use = = to detect whether two strings are equal, it can only determine whether two strings are placed in the same position.

(c) Get 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 functionality.

StringBuilder: Build string that allows changes and changes StringBuilder

7. Input and output

(a) When entering via 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.

(b) To read a file, you need to construct a scanner object with the Files object. Eg:–scanner in = new Scanner (New File ("MyFile.txt"));

(c) To write to a file, you need to construct a PrintWriter object, in the constructor, simply provide the file name: –printwriterout = new PrintWriter ("MyFile.txt");

8. Circular statement: While,do-while,for

Part II: Experimental part

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

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

}

}

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;

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

3. Experiment Summary:

This chapter mainly introduces the basic Java program design structure, in this chapter of learning, I learned to add comments in the Elipse, the data types, variables, operators and string conversion and use. In this experiment, we are more familiar with the process of executing programs in command line and JDK, learned how to import files in Elipse, how to write arithmetic expressions in Java, practice on the basis of theory, Clearer understanding of the difference and conversion of the string class and the StringBuilder class. But in large numbers and arrays of learning is not in place, some programming languages and writing methods have not been understood, in this regard I will spend more time to understand it.

201771010121 Tang "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.