Basic Java Content

Source: Internet
Author: User
Tags float double

I. Java Fundamentals
1. Data type
Char One byte Chinese 2-3
String
int long short byte (127-128)
Float double
Boolean
2. Data conversion
Large to small section casts
Long time=199999888;
int timeint= (int) time;

Short age=90;
int ageint=age;

String agestr= "19";

int->integer Class

int Age1=integer.parseint (AGESTR);

String money= "20000.05";
Reference Class Float->float Class
Double->double class
float moneyfloat = float.parsefloat (Money);
String to Value

Example

1. Enter a value (3-10) to figure out its factorial

BYTE b1=10;
Short s2= (short) b1+11;//error

float scope = 990.5f;
Decimal type default double integer default int

Numeric Type-string
21-> "21"
String s2str=string.valuueof (S2);

String scopestr=string.valueof (scope);

3. Object-oriented
Class:
Properties (member variables)
Method (member method, construction method)

Members of the class four access rights:
Public: Class object access
Default: Class object access under the same package
Protected: The subclass member method of the class can be accessed
Private: The member method of the class can access the

Grammar:
Class Name {

member variables;
Construction method;
Member methods;

}

Class Name: The first character must be uppercase, followed by the first character of each phrase is capitalized
Member variable: the first character is lowercase, followed by the first character of each phrase is capitalized
Constructor Method Name: = Class name does not have an identifier for the return type, access rights are public
Member method name (named) = Member variable. Composition: Access right return type method name {}

Class person{
private String name;
Public person () {

}
Public person (String name) {
This.name=name; (use of local variables)

}
public void Market (String tings) {


}
Public Sting GetName () {
return name;

}

}


Instantiation of the class:
Class reference = new Class construction method ();
Person P=new person ();
P.market ("fruit");

4. Common Classes
String, Math, Date,simpledateformmat

String:length ()
Replace (String ostr,string rstr)
SUBSTRING (int start)
substring (int start, int end)
Equals (String s)
Format (String pattern,object ...);

Math:double random ()//[0,1)

Create new Project:new SDK, select Jdk_home

Development environment: JAVA; 1.8/1.6 IntelliJ Idea (Eclipse)

Structure:
. idea
SRC (source information)/main App.java
iML
Shortcut keys:
Alt+[insert] Generate classes, packages, class members

alert+ enter [Enter] solve the problem key, guide package, type conversion, exception handling, etc.
Alt+ctrl+s Open Settings page
Alt+ctrl+shift+s Open the Project file Settings page

Set Font size: Setting->editor->color&fonts
->save

Basic Java Content

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.