First knowledge of Java

Source: Internet
Author: User

One, character


Escape character: \ plus special character \ t \ n


Ii. data types and operators


1) Naming conventions for identifiers:
Project name, package, class, interface, variable, method name, constant
The most basic requirement: see the name and know the meaning
Project name: Letters and Numbers
Package: General use of the company domain name of the anti-write, CN.BDQN
Class, interface: First letter uppercase, if multi-syllable word, subsequent character uppercase HelloWorld
Variable, method name: First letter lowercase, if multi-syllable word, subsequent character uppercase Studentname age
Constants: All uppercase letters, if it is a multi-syllable word, underline. Age Student_name


2) Comments: Single line, multiple lines, document comments
Document comments to class and method hints.


3) Basic data type (8 kinds)


4) Usage of the Scanner class
A) console garbled problem.
b) Space question nextline () can enter a space.
c) Enter a single character: Input.next (). charAt (0);


5) Operator:
A) arithmetic operator: +-*/% + +--
Features: + can be used in string and numeric type, others can only be used in numerical type transport.
+ +-can only be combined with variables
b) Assignment Transport character: = + = = *=/=%=
c) Compare transport characters: > < >= <= = = =!
The results are all Boolean type
d) logical operators: & | Non-short circuit!  && | | Short circuit. Using short-circuit logical operators
e) ternary conditional operator? :
6) Numeric conversions: Casts and auto-conversions


Third, the program structure


1) Basic program structure: sequential structure, selection structure, cyclic structure


2) Select the structure:
A) if selection structure;
b) IF-ELSE selection structure
c) If-else if-...-[else] multiple if selection structure (comparison criteria can only be small to large or from large to small)
d) nested IF-ELSE selection structure. The dimensions that are compared are multidimensional, and the results require more than one.
e) Switch-case: equivalent judgment


3) Single Weight cycle structure
Do-while while for
Four elements of a loop:
Loop variable initialization,
Comparison of cyclic conditions,
Cyclic operation,
Changes in cyclic variables
Considerations for Recycling:
i) if the number of times is fixed, the handwriting for
II) if the number of times is not fixed, use do-while or while
III) If it must be performed once, the preferred do-while


4) Dual Cycle


5) Break continue general and if statements are put together with
Return can completely jump out of all loops


Four, array


program = data structure + algorithm


Arrays: Identifiers, subscripts, elements
Assignment of arrays: Assigning values between initializations, keyboard input assignment
1) int[] nums = {1,2,3,4}
2) int[] nums = new int[]{1,2,3,4}
Keyboard assignment via for loop


Where the array is prone to error when used:
1) array out of bounds: Upper and lower bounds


If the array is not assigned a value, there is an initial value.


Array of applications:
1) Find the maximum and minimum values in the array;
2) Find the specified value in the array
3) Add elements to the array: Find position, move element, add
4) Delete element in array: Find position, move element


Enhanced for, read-only, can only be used to read the values inside the array.


A two-dimensional array.


Arrays provides a common static method: sort (ascending), find, copy


Arrays are typically associated with a for loop when used.


First knowledge of Java

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.