美文网首页
javaSE基础总结

javaSE基础总结

作者: 尽人事听天命_6c6b | 来源:发表于2019-06-18 19:53 被阅读0次

/**

  • 变量与运算符
  • 标识符:就是一个名称 例如类名:VariableDemo
  • 特点(规则):首字母大写
  • 关键字:是具有特殊意义的单词 例如:public(公有的) class(类) static(静态的) void(无返回值的)
  • 特点:都是小写的
  • 注意:包名全都小写 格式com.neusoft
  • 变量:变量是指在程序的运行过程中随时可以发生变化的量
  • 作用:保存数据 例如:x = 0 y = 20
  • Java中数据类型:
  •  有两种数据类型:
    
  •      1.基本类型(8种):
    
  •      整型(byte 8位 、short 16位、 int 32位、 long 64位) 最常用的默认的类型为 int类型    整型的默认值为0
    
  •      浮点型(float 32位 double 64位)  浮点数默认的类型为double类型    浮点型默认值为0.0
    
  •      布尔(boolean):只有两个值(true/false) 布尔(boolean)默认值为false
    
  •       字符(char):表示键盘上一个特定的字符  使用'一个特定的字符'   注意与"多个字符组成的字符串"
    
  •      2.引用类型
    
  • 如何定义一个变量呢?语法:数据类型 变量名[=变量的初始值];
  • 注意:变量一定要先初始化然后才能使用
  • @author ttc

*/
public class VariableDemo{
public static void main(String[] args) {
String name="tom";
byte age = 100;//一个字节=8位
short number = 45;//16位
int mon=1000;//32位
long nuk = 1133L;//64位
float f = 23.567F;
double d = 3.4;
boolean isRight = false;
char c = 'a';
System.out.println(c);
System.out.println(isRight);
System.out.println(f);
System.out.println(d);
System.out.println(34.567);//浮点数默认的类型为double类型
System.out.println(age+number+mon+nuk);//+会累加求和
System.out.println("相当于字符串的连接"+age+number+mon+nuk);//+相当于字符串的连接

}

}
/**

  • Java中的运算符
  • 是一种特殊的符号,用以表示数据的运算、赋值和比较
  • 运算符的种类:
  • 1.算术运算符:+、 ﹣、 *、 /、 %(求余数)、 ++(自增加1)、 --(自减1)
  • 2.赋值运算符: =、 +=、 ﹣=、 *=、 /=、 %=
  • 3.比较运算符:>、 <、 >=、 <=、 ==、 !=、 注意:比较运算符的最终结果为boolean类型
  • 4.逻辑运算符
  • @author ttc

*/
public class OperatorDemo {

public static void main(String[] args) {
    
    
    int a = 5;
    int b = 2;
    int c = a + b;
    int d = a / b;
    int e = a % b;
    String s1 = "aaa";
    String s2 = "bbb";
    // 关系运算符--------------------------------start
    boolean b1 = a>b;
    boolean b2 = a<b;
    System.out.println(b1);//true
    System.out.println(b2);//false
    System.out.println(a>=b);//true
    System.out.println(a<=b);//false
    System.out.println(a==b);//false
    System.out.println(a!=b);//true
    // 关系运算符--------------------------------end
    
    // 赋值运算符--------------------------------start
    //      System.out.println(a+=b);
    //      System.out.println(a-=b);
    //      System.out.println(a*=b);
    //      System.out.println(a/=b);
    //      System.out.println(a%=b);
    // 赋值运算符--------------------------------end
    // 算术运算符--------------------------------start
    System.out.println("---------------------------");
    //算法:(a++)=5 a=6  (++a)=7 a=7   (a--)=7 a=6   (--a)=5 a=5
    //      int f = (a++)+(++a)+(a--)+(--a);
    //      System.out.println(f);//24
    //      System.out.println(s1+f+s2);
    //int f = ++a;//a++:a先参与运算,之后a自身加1
    //System.out.println("f="+f);
    //System.out.println("a="+a);
    System.out.println("---------------------------");
    System.out.println(c);
    System.out.println(d);
    System.out.println("5除以2的余数为:"+e);
    // 算术运算符--------------------------------end

}

}

/**

  • 创建一个Person类(抽象的概念)
  • 属性:姓名(String) 性别(char) 年龄(int) 出生年月(String) 所在学校(String)
  • 8种基本数据类型:byte short int long float double char boolean
  • 整数类型默认值:0 浮点类型默认值:0.0 boolean的默认值:false
  • 创建变量的基本语法: 数据类型 变量名[=初始值];
  • 类型转换:
  •      自动类型转换(由小到大)
    
  •      int a = 10;
    
  •      double d = a;
    
  • 强制类型转换(由大到小)
    
  •      double k = 3.14;
    
  •      int y = (int)k;
    

*规则:
*1.不同类型的变量进行运算最后得到的是位数最大的类型 int a = 1 float f = 3.14F double d = 12.90 double dd = a+f+d
*2.字符串与任何基本数据类型连接后,最终的结果都是字符串 System.out.println("hello"+a+d);

  • @author zjjlive

*/
@SuppressWarnings("unused")
public class Person {

public static void main(String[] args) {
    
    String name = "tom";
    char sex = 'M';
    int age = 30;
    String birthday = "1995-6-13";
    String school = "foreknow test";
    boolean marry = true;
    double salary = 2000.50;
    
    float fff = '1';
    System.out.println(fff);
    
    System.out.println(name);
    System.out.println(sex);
    System.out.println(age);
    System.out.println(birthday);
    System.out.println(school);
    System.out.println(marry);
    System.out.println(salary);
}

}
/**

  • Java中的运算符
  • 是一种特殊的符号,用以表示数据的运算、赋值和比较
  • 运算符的种类:
  • 1.算术运算符:+、 ﹣、 *、 /、 %(求余数)、 ++(自增加1)、 --(自减1)
  • 2.赋值运算符: =、 +=、 ﹣=、 *=、 /=、 %=
  • 3.比较运算符:>、 <、 >=、 <=、 ==、 !=、 注意:比较运算符的最终结果为boolean类型
  • 4.逻辑运算符: &&(逻辑与) ||(逻辑或) !(逻辑非)
  • 运算规则 : true && true=true true || true = true !isRight
  •        true && false=false        true || false = true
    
  •        false && true=false        false || true = true
    
  •        false && false=false       false || false = false
    
  • 在实际中如何使用: 20<x<100 等价于(x>20) && (x<100)
  • @author ttc

*/
public class OperatorDemo {

public static void main(String[] args) {
    int x = 140;
    int a = 5;
    int b = 2;
    int c = a + b;
    int d = a / b;
    int e = a % b;
    System.out.println(d);
    String s1 = "aaa";
    String s2 = "bbb";
    
    System.out.println(x>20 && x<100);//20<x<100
    System.out.println(x>20 || x<100);
    
    boolean isRight = false;
    System.out.println("取反:"+!isRight);
    // 关系运算符--------------------------------start
    boolean b1 = a>b;
    boolean b2 = a<b;
    System.out.println(b1);//true
    System.out.println(b2);//false
    System.out.println(a>=b);//true
    System.out.println(a<=b);//false
    System.out.println(a==b);//false
    System.out.println(a!=b);//true
    // 关系运算符--------------------------------end
    
    // 赋值运算符--------------------------------start
    //      System.out.println(a+=b);
    //      System.out.println(a-=b);
    //      System.out.println(a*=b);
    //      System.out.println(a/=b);
    //      System.out.println(a%=b);
    // 赋值运算符--------------------------------end
    // 算术运算符--------------------------------start
    System.out.println("---------------------------");
    //算法:(a++)=5 a=6  (++a)=7 a=7   (a--)=7 a=6   (--a)=5 a=5
    //      int f = (a++)+(++a)+(a--)+(--a);
    //      System.out.println(f);//24
    //      System.out.println(s1+f+s2);
    //int f = ++a;//a++:a先参与运算,之后a自身加1
    //System.out.println("f="+f);
    //System.out.println("a="+a);
    System.out.println("---------------------------");
    System.out.println(c);
    System.out.println(d);
    System.out.println("5除以2的余数为:"+e);
    // 算术运算符--------------------------------end

}

}
**

  • if 条件判断 (单一条件)
  • 基本语法:
  • if(表达式){
  •   执行语句;
    
  • }
  • 规则:如果条件表达式为true 就会执行化括号里面的语句 如果条件表达式为false会执行if之后的语句
  • if 条件判断(二选一)
  • 语法:
  • if(表达式){
  • 语句块1;
  • }else{
  • 语句块2;
  • }
  • @author ttc

*/
public class IFControlDemo {

public static void main(String[] args) {
    int x = 160;

// if(x>=60){
// System.out.println("太好了,及格了!!!!!");
// }
// System.out.println("我很爱学习java!!!!!!");

    System.out.println("---------------------------------------------");
    
    if(x>=60) {
        System.out.println("及格了!!!!!!");
    }else {
        System.out.println("不及格!!!!!!");
    }
    System.out.println("需要重修!!!!!!");
    
    System.out.println("---------------------------------------------");
    
    boolean b = true;
    if (b=false) {
        System.out.println("111111111111111");
    } else {
        System.out.println("222222222222222");
    }
    System.out.println(b);
    
    System.out.println("-----------------------------------------------");
    
    int y = 2;
    
    if(y<2){
        ++y;
    }
    else{
        y--;
    }
    System.out.println("y="+y);
    System.out.println("-------------------------------------------------");

// y=y<2?++y:y--;
// System.out.println("y="+y);

// int z=(y--);
// System.out.println(z);
// System.out.println(y);

}

}
/**

  • 数组:数组可以看成是多个相同类型数据的组合, 实现对这些数据的统一管理。也可以将数组看成是一个容器 元素:数组中的每一个数据都可以称为一个元素
  • 数组的长度:数组中元素的个数 数组的分类:一维数组、多维数组 一维数组的定义: 数组类型[] 数组名; 如何对数组进行初始化?数组类型[] 数组名 =
  • new 数组类型[长度]; 动态初始化 1. int[] array = new int[5]; 静态初始化 1. int[] array1 = new
  • int[]{1,23,4,5,66,77,12}; 2. String[] s =
  • {"java","c++","python","javascript","spring"}; 如何获取到数组中某一个元素:数组名[下标] 例如:s[1]
  • = "c++" 注意:数组的下标是从0开始的
  • @author ttc

*/
public class ArrayDemo {
public static void main(String[] args) {
// 定义一个整型数组,数组名为array并进行初始化
// int[] array = new int[5];
// //如何对数组进行赋值
// array[0] = 12;
// array[1] = 1;
//// array[2] = 3;
//// array[3] = 14;
//// array[4] = 5;
//
// System.out.println(array[4]);
//
// String[] s1 = new String[4];
// s1[0] = "tom0";
// s1[1] = "tom1";
// s1[2] = "tom2";
// s1[3] = "tom3";
// System.out.println(s1[3]);
//
// //静态初始化
// int[] array1 = new int[]{1,23,4,5,66,77,12};
// System.out.println(array1[1]);
// System.out.println("数组的长度为:"+array1.length);
//
// String[] s = {"java","c++","python","javascript","spring"};
// System.out.println("输出数组中的某一个元素:"+s[4]);
//
// System.out.println("------------------------------------------------");
// //如何将数组中的元素一次输出(对数组进行遍历),可以使用循环
// for(int i = 0;i<s.length;i++) {
// System.out.println(s[i]);
// }
//
// //练习:已知数组[2,14,68,15,3,66,5,35] 用户从控制台输入一个数并判断这个数在数组中是否存在
// //思路:
// //1.对数组进行遍历操作
// //2.每遍历一次需要判断用户输入的这个数与数组中的某一个元素是否相等,如果相等跳出循环
//
// Scanner input = new Scanner(System.in);
// boolean isRigth = false;
// System.out.println("请输入一个数:");
// int guess = input.nextInt();
// int[] arr = {2,14,68,15,3,66,5,35};
// for(int i = 0;i<arr.length;i++){
// if(guess==arr[i]) {
// isRigth = true;
// break;
// }
// }
// if(isRigth) {
// System.out.println("success......");
// }
//
// //已知数组[2,14,68,15,3,66,5,35] 求数组中所有数的奇数和以及偶数和
//
// //二维数组的定义以及初始化(数组的数组)
// int[][] arr1 = new int[3][4];
// arr1[0][0] = 12;
// arr1[0][1] = 13;
// arr1[0][2] = 14;
// arr1[0][3] = 15;
//
// arr1[1][0] = 11;
// arr1[1][1] = 12;
// arr1[1][2] = 13;
// arr1[1][3] = 14;
//
// arr1[2][0] = 22;
// arr1[2][1] = 23;
// arr1[2][2] = 24;
// arr1[2][3] = 25;
//
//
//
// int[][] arr2 = {{1,2,3},{4,5,6},{7,8,9}};
// System.out.println(arr2[0][1]);
//
// int[][] a = new int[3][ ];
// a[0] = new int[2];
// a[1] = new int[3];
// a[2] = new int[4];

    // System.out.println(a[0][0]);
    int[][] a = { { 1 }, { 4, 5, 6 }, { 7, 8 } };
    for (int i = 0; i < a.length; i++) {
        for (int j = 0; j < a[i].length; j++) {
            System.out.print(a[i][j] + " ");
        }
        System.out.println();
    }

// [3,1,4,67,13,12,2]
}
}

/**

  • 函数:函数是完成某个功能的一组语句,通常将常用的功能写成一个函数 例如:input.next()

  • 函数有两种:1.使用别人写好的函数,我们调用 2.自定义的函数

  • 语法:

  • [访问控制符] [修饰符] 返回值类型 函数名(参数类型 形式参数,参数类型 形式参数,…)
    {
    函数体
    }
    返回值类型有两种:1.有返回值的 2.无返回值 void
    如何调用函数:在主方中使用 类名.函数名(实参)
    参数的类型:可以是基本类型(8种)/引用类型 String、数组
    注意:自定义函数要与在类中,不能写在main方法中,因为java的函数是不能嵌套的
    形式参数:在方法被调用时用于接受外部传入的变量(用户的输入)
     参数类型:就是该形式参数的数据类型
    返回值:方法在执行完毕后返回给调用它的程序的数据(表示函数的最终的结果)
     返回值类型:函数要返回的结果的数据类型(基本类型、引用类型)
    注意:如果一个函数有返回值类型就一定要写return(表示函数的最终结果)

       什么时候定义有返回值的方法,什么时候定义无返回值的方法
         当方法的调用者(main)需要利用函数返回值的结果参与其它运算,就应该定义为有返回值的方法,否则可以定义为无返回值的函数
    
  • @author ttc

*/
public class FunctionDemo {

public static void eat(String tools){
    System.out.println("我们可以使用"+tools+"来吃饭!!!");
}

public static void sleep() {
    System.out.println("sleep......");
}

/**
 * 定义一个登录的方法
 * 思考:是否需要参数(username,password)
 * @param args
 */
public static void login(String username,String password){
    System.out.println("用户名:"+username+"密码:"+password);
}

public static void cacul() {
    int[] array = {1,2,3,4,5,6,7};
    for(int i = 0;i<array.length;i++){
        System.out.println(array[i]);
    }
}

/**
 * 用户从控制台输入两个数并计算两个数之和
 * 用函数来实现
 * @param args
 */
public static void sum(int a,int b) {
    int sum = a+b;
    System.out.println(sum);
}



/**
 * 计算三个数之和
 * @param a 输入参数
 * @param b 输入参数
 * @param c 输入参数
 * @return sum 和
 */
public static int total(int a,int b,int c) {
    int sum = a+b+c;
    return sum;
}

public static void main(String[] args) {
    int sum = FunctionDemo.total(1, 2, 3);
    int fol = sum+100;
    System.out.println(sum);
    
    System.out.println("-----------------------------------------");
    //函数的调用
    FunctionDemo.eat("筷子");
    FunctionDemo.sleep();
    FunctionDemo.login("tom","123456");
    FunctionDemo.cacul();
    
    Scanner intput = new Scanner(System.in);
    
    System.out.println("请输入第一个数:");
    int num1 = intput.nextInt();
    System.out.println("请输入第二个数:");
    int num2 = intput.nextInt();
    
    //函数的调用
    FunctionDemo.sum(num1, num2);
    
    
}

}
/**

  • 函数是不能嵌套的但是可以互相调用
  • 注意:main函数可以放到其它类中。main就相当于测试函数
  • @author ttc

*/
public class FunctionDemo2 {
public static int f1(int a, int b) {
return a + b;
}

public static String f2(String username, String password) {
    int sum = f1(1, 2);
    String school = f3("forknow");
    return username + "  " + password + sum + school;
}

public static String f3(String school) {
    return school;
}

}

/**

  • 冒泡排序(由小到大排序)
  • 规则:相邻的两个元素进行比较
  • array:[3,1,16,22,11,4,5,7]
  • [1,3,16,11,4,5,7,22]
  • 思路:
  • 需要使用嵌套for,外层的for循环控制总的比较次数,内层循环完成相邻的两个元素比较
  • 相邻的两个元素比较?
  • a = 2 b =1 如果a>b a = 1 b = 2 创建一个临时变量(空瓶)
  • @author ttc

*/
public class PopSort {

// public static void pop() {
// int[] array = {3,1,16,22,11,4,5,7};
// for(int i = 0;i<array.length;i++) {
// //相邻的两个元素比较
// for(int j = 0;j<array.length-1;j++) {
// if(array[j]>array[j+1]) {
// int temp = array[j];
// array[j] = array[j+1];
// array[j+1] = temp;
// }
// }
// }
// //对排序后的结果输出
// for(int i = 0;i<array.length;i++) {
// System.out.println(array[i]);
// }
// }

// public static void pop(int[] array){
// for(int i = 0;i<array.length;i++) {
// //相邻的两个元素比较
// for(int j = 0;j<array.length-1;j++) {
// if(array[j]>array[j+1]) {
// int temp = array[j];
// array[j] = array[j+1];
// array[j+1] = temp;
// }
// }
// }
// //对排序后的结果输出
// for(int i = 0;i<array.length;i++) {
// System.out.println(array[i]);
// }
// }

public static int[] pop(int[] array){
    for(int i = 0;i<array.length;i++) {
    //相邻的两个元素比较
    for(int j = 0;j<array.length-1;j++) {
        if(array[j]>array[j+1]) {
            int temp = array[j];
            array[j] = array[j+1];
            array[j+1] = temp;
        }
    }
}
    return array;
}

public static void main(String[] args) {

// PopSort.pop();
int[] array = {3,1,16,22,11,4,5,7};
int[] a = PopSort.pop(array);
//对排序后的结果输出
for(int i = 0;i<a.length;i++) {
System.out.println(a[i]);
}
}
}

/**

  • 构造函数(构造器):它是一个特殊的方法,这个方法没有返回值类型,通过情况下访问修饰符都是public的
  • 语法:
  • public 类名(参数类型 参数名,参数类型 参数名....){
  • }
  • 构造器的调用:new 构造器();
  • 构造器的作用:1.可以初始变量 2.可以初始化对象
  • 注意:
  • 在Java中,每个类都至少要有一个构造方法,如果程序员没有在类里定义构造方法,系统会自动为这个类产生一个默认的构造方法
  • @author ttc

*/
public class ConstructorDemo {
String name;
int age;
String school;
User user;

//初始化变量
public ConstructorDemo(String name,int age,String school){
            //this表示当前对象(ConstructorDemo)自身
            this.name=name;
            this.age = age;
            this.school = school;
            user = new User();
            //user.setEmail("zjjlive@163.com");
    
}

// public ConstructorDemo() {
// System.out.println("这是一个默认的构造函数......");
// }

public void method() {
    System.out.println("method......");
}

public static void main(String[] args) {
    ConstructorDemo cDemo = new ConstructorDemo("tom",30,"foreknow");   
}

}

/**

  • 在一个构造方法中,调用其它重载的构造方法
  • 语法:
  • this();
  • 规则: this();只能写在构造器的第一行。
  • @author ttc

/
public class ConstructorDemo2 {
public ConstructorDemo2() {
System.out.println("D......................");
}
public ConstructorDemo2(int a) {
this();
System.out.println("A......................");
}
public ConstructorDemo2(int a,int b) {
this(a);
System.out.println("B......................");
}
public ConstructorDemo2(int a,int b,int c) {
this(a, b);
System.out.println("C......................");
}
public static void main(String[] args) {
ConstructorDemo2 cDemo2 = new ConstructorDemo2();
}
}
/
*

  • 方法的重载:方法名相同,参数以及类型不同,与返回值类型无关
  • 变量的作用域:
  • 1.出现在main方法中的变量,称为局部变量(只在main中有效),一定要先初始化,然后再使用
  •  例如:int a = 0;   String name = null;  boolean isRight = false;  Student s = null; Scanner s = null;
    
  • 2.出现在方法中的变量,称为局部变量(只在当前方法中有效),一定要先初始化,然后再使用
  •  public class A{
    
  •      public void method(int a,String n,User u){
    
  •          int max = 0;一定要先初始化,然后再使用
    
  •      }
    
  •      public static void main(String[] args){
    
  •          A a = new A();
    
  •          User user = new User();
    
  •            a.method(1,"abc",user);
    
  •      }
    
  •  }
    
  • 3.出现在类中的属性(变量)为全局变量,作用域在整个类中都有效
  • @author ttc

*/
public class OverLoadDemo {
public int sum(int a,int b) {
int c = a+b;
return c;
}
public void sum(int a,int b,int c) {
int d = a+b+c;
System.out.println(d);
}
public static void main(String[] args) {
OverLoadDemo oDemo = new OverLoadDemo();
int s = oDemo.sum(1, 2);
System.out.println(s);

    oDemo.sum(3, 4, 5);
}

}

**

  • 匿名對象
  • 语法:
  • new 类名().方法名()
  • 什么时候使用:只需要调用当前对象方法一次
  • @author ttc

*/
public class SayHello {

public String say() {
    return "say";
}

public void abc() {
    System.out.println("abc......");
}

public String method() {

// SayHello sayHello =new SayHello();
// String ss = sayHello.say();

    return new SayHello().say();
}

public static void main(String[] args) {
    SayHello sHello = new SayHello();
    sHello.say();
    sHello.abc();
    
    //匿名對象
    new SayHello().say();
    new SayHello().abc();
}

}
/**

  • static关键字
     static可以修饰的元素
     属性:可以被多个对象共享 在实际中经常被用于累加器 调用:类名.静态变量 StaticDemo.a
     方法:类名.方法名()
     代码块
    static{
    //作用是负责初始化(变量、对象)
    }
    注意:静态代码块无需调用(了解)
    需要注意的问题
     只能修饰类成员,不能修饰局部变量。
    静态方法里只能直接访问静态成员,而不能直接访问类中的非静态成员
     静态方法中不能使用this关键字
     静态方法不能修饰构造方法
  • @author ttc

*/
public class StaticDemo {
String name;//成员变量(实例变量)
static int a;//静态变量
public StaticDemo() {
a++;
}

//静态方法
public static void method() {
    System.out.println("static method......");
}

//实例方法(成员方法)
public void test() {
    System.out.println("test.....");
}

public static void main(String[] args) {
    //调用静态方法
    StaticDemo.method();
    
    StaticDemo s1 = new StaticDemo();
    System.out.println(s1.name);
    System.out.println(StaticDemo.a);
    StaticDemo s2 = new StaticDemo();
    System.out.println(s2.name);
    System.out.println(StaticDemo.a);
    StaticDemo s3 = new StaticDemo();
    System.out.println(s3.name);
    System.out.println(StaticDemo.a);
    StaticDemo s4 = new StaticDemo();
    System.out.println(s4.name);
    System.out.println(StaticDemo.a);
}

}
/**

  • 面向对象编程:就是面向类编程,类是一个抽象的概念(是具有相同属性和行为的一个模板),而对象是一个具体的。
  • 特征:
  • 1.封装
     2.继承
     3.多态
    类中只能定义属性(变量)与行为(方法)
    public class 类名{
    成员变量(属性)
    成员方法(函数)
    }
    如何创建对象
    类名 引用变量 = new 类名(); Scanner input = new Scanner(System.in)
    如何访问当前对象的属性以及方法:
    1.引用变量.属性名 2. 引用变量.方法名()
  • @author ttc

*/
public class Student {

int sid;//学号
String name;//姓名
String school;//所在学校
int age;//年龄

public void eat() {
    System.out.println("eat......");
}

public void sleep() {
    System.out.println("sleep......");
}

public void study() {
    System.out.println("study......");
}

public static void main(String[] args) {
    //如何创建对象
    Student s1 = new Student(); 
    s1.sid = 1000;
    s1.name = "tom";
    s1.age = 20;
    s1.school = "neusoft";
    s1.eat();
    s1.sleep();
    s1.study();
    System.out.println(s1.sid+"--"+s1.name+"--"+s1.age+"--"+s1.school);
    Student s2 = new Student(); 
    s2.sid = 1001;
    s2.name = "jazz";
    s2.age = 30;
    s2.school = "neusoft";
    s2.eat();
    s2.sleep();
    s2.study();
    System.out.println(s2.sid+"--"+s2.name+"--"+s2.age+"--"+s2.school);
}   

}
/**

  • User类:可以称为一个Javabean(就是一个普通的java类),只包含get/set方法
  • 规则:所有的属性都定义为private(私有的)
  • private:只有当前类可以使用,对于其它类是不可见的(封装)
  • 构造器的重载:构造器的名称相同,但是参数不同(类型) 例如:println(String) println(char) println(int)
  • @author ttc

*/
public class User {
private String email;
private String password;
private String confirm_pass;
private String require_code;
private String phone;
public User() {
}
public User(String email,String password,String confirm_pass) {
this.email = email;
}
//获取email的属性值
public String getEmail() {
return email;
}
//可以给User对象的属性email进行初始化(设置一个值)
public void setEmail(String email) {
this.email = email;
}
}

相关文章

  • javaSe基础总结

    、6一、基本知识 1.JDK和JRE的区别 答:JDK是java语言开发工具包,包含JRE和开发工具(javac....

  • javaSE基础总结

    /** 变量与运算符 标识符:就是一个名称 例如类名:VariableDemo 特点(规则):首字母大写 关键字...

  • 大数据新鲜干货,一起学习吧

    大数据语言基础 语言基础(视频) JavaSE 语言基础 Eclipse 开发环境 、 JavaSE 7.0 AP...

  • JavaSE 基础学习之五 —— IO 操作 (java. io

    接上篇《JavaSE 基础学习之四 —— 异常的处理》 五. JavaSE 基础学习 —— IO 操作 (java...

  • JAVA(1) 基础与环境配置

    基础了解、环境配置 基础 java ~~~ 1995年诞生 javaSE~~~ java基础版 javaEE...

  • 简述JavaEE学习流程

    1,Java基础 Java基础也就是JavaSE,Java SE(Java Platform, Standard ...

  • JavaSE基础

    面向对象都有哪些特性以及你对这些特性的理解 一.继承:继承是从已有类得到继承信息创建新类的过程。提供继承信息的类被...

  • JAVASE基础

    第一阶段java基础复习 1.软件开发基础 1.1开发软件的目的 提高人个计算机之间的交互方式 1.2软件 软件=...

  • JavaSE基础

    1.干什么之前要先有思路,在有总体的思路构想后,不断在思路的指导下面做事情和完善相应的细节。 2.理解越多,需要记...

  • JavaSE基础

    1,Java虚拟机以及jdk和jre的介绍 为什么JAVA可以跨平台? 和C++ 相比,很重要的一点就是:C++ ...

网友评论

      本文标题:javaSE基础总结

      本文链接:https://www.haomeiwen.com/subject/wupqqctx.html