core java知识点整理

9.30 java语言基础(one day
  1.命令提示符:d:、cd c:work 、dir、path、等
  2.最好在当前目录运行这个类,否则需要以下形式执行:
  java -cp 类所在的目录 类名
  3.注释:单行、多行、文档
  //、
   /*
   */、
  /**
  *
  */
  4.输入、出(Scanner类)
  import java.util.Scanner;
  Scanner scanner=new Scanner(System.in);
  int a=scanner.nextInt();
  int b=scanner.nextInt(2);//二进制
  String str=scanner.next();
  nextLine()/nextByte()/ nextShort()/ nextDouble()/
  
  hasNextInt();
  hasNextInt(2);//按照指定的进制判断
  
  eg.//两者结合使用,先判断是否合法,再执行,这样比较安全
  while(scanner.hasNextInt()){
   sum+=scanner.nextInt();
  }
  
  print()/ println()/ printf();
  eg.
  int a=10;
  int b=20;
  int c=a+b;
  System.out.printf("%d+%d=%d",a,b,c);//输出格式化消息
  格式化规定符:http://blog.csdn.net/feiniaolql/article/details/7177783
  
  5. 标识符 、关键字、 字面值
  标识符使用Unicode字符集
  Unicode(2^7)前128个字符与ASCII码一致(2^16)
  int 数字1=10;//合法,不提倡
  命名习惯
  
  关键字不能作为标识符
  eg. abstract/ for / int
  
  字面值
  eg. null字面值
  boolean:true/false
  
  变量:
  局部变量:系统不会自动对其进行默认初始化
  合法命名的条件:
  满足标识符的命名要求;不能使关键字,也不能是true、null等特殊意义的字面值;在同一个作用域内不能重名
  
  6.八种数据类型
  整数类型:byte / short / int / long
  浮点类型:float / double
  字符类型:char
  逻辑类型:boolean
  eg.float b=1.1;//错误
  char c=97;//c表示字符‘a'
  
  转换:
  byte>short> int > long > float> double
        char>    
   强制转换:
   int a=10;
   char c=(char)a;
   隐含强制转换:eg.  byte b=12; 但byte b; int a=12;a=b;//出错,这种隐含转换仅用于字面值对变量进行赋值时
  7.数组
   arraycopy
  8.算数运算符
  精度:其结果类型是两个参与运算操作数的精度较高者,且最少是int类型
  
  移位运算符:<< 有符号左移 、 <<<无符号
  1<<31; //-2^31
  -1<<<1; //2^31-1
  移位运算结果的数据类型:
  byte a=10;
  a=a>>1; //错
  a=(byte)a>>1; //自动转换成int
  
  位运算符:& 、| 、 ^ 、~
  
  赋值运算符: x=1; x+=1;
  
  关系运算符: <  >=
  
  逻辑运算符:&&  ||   !   ^
  
  其他运算符:? 条件运算;
     new  创建对象
     . 用于访问对象或类的成员方法、变量
     []用于数组操作
     instanceof 判断对象时什么类型
  9.语句
  分支:if 和 switch-case
  switch-case: 一般为char  byte  short  int / Character  Byte  Short  Integer  enum
  循环:for  、 while 、 do-while
  控制:break 、 continue 、return

(9.30)
 类与对象基础
  1.Math类
  
  2.String 、 StringBuffer 、StringBuilder
   区别: String 字符串常量(不变模式,对象池)
     StringBuffer 字符串变量(线程安全)
     StringBuilder 字符串变量(非线程安全)
  String:
   1)常用构造器
    public String(char[]value)
    public String (char[]value,int offset,int count )
    publci String (String original)
   2)常用方法
    A.
    public int length()
    pulbic char charAt(int index)
    public char[] toCharArray()
    B.查找单个字符
    public int indexOf(int ch)
    public int indexOf(int ch,int fromIndex)
    public int lastIndexOf(int ch)
    public int lastIndexOf(int ch,fromIndex)
    C.字符串内容比较
    public boolean equals(Object anObject)
    pulbic boolean equalsIgnoreCase(String anotherString)
    public int compareTo(String anotherString)
    public int compareToIgnoreCase(String anotherString)
    public boolean startsWith(String prefix)
    public boolean startsWith(String prefix,toffset)
    D.搜索字符串
    public int indexOf(String str)
    public int indexOf(String str,int fromIndex);
    lastIndexOf()
    E.获取子字符串
    public String substring(int beginIndex)
    public String substring(int beginIndex,int endIndex)
    F.创建新字符串
    public String replace(char oldChar,char newChar)
    replaceAll(String regex,String replacement)
    replaceFirst(String regex,String replacement)
    toLowerCase();
    toUpperCase()
    concat(String str)
    trim()
    G.拆分字符串
    public String[] split(String regex)
    split(String regex,int limit)
    
  StringBuffer
   public StringBuffer()
   public StringBuffer(Stirng str)
   pulbic StringBUffer(int capacity)
   
   public int capacity()
   length()
   toString()
   常用方法:
    A.添加方法
    append();
    B.插入方法
    insert(int offset,插入内容(如:boolean b,char c,String str...))
    C.删除、替换、修改方法
    delete(int start,int end)
    deleteCharAt(int index)
    replace(int start,int end,String str)
    reverse()
    setCharAt(int index,char ch)
    setLength(int newLength)
    D.查找
    indexOf
    lastIndexOf
    E.读取
    substring
    charAt
    getChars
    
  StringBuilder:与StringBuilder一样
 
  如何选择三者:
    ●  如果你偶尔对简单的字符串常量进行拼接,那么可以使用String,它足够简单而且轻量级; 
    ●  如果你需要经常进行字符串的拼接、累加操作,请使用StringBuffer或StringBuilder;
    ●  如果是在单线程的环境中,建议使用StringBuilder,它要比StringBuffer快;如果是在多线程的环境中,建议使用StringBuffer,它是线程安全的;
(10.2补充){
   两种创建字符串的方法:
    String name="haha";//从对象池中得到,如果没有则创建
    String name=new String("haha");//创建新的“haha”。。。。创建了两个对象,首先在对象池创建“haha”,再作为参数创建对象
    
    Integer i=5; //包装类Integer也有不变模式和对象池,与String类似(day06 am),但为什么没有StringBuffer的,所以要是经常改变Integer的话,就不用了呗,改为int,因为它可以随便改变的。
    Integer i=new Integer(5);
   } 
  3.数组类
   A.一维数组的拷贝:System.arraycopy()
   public static void arraycopy(Object src,int srcPos,Object dest,int destPos,int length)
   eg.System.arraycopy(arraySrc,3,arrayDest,1,2);
   B.   排序与搜索:Arrays.sort() ;Arrays.binarySearch()
   public static void sort(类型[]a);
   publci static void sort(类型[]a,int fromIndex,int toIndex);
   public static int binarySearch(类型[]a,类型key);
   C.不等长的二维数组
    首先通过"new 数据类型[行长度][]"创建二维数组,再分别创建相应长度的数组
    eg. int[][] table=new int[2][];
     table[0]=new int[2];
     table[1]=new int[4];
  4.基本类型包装类
   Integer:public static int parseInt(String s)
     public static int parseInt(String s,int radix)
     public static String toString(int i,int radix)
     public Integer(int value)
     publci Integer(String s)
     public static Integer valueOf(int i)
     public static Integer valueOf(String s,int radix)
     publci static Integer decode(String nm)
     public byte byteValue()//shortValue(),intValue(),doubleValue()
     
10.1 5.BigInteger与大数处理
   BigInteger:处理大整数
    在具体应用中如果某个整数的取值范围超过long类型时,为了避免运算溢出等情况,需要考虑BigInteger或浮点型.
    浮点型:精度损失,速度较快
    BigInteger:不会损失精度,速度较慢
     eg. BinInteger result=BigInteger.ONE;
     for(int i=1;i<n;i++){
      BigInteger k=BigInteger.valueOf(i);
      result=result.multiply(k);
     }
   BigDecimal:处理大小数
   
  6.时间处理
   A.Date类
    读取和设置毫秒数
    转换为字符串
    Date对象的比较
    
   B.SimpleDateFormat类:public String format(Date date)
    eg.  Date dateNow=new Date()
      SimpleDateFormat dateForm=new SimpleDateFormat(yy年mm月dd日);
      dateForm.format(dateNow);
   C.Calendar:  Calendar calendar=Calendar.getInstance();
    获取日历字段的值:public int get(int field);
   D。Date对象与Calendar对象之间的转化: calendar.setTime(dateNow);//将calendar时间设置为dateNow的时间
    
  7.Exception与异常处理  
   运行时异常和非运行时异常
(10.2补充){
  8.Object类 
  equals(Object obj):(覆盖的掌握,及其要对其覆盖必遵循的五大原则)
       反身性;对称性;传递性;一致性;非空性
   String s1=new String("hello");
   String s2=new String("hello");
   sysou(s1==s2);   //false
   sysou(s1.equals(s2)); //true   此处不是Object的equals方法,是String.。比较的是值
  hashcode
  toString
  9.int , Integer , String之间的转换
   int转Integer:  Integer i=5;//自动装箱和拆箱  JDK5.0
        new Integer(5);
        Integer.valueOf(5);
   Integer装int:  i.intValue();
        int a=new Integer(5);//  JDK5.0
   String转Integer: new Integer("12");
        Integer.valueOf("12");
   Integer转String: .toString()
   String转int:  Integer.parseInt("");
   int转String:  Integer.toString(5);//(5,int 进制)
  10.包装类:为什么包装类;提供了什么方法;类型转化
  11.main方法的参数
  }
  面向对象:以数据抽象为导向
  面向过程:以业务逻辑为导向(C中没有类,只有函数)
  
  生成对象的过程:分配对象空间;
      给属性附初值;
      调用构造方法
 类的设计与封装
  封装:类、方法、包都可认为封装
     类的封装:i.该私有的私有,该公开的公开
     ii. 类的属性一般为私有,
     iii.get和set方法(只读和只写),可以在set方法里的参数设置安全检查。其实就叫JavaBean(良好封装的组件)
  继承:继承是多态的基础(extends 扩展;inherit继承)
    里氏代换原则
    super()  this()  super.xxx   this.xxx的用法
    子类中一般不再定义相同的属性,没意义
    覆盖的注意点
    强制类型转换一般和instanceof连用
     eg. if(a1 instanceof Bird){
      Bird b=(Bird)a1;
     }
    Animal a=new Bird();
    a.move();//子类的move
    a.name;//父类的name(父子类都有name的条件下,不提倡这样)
    
  多态
 类继承与接口的设计(one day
    接口没有构造方法
    接口---继承(多)--接口
    接口中的属性必须赋值
    接口编程的 好处:
     尽量降低系统的 耦合度;
     将标准制定者和标准的实现者分离
     接口应该尽量简单和单一
     基于接口的编程(基于抽象的编程)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值