JAVA
1.Basic DataType
int Data=1;
float Data=1.0f;
double Data=1.1;
char Data='A';
boolean Data=true;
byte Data=1;
short Data=1;
long Data=1000000L;
2.Blocks
if(condition){ do ..}
do { ... }while(condition);
for(condition){ do ..}
switch(condition) {
case condition:
default:
break;
}
3.Class
class ClassName{
var var1;//instance variable
ClassName(){
constructor1;
}
returnType methodName(var1,var2,var3 ...){
...
}
}
ClassName a=new ClassName();
a.var1=xxx;
//public menber can be accessed in the inside of its defination class and the outside
//Private only be accessed in the defination class inside;
overload method
public class test {
public static void main(String[] args) {
hello demo = new hello();
System.err.println(demo.db(3));
System.err.println(demo.db(33.3));
}
}
class hello {
int db(int a) {
return a * 2;
}
double db(double a) {
return a * 2;
}
long db(long a) {
return a * 2;
}
}
overload constractor
class demo{
int i;
demo(int i){
x=i;
}
demo(double i){
x=i;
}
}
Static
the variables can be changed or affected by any object s
static int a=2;
//the static create and can be accessed by any objects just like a global variables
public class test {
public static void main(String[] args) {
// Demo demo=new Demo();
//the static method is not nessary to new a object;
//and its not use like object.xxx;and like className.xxx;
System.err.println(Demo.passobject("hello"));
}
}
class Demo {
static String passobject(String oj) {
return new String(oj);
}
}
static block
main:
//the static block start run when the object is allocted and can use to init static value
System.err.println(Demo.name);// alex
class:
static String name;
static {
name = "alex";
}
标签:java,String,int,demo,static,Data,class
From: https://www.cnblogs.com/alexmaodali/p/18114042