JAVA_01 基础

环境变量配置:


tomcat:       JAVA_HOME  +  JDK路径  

 JAVA:            PATH  +  bin路径


八进制必须以0开头,十六进制必须以0X或0x开头。

整数类型:

  • byte 8位
  • short 16位
  • int      32位
  • long   64位

浮点类型:

  • float   32位
  • double   64位

char 型:

用于存储单个字符,占16位(两个字节)

强制类型转换

		byte b = 3;
		b = (byte) (b + 3);

封装:函数式最小的封装体


this:用于区分全局变量与局部变量


static:属性共享      直接类名.调用


静态代码块: 随着类的加载而执行,只执行一次。


23种设计模式:

单例模式:一个类在内存中只存在一个对象。
1、为了避免其他程序过多建立对象,禁止其他程序建立对象。构造函数私有化
2、为了让其他程序可以访问到该类对象,只好在本类中自定义一个对象。创建一个本类对象
3、为了方便其他程序对自定义对象访问,可以对外提供一些访问接口提供一个方法获取该对象
public class Person {
	
	private Person(){}
	
	static Person p = new Person();
	
	public static Person getPerson(){
		return p ;
	}
}

饿汉式:
//饿汉式   单例模式
public class Single {
	private static final Single s = new Single();
	public static Single getInstance() {
		return s;
	}
}
懒汉式
//懒汉式  单例模式
public class Single {
	private static Single s = null;
	
	public Single() {

	}

	public static synchronized Single getInstance() {
		if(s==null)
			s = new Single();
		return s;
	}
}



抽象类特点:    (强迫子类做些特有事情)   (可含有两种 抽与非抽)

1、抽象方法一定在抽象类中
2、抽象方法和抽象类都必须被abstract关键字修饰
3、抽象类不可以用new创建对象。因为调用抽象方法没意义。
4、必须子类覆写方法使用。

接口: (全是抽象类)

interface Person {
	
	public static final int NUM = 3;
	
	public abstract void show();
}

多态: 实物存在多种体态

猫  x = new 猫();
动物 x = new 猫();
1、多态的体现
父类的引用指向了自己的子类对象
父类的引用也可以接收自己的子类对象
2、堕胎的前提
类与类之间有关系, 继承、实现
3、多态的好处
大大提高程序拓展性

内部类

Outer.Inner in = new Outer().new Inner();


异常:程序在运行时出现的不正常情况

问题的划分:  严重  Error、不严重 Exception。

Error: 一般不编写针对性的代码进行处理


throws Exception :  声明该方法可能抛出异常

自定义异常:

FushuException.java

class FushuException extends Exception{

	private String msg;
	
	public FushuException(String msg) {
		this.msg = msg;
	}

	public String getMessage() {
		return msg;
	}
}


demo.java

public class Demo {
	public static void main(String[] args) {

		try {
			int y = -1;
			if(y<0){
				throw new FushuException("不能使负数");
			}
			
			int x = 5 / y;
			
			System.out.println(x);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}


throws用在函数上throw用在函数内


链表数据结构


递归算法

间接或直接调用自身算法的过程

  • 一定要有出口
  • 次数过多容易溢出

	public static int diGui(int num){
		if(num == 1){
			return 1;
		}
		return num*diGui(num-1);
	}

Math类

		System.out.println(Math.PI);			//pi值
		System.out.println(Math.abs(-10));		//绝对值
		System.out.println(Math.random());		//随机值		
		System.out.println(Math.round(1.5));	//四舍五入
		System.out.println(Math.sqrt(2));		//平方根

Date类

表示特定的瞬间,精确到毫秒,也就是程序运行时的当前时间

Calendar类

日历类  使用此类可以将时间精确到毫秒

		//两种实例化方式
		Calendar calendar = Calendar.getInstance();
		Calendar calendar2 = new GregorianCalendar();

		Calendar calendar = Calendar.getInstance();
		
		int year = calendar.get(Calendar.YEAR);					
		int month = calendar.get(Calendar.MONTH);
		int day = calendar.get(Calendar.DAY_OF_MONTH);
		int hour = calendar.get(Calendar.HOUR_OF_DAY);
		int minute = calendar.get(Calendar.MINUTE);
		int sec = calendar.get(Calendar.SECOND);
		int m_sec = calendar.get(Calendar.MILLISECOND);
		int week = calendar.get(Calendar.DAY_OF_WEEK);
		
		System.out.println(year+"-"+month+"-"+day);
		System.out.println(hour+":"+minute+":"+sec+":"+m_sec);
		System.out.println("星期"+week);


DateFormat类及子类SimpleDateFormat

DateFormate:
		DateFormat df = DateFormat.getDateInstance(DateFormat.LONG,Locale.CHINA);
		String date = df.format(new Date());
		System.out.println(date);
		
		DateFormat df1 = DateFormat.getTimeInstance(DateFormat.LONG,Locale.CHINA);
		String date1 = df1.format(new Date());
		System.out.println(date1);

SimpleDateFormate:  (可直接new对象)
		//需要查找api里字母含义
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss  SSS");
		String date = df.format(new Date());
		
		System.out.println(date);


实现重写  Comparable ()  方法    比较对象

		public int compareTo(Person p){
			if(p == null){
				throw new NullPointerException();
			}
			if(this.age<p.age){
				return -1;				
			}else if(this.age>p.age){
				return 1;
			}
			return 0;
			
		}

克隆对象

/**
 * 一个类想实现克隆功能,必须:
 * 1、实现Cloneable接口,该接口是一个标记接口
 * 2、重写Object类中的clone方法
 * @author GA
 *
 */
		Cat cat = new Cat("小白", "3");
		System.out.println(cat.toString());
		try {
			Cat c1 = (Cat)cat.clone();
			System.out.println(c1);
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值