Feng Zhixia 201771010107 "Object-oriented Programming (Java)" Second week study summary

Source: Internet
Author: User
Tags modifier

Experiment Two Java Basic Program Design ( 1 )

Experimental Time 2018-9-6

The study and mastery of theoretical knowledge:

Naming conventions:

    • Case sensitive: All names are case-sensitive
    • Class name: Uppercase for each word first letter
    • Method Name: All methods start with lowercase letters
    • class file name: Class file name must be the same as the class name
    • Program main entrance: All programs are from Public static void Main (string[] args) method to start execution

Class names, method names, variable names are called identifiers

    • all identifiers are in letters ( A- z or A- z ), dollar symbol ( $ ), beginning with an underscore ( _ )
    • The first character can be followed by letters, dollar symbols, underscores, numbers
    • Keyword cannot be used as an identifier
    • Identifiers are case-sensitive

Variable type

member variables: In a class, variables defined outside the method body exist in heap memory

Local variables: Variables defined in methods, construction methods, statement blocks, existing in stack memory

static variable (class variable): A variable defined outside a method body in a class, but must be decorated by the static keyword, where there is still storage (method area)

Basic data types

Four types of numbers:byte(1 bytes),short( 2 bytes),int(4 bytes),long( 8 bytes)

Two floating-point types:float(4 bytes),double(8 bytes)

A Boolean type:boolean(false and true)

One character type:char(2 bytes )

Key words

The key word is Java the language has been given a certain meaning some of the words.  

Common are: class , Public , Try , Catch , if , float , Import , void and so on.  

Keyword does not make a variable name.

Comments

Java There are three ways to annotate: 1./ /The contents of the note are 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.

String

    • Java string is Unicode The sequence of characters, which is the basic data structure of the organization character, used similar to a character array.

There is a built-in string type, but a standard Java The class Library provides a Java pre-defined classes String . In Java , strings that are used as objects in the l -manager program can be divided into two main categories:

1. immutable strings that are not modified and changed after the creation of the string class;
2.
Build String StringBuilder class that allows changes and changes after creation .

    • Input/Output
    • * Read Input  * formatted output  * file input and output

Large value

* if basic integer and floating-point data do not meet the required precision, you can use the Java.math two classes in a package, BigInteger and the BigDecimal . These two classes can manipulate arbitrary long numbers.

*biginteger class implements an integer operation of arbitrary precision, BigDecimal the floating-point arithmetic with arbitrary precision is realized.

Array

* An 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,

as A[0] represents an array a the first element, A[1] represents an array

    • Non-access modifiers
    • Static modifier
    1. Static variables: No matter how many objects are instantiated, there is only one static variable, and the local variable cannot declare a static variable
    2. Static methods: Static methods cannot use non-static variables

Final modifier

    1. Final modified variable: constant, value not variable
    2. Final Decorated object: variable value, reference invariant
    3. Final decorated method: can inherit, but cannot be overridden
    4. Final decorated class: not able to inherit

Abstract modifier

    1. Abstract class: cannot be used for instantiation, a class cannot be both abstract and final decorated
    2. Abstract methods: cannot be declared as final and static, abstract methods must appear in abstract classes

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)

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

}

}

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.

In this program, the scanner class object is implemented from the console input operation, the 20th line defines the new variable age assigns the value to it to do the following

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.

Summary: This experiment I learned how to import the source program in the IDE, through the legality of the Test code and learning examples to slowly understand the input and output, the legitimacy of identifiers, the definition of variables, and some of the same knowledge of C language, and so on, although not fully mastered, But also better than before, of course, mainly from the above examples to learn the loop control structure, the use of large numeric classes, one-dimensional arrays and multi-dimensional arrays and the use of irregular arrays, these programs for me or now fully understand still a little difficult, but I try to find information to overcome. Every time do experiment always have to understand, learn, master, step by step slowly to ascend

Feng Zhixia 201771010107 "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.