First knowledge of Java

Source: Internet
Author: User

The first part of the Java Foundation

I. Knowledge of Java

1. What is Java?

Java is an object-oriented programming language that can compose cross-platform applications, and is a generic term for the Java programming language and Java platform (ie, javase, EE, javame), introduced by Sun Microsystems Corporation in May 1995.

2. Build a Java Project

① Create a new java-project:file---new---java-project, creating PROJECT;SRC Storage package and source files;

Project name: named English, letters, numbers, underscores, cannot start with a number, and each word is capitalized in the first letter.

Example: Helloworld_1

    

    

② new Package in SRC

Name: Letters, numbers, underscores, cannot start with a number; The URL is inverted +project name (lowercase).

Example: Com.jredu100.helloworld

    

      

③ new Java class,name and Class name are the same in the package.

Example: HelloWorld

    

Second, Java basic knowledge

1. How to name identifiers 

① Pascal nomenclature: Capitalize the first letter, followed by the first letter of all the words are capitalized;

Classes, interfaces, enumerations, etc. are used in Pascal's nomenclature.

Hump rule: First letter lowercase, all subsequent words capitalized.

The method name, variable name and so on use the hump rule.

When the ② identifier is named, it begins with a letter, underscore, and $ symbol, and the remainder can be letters, underscores

and numbers.

2. Basic data types in Java

①int (integral type)

②short (short integer type)

③long (Long integer type)

④byte (bytes)

⑤float (single-precision floating-point type)

⑥double (double-precision floating-point type)

⑦char (character type): Char c= ' a '; or char c= ' word ';

⑧boolean (Boolean): Only true and false two values

3. Data type Transfer

① Basic data type: pass by value, pass the copy, modify the copy without affecting the original data;

② Reference Data type: passed by reference, passing a pointer, if the modification affects the original data.

4. Constant value

(1) constant type (package change)
Boolean constant: (True, False)
Character Constants
string Constants
NULL constant: Indicates that the reference variable is saved with an empty address and has not pointed to any objects.
Integral type constant
floating-point constants
(2) Use of constants
declaring constants needs to be decorated with final    
//constant name All letters are capitalized (pi=3.14f)
//constants cannot be modified during program operation
final float pi=3.14f;    
//pi=3.1415f;
float Area=10*10*pi;    
System.out.println (area);

5. Basic Data type Conversion
(1) automatic type conversion rules
Wasting memory space
A, Rule 1: Arithmetic operations
Low---> High level
Short s_int=100;
int n=s_int;
System.out.println (n);
(2) Forced type conversion
forced type conversions (high-level---> Low-level) are required when assigning a high number of types to a low-level type
int turns to short:
   int n3=100;
Short s_int2= (short) N3;
System.out.println (s_int2);
* from high to low turn, loss of data accuracy;
For example: float f3=7.999f;
int n4= (int) F3;
System.out.println (N4);
6. Operators
(1) operator type
arithmetic operations: + (plus)-(minus) * (multiply)/(except)% (take surplus)
relational operations: equals sign: = = not equals symbol:! = greater than symbol:> less than symbol:< greater than equals symbol: >= less than equals symbol: <=
bitwise operator:& | ~; logical operator:&& | |!
Assignment Operation: = + = = *=/=%=
single-Mesh operation: + (take positive)-(minus) + + (self-increment)--(self-reduction)
Multi-mesh operation (ternary operator): A>b?true:false
shift operator:<< left shift, >> right SHIFT, >>> unsigned right shift
(2) operator precedence and binding
Priority: Non-> and > or
other best-in-Class () control, highest priority
(3) Scanner
//1. Get your membership card number 4 digits
System.out.println ("Please enter the membership card number (4-bit integer)");
//instantiation of a Scanner object SC: Object name NEW: New
//system.in Standard input stream, console input
Scanner sc=new Scanner (system.in);
//sc.nextint () Gets the value of an int from the standard input stream (input decimal, missed match, error)
int cardid=sc.nextint ();//get an int data value
System.out.println (CardID);

  

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.