公司网站建设空间自然堂网站建设情况
- 作者: 五速梦信息网
- 时间: 2026年03月21日 11:10
当前位置: 首页 > news >正文
公司网站建设空间,自然堂网站建设情况,安平县做网站的有哪些,中山网站建设招聘Java核心类库类Math(☆☆☆)System(☆☆☆)Object(☆☆☆☆)Objects (☆)BigDecimal(☆☆☆☆)基本类型的包装类(☆☆☆☆☆)算法(☆☆☆☆☆)二分查找冒泡排序递归Arrays(☆☆☆☆)Date (☆☆☆☆☆)SimpleDateFormat(☆☆☆☆☆)LocalDateTime (☆)Throwable 类(☆☆☆☆)Str… Java核心类库类Math(☆☆☆)System(☆☆☆)Object(☆☆☆☆)Objects (☆)BigDecimal(☆☆☆☆)基本类型的包装类(☆☆☆☆☆)算法(☆☆☆☆☆)二分查找冒泡排序递归Arrays(☆☆☆☆)Date (☆☆☆☆☆)SimpleDateFormat(☆☆☆☆☆)LocalDateTime (☆)Throwable 类(☆☆☆☆)String(☆☆☆☆☆)StringBuilder(☆☆☆)类 Math(☆☆☆) Math的这些方法 都是静态的。 Math的构造方法私有的。 Math是不能创建对象的。 1.public static int abs(int a) 返回参数的绝对值 absolute 绝对的 例:int abs Math.abs(-10); //102.public static double ceil(double a) 向上取整 例:double ceil Math.ceil(10.1); //11.03.public static double floor(double a) 向下取整例:double floor Math.floor(10.9); //10.04.public static int round(float a) 四舍五入例:long round Math.round(10.1); //10long round1 Math.round(1.9); //25.public static int max(int a,int b) 返回两个int值中的较大值例:int max Math.max(10, 20); //206.public static int min(int a,int b) 返回两个int值中的较小值例:int max Math.max(10, 20); //107.public static double pow(double a,double b) 返回a的b次幂的值例:double pow Math.pow(2, 3); //88.public static double random() 返回值为double的正值[0.0,1.0)例:double a Math.Random(); //随机一个0.0到1.0之间的小数 int b (int)(Math.random()*13) //[0,13) System(☆☆☆) System的这些方法 都是静态的。 System的构造方法私有的。 System是不能创建对象的。 1.public static void exit(int status) 终止当前运行的 Java 虚拟机非零表示异常终止 2.public static long currentTimeMillis() 返回的是 当前时间 减去1970-1-1 8:00:00的时间差,所换算成的毫秒值。3.arraycopy(Object src , int formIndex , Object dest ,int formIndex1 ,int len ); //arraycopy(数据源数组, 起始索引, 目的地数组, 起始索引, 拷贝个数)Object(☆☆☆☆) toString 类重写了toString 打印语句就打印toString的内容public class Student /extends Object/private String name;private int age;public Student(String name, int age) {this.name name;this.age age;}Override //重写toString方法public String toString() {return Student{ name name \ , age age };}}public class Demo {public static void main(String[] args) {Student s new Student(张三,23);System.out.println(s); //内容System.out.println(s.toString()); //内容}} equals(); Object 的equals方法是比较的地址。要想让自己定义的类的对象比较内容就必须重写equals方法 来比较内容public class Student {private int age;private int score;public Student(int age , int score){this.age age;this.score score;}Overridepublic boolean equals(Object o) {if (this o) return true;if (o null || this.getClass() ! o.getClass()) return false;Student student (Student) o;if (age ! student.age) return false;return score student.score;}Objects (☆) Object 类的 工具类 工具类 private 私有构造 里面全部都是 静态方法。 1.public static String toString(对象) 返回参数中对象的字符串表示形式。 2.public static String toString(对象, 默认字符串) 返回对象的字符串表示形式。如果对象为空,那么返回第二个参数.3.public static Boolean isNull(对象) 判断对象是否为空4.public static Boolean nonNull(对象) 判断对象是否不为空BigDecimal(☆☆☆☆) System.out.println(0.70.1); //0.7999999999999999BigDecimal 可以精准运算小数的加减乘除BigDecimal的两种构造方法: 1.BigDecimal bd new BigDecimal(double d); // 不可以精准运算 例: BigDecimal bd3 new BigDecimal(1.3);BigDecimal bd4 new BigDecimal(0.5);2.BigDecimal bd new BigDecimal(String s); // 可以精准运算例: BigDecimal bd1 new BigDecimal(0.1);BigDecimal bd2 new BigDecimal(0.2);成员方法: 1.public BigDecimal add(另一个BigDecimal对象) //加法例: BigDecimal add bd1.add(bd2); //0.32.public BigDecimal subtract (另一个BigDecimal对象) //减法例:BigDecimal subtract bd1.subtract(bd2); //-0.13.public BigDecimal multiply (另一个BigDecimal对象) //乘法例:BigDecimal multiply bd1.multiply(bd2); //0.024.public BigDecimal divide (另一个BigDecimal对象) //除法例:BigDecimal divide bd1.divide(bd2); //0.5 5.public BigDecimal divide (另一个BigDecimal对象精确几位舍入模式) //除法例:BigDecimal divide bd1.divide(bd2, 2, BigDecimal.ROUND_HALF_UP); //bd1除以bd2,保留2位小数,四舍五入 舍入模式: //进一法 BigDecimal.ROUND_UP 已过时//去尾法 BigDecimal.ROUND_FLOOR 已过时//四舍五入 BigDecimal.ROUND_HALF_UP 已过时基本类型的包装类(☆☆☆☆☆) 8种基本类型的包装类:(int和char特殊记,剩余首字母大写)byte Byteshort Shortint Integer(特殊)long Longfloat Floatdouble Doublechar Character(特殊)Boolean Boolean构造方法 Integer in new Integer(int num); // (已过时)in 就是100 Integer in1 new Integer(String num); // (已过时)in1 就是100 Integer in2 Integer.valueOf(int num); Integer in3 Integer.valueOf(String num); 自动装箱 Integer inte 10; //自动装箱int i 20; Integer inte2 i; //自动装箱自动拆箱 Integer in new Integer(10); int a in; //自动拆箱Integer in new Integer(10); int a in 10; //只涉及到了拆箱 Integer in1 in 10; // 自动装箱和自动拆箱基本类型和String之间的转换 int – StringString s 100;String s1 Integer.toString(10);String str String.valueOf(10);String – intint a Integer.parseInt(100); // 这个地方传入的字符串 必须是 数字形式的字符串否则就要运行出错了float 和String的转换float – StringString s 100.5f ;String s1 Float.toString(100.5f);String str String.valueOf(100.5f);String – float float f Float.parseFloat(100.6);其他的也相同…. //byte b Byte.parseByte(126); 注意Character 里面没有 parseChar的。。。。算法(☆☆☆☆☆) 二分查找 前提条件:数组内的元素一定要按照大小顺序排列如果没有大小顺序是不能使用二分查找法的二分查找的实现步骤:1定义两个变量表示要查找的范围。默认min 0 max 最大索引2循环查找但是min max3计算出mid的值4判断mid位置的元素是否为要查找的元素如果是直接返回对应索引5如果要查找的值在mid的左半边那么min值不变max mid -1.继续下次循环查找6如果要查找的值在mid的右半边那么max值不变min mid 1.继续下次循环查找7当 min max 时表示要查找的元素在数组中不存在返回-1.冒泡排序 概述:1,可以实现数组内容按顺序排序2,一种排序的方式对要进行排序的数据中相邻的数据进行两两比较将较大的数据放在后面依次对所有的数据进行操作直至所有数据按要求完成排序如果有n个数据进行排序总共需要比较n-1次每一次比较完毕下一次的比较就会少一个数据参与递归 什么是递归递归指的是方法本身自己调用自己递归解决问题的思路把一个复杂的问题层层转化为一个与原问题相似的规模较小的问题来求解递归策略只需少量的程序就可描述出解题过程所需要的多次重复计算递归的注意事项1,递归必须要有出口2,递归每次的参数传递 要去靠近出口3,递归的过程就是 把问题逐渐缩小化的过程,最终涌向出口4,递归的次数不宜过多否则都会造成内存溢出,大概最大到 18000次左右Arrays(☆☆☆☆) Arrays 类的 工具类 工具类 private 私有构造 里面全部都是 静态方法。 1,public static String toString(int[] a) 返回指定数组的内容的字符串表示形式例:int [] arr {3,2,4,6,7};Arrays.toString(arr) //[3, 2, 4, 6, 7]2,public static void sort(int[] a) 按照数字顺序排列指定的数组Arrays.sort(arr); //{2,3,4,6,7}3,public static int binarySearch(int[] a, int key) 利用二分查找返回指定元素的索引//1,数组必须有序//2.如果要查找的元素存在,那么返回的是这个元素实际的索引//3.如果要查找的元素不存在,那么返回的是 (-插入点-1)//插入点:如果这个元素在数组中,他应该在哪个索引上Date (☆☆☆☆☆) Date类概述 Date代表了一个特定的时间类精确到毫秒值构造方法 Date d new Date(); 以当前系统时间创建对象 Date d new Date(long l) 以指定毫秒值时间创建对象,(毫秒值)成员方法: Date d new Date(); 1,long time d.getTime(); //获取时间毫秒值 time是 d这个时间的毫秒值2,d.setTime(long l) 根据传入的毫秒值设置时间 SimpleDateFormat(☆☆☆☆☆) 日期格式化类 构造方法: SimpleDateFormat sdf new SimpleDateFormat(日期模板格式); //常用的日期模板格式yyyy年MM月dd日 HH:mm:ssyyyy-MM-dd HH:mm:ss格式化 Date — String String s sdf.format(Date d) 将日期对象格式化成字符串例:Date d new Date();SimpleDateFormat sdf new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);String str sdf.format(d); //2000-01-01 10:10:10解析 String— Date Date d sdf.parse(String s); 将字符串日期解析成Date对象例:String str 2020-1-1;SimpleDateFormat sdf new SimpleDateFormat(yyyy-MM-dd);Date d sdf.parse(str); //Wed Jan 01 00:00:00 CST 2020LocalDateTime (☆) jdk8 后加的表示时间的类 构造方法: public static LocalDateTime now() 获取当前系统时间例:LocalDateTime now LocalDateTime.now(); //2020-01-01T10:40:37.287public static LocalDateTime of(年, 月 , 日, 时, 分, 秒) 使用指定年月日和时分秒初始化一个LocalDateTime对象例:LocalDateTime localDateTime LocalDateTime.of(2020, 11, 11, 11, 11, 11); //2020-11-11T11:11:11获取方法 public int getYear() 获取年例:LocalDateTime localDateTime LocalDateTime.of(2020, 11, 12, 13, 14, 20);int year localDateTime.getYear(); //2020public int getMonthValue() 获取月份1-12例:int month localDateTime.getMonthValue(); //11Month month1 localDateTime.getMonth(); //NOVEMBERpublic int getDayOfMonth() 获取月份中的第几天1-31例:int day localDateTime.getDayOfMonth(); //12public int getDayOfYear() 获取一年中的第几天1-366int dayOfYear localDateTime.getDayOfYear(); //317public DayOfWeek getDayOfWeek() 获取星期DayOfWeek dayOfWeek localDateTime.getDayOfWeek(); //THURSDAYpublic int getMinute() 获取分钟int minute localDateTime.getMinute(); //14public int getHour() 获取小时int hour localDateTime.getHour(); //13转换方法: public LocalDate toLocalDate () 转换成为一个LocalDate对象,只表示 年月日例:LocalDate localDate localDateTime.toLocalDate(); //2020-11-12public LocalTime toLocalTime () 转换成为一个LocalTime对象,只表示 时分秒例:LocalTime localTime localDateTime.toLocalTime(); //13:14:20格式化和解析: LocalDateTime — Stringpublic String format (指定格式) 把一个LocalDateTime格式化成为一个字符串 指定格式传DateTimeFormatter格式参数例:DateTimeFormatter pattern DateTimeFormatter.ofPattern(yyyy年MM月dd日 HH:mm:ss);String s localDateTime.format(pattern); //2021年11月12日 13:14:20String — LocalDateTimepublic LocalDateTime parse (准备解析的字符串, 解析格式) 把一个日期字符串解析成为一个LocalDateTime对象例:String s 2020年11月12日 13:14:15;DateTimeFormatter pattern DateTimeFormatter.ofPattern(yyyy年MM月dd日 HH:mm:ss);LocalDateTime parse LocalDateTime.parse(s, pattern); //2020-11-12T13:14:15public static DateTimeFormatter ofPattern(String s) 格式对象,以便给DateTimeFormatter传参 ()里是格式增加或者减少时间的方法(plus): 1,public LocalDateTime plusYears (long years) 添加或者减去年例:LocalDateTime newLocalDateTime localDateTime.plusYears(1); //2022-11-12T13:14:20LocalDateTime newLocalDateTime localDateTime.plusYears(-1); //2020-11-12T13:14:202,public LocalDateTime plusMonths(long months) 添加或者减去月3,public LocalDateTime plusDays(long days) 添加或者减去日4,public LocalDateTime plusHours(long hours) 添加或者减去时5,public LocalDateTime plusMinutes(long minutes) 添加或者减去分6,public LocalDateTime plusSeconds(long seconds) 添加或者减去秒7,public LocalDateTime plusWeeks(long weeks) 添加或者减去周减少或者增加时间的方法(minus): 1,public LocalDateTime minusYears (long years) 减去或者添加年例:LocalDateTime newLocalDateTime localDateTime.minusYears(1); //2020-11-12T13:14:20LocalDateTime newLocalDateTime localDateTime.minusYears(-1); //2022-11-12T13:14:202,public LocalDateTime minusYears (long years) 减去或者添加年3,public LocalDateTime minusMonths(long months) 减去或者添加月4,public LocalDateTime minusDays(long days) 减去或者添加日5,public LocalDateTime minusHours(long hours) 减去或者添加时6,public LocalDateTime minusMinutes(long minutes) 减去或者添加分7,public LocalDateTime minusSeconds(long seconds) 减去或者添加秒8,public LocalDateTime minusWeeks(long weeks) 减去或者添加周 修改方法(with): 1,public LocalDateTime withYear(int year) 直接修改年2,public LocalDateTime withMonth(int month) 直接修改月3,public LocalDateTime withDayOfMonth(int dayofmonth) 直接修改日期(一个月中的第几天)4,public LocalDateTime withDayOfYear(int dayOfYear) 直接修改日期(一年中的第几天) 5,public LocalDateTime withHour(int hour) 直接修改小时6,public LocalDateTime withMinute(int minute) 直接修改分钟7,public LocalDateTime withSecond(int second) 直接修改秒时间间隔Period 年月日) public static Period between(开始时间,结束时间) 计算两个时间的间隔,传入LocalDate参数对象LocalDate localDate1 LocalDate.of(2020, 1, 1);LocalDate localDate2 LocalDate.of(2048, 12, 12);Period period Period.between(localDate1, localDate2);System.out.println(period); //P28Y11M11Dpublic int getYears() 获得这段时间的年数System.out.println(period.getYears()); //28public int getMonths() 获得此期间的月数System.out.println(period.getMonths()); //11public int getDays() 获得此期间的天数System.out.println(period.getDays()); //11public long toTotalMonths() 获取此期间的总月数System.out.println(period.toTotalMonths()); //347Period 不能获取总天数 因为在这两时间之内 每个月份是有31天和30天 29天28天之分的。// 要想获取 时间间隔天数 请用下面的Duration时间间隔Duration: 年月日时分秒 public static Duration between(开始时间,结束时间) 计算两个“时间的间隔LocalDateTime localDateTime1 LocalDateTime.of(2020, 1, 1, 13, 14, 15);LocalDateTime localDateTime2 LocalDateTime.of(2020, 1, 2, 11, 12, 13);Duration duration Duration.between(localDateTime1, localDateTime2);System.out.println(duration); //PT21H57M58Spublic long toSeconds() 获得此时间间隔的秒System.out.println(duration.toSeconds()); //79078public long toMillis() 获得此时间间隔的毫秒System.out.println(duration.toMillis()); //79078000public long toNanos() 获得此时间间隔的纳秒System.out.println(duration.toNanos()); //79078000000000// 获取此事件间隔的天数System.out.println(duration.toDays()); Throwable 类(☆☆☆☆) 异常的概述 : 指的是程序出现了不正常的情况异常的体系结构: Throwable Error(问题严重,不需要处理)Exception(异常类,程序本身可以处理的问题)RuntimeException(运行时异常,编译的时候不报错)非RuntimeException(编译期异常,编译的时候就会报出红线目的是为了让你检查程序,用throws抛出即可)RuntimeException运行期异常处理: 运行期异常的trycatch处理方式当出现了问题之后 给这个用户一个温馨的提示并且做到让后续的代码继续执行(程序不崩溃)try…catch处理方式标准格式try{可能会出现异常的代码}catch(异常类型 对象名) {处理方式} Throwable的三个方法 try {/String s null;boolean aa s.equals(aa);/int[] arr {1};System.out.println(arr[100]); // 向外扔出一个异常 new ArrayIndexOutOfBoundsException(100);} catch (Exception e) {System.out.println(e.toString()); //java.lang.ArrayIndexOutOfBoundsException: 100System.out.println(————);System.out.println(e.getMessage()); //100System.out.println(————);e.printStackTrace();/java.lang.ArrayIndexOutOfBoundsException: 100at com.suihao.Demo10.main(Demo10.java:9)/}运行期异常的Throws处理方式没有任何用处。 Throws的处理方式 并不是针对运行期异常而产生的。因为 运行期异常 不管你throws 还是不throws 都是一摸一样的。 没有任何差别。String(☆☆☆☆☆) 构造方法 1, String s abc; //直接赋值2, String s new String(); //等同于String s1 ; 3, String s new String(abc); //等同于14, String s new String(char[] chars); //传入char数组5 ,String s new String(char[] chars,int index,int count); //根据传入的字符数组和指定范围个数来创建一个字符串对象5, String s new String(byte[] bytes) //传入byte数组6, String s new String(byte[] bytes,int index,int count); //根据传入的字节数组和指定范围个数来创建一个字符串对象7, String s new String(StringBuilder builder) //传入StringBuilder对象成员方法 获取功能:1, int length(); 获取字符串的长度2, String concat(String str); 拼接字符串并返回新字符串3, char charAt(int index); 获取指定索引处的字符4, int indexOf(String str); 获取传入的字符串在整个字符串中第一次出现的索引位置5, int lastIndexOf(String str); 获取传入的字符串在整个字符串中最后一次出现的索引位置6, String substring(int index); 从指定索引处开始截取默认到结尾7, String substring(int start,int end); 截取指定索引范围的字符串。(包含开始索引、不包含结束索引)8, static String valueOf (参数); 可传: (int i) (long l) (float f) (double d) (char c) (boolean b) (char[]ch)// 返回 各自 参数的字符串表示形式。判断功能:1, boolean equals(String str); 比较两个字符串内容是否相同区分大小写2, boolean equalsIgnoreCase(String str); 比较两个字符串内容是否相同不区分大小写3, boolean startsWith(String str); 判断整个字符串是否以传入的字符串为开头4, boolean endsWith(String str); 判断整个字符串是否以传入的字符串为结尾5, boolean contains(String str); 判断整个字符串中是否包含传入的字符串6, boolean isEmpty(); 判断字符串是否为空转换功能:1, char[] toCharArray(); 将字符串转成字符数组2, byte[] getBytes(); 将字符串转成字节数组3, String replace(String oldS,String newS);用新字符串替换老字符串4, String toUpperCase(); 将字符串转成大写并返回5, String toLowerCase(); 将字符串转成小写并返回其他功能:1, String[] split(String regex); 根据指定规则进行切割字符串2, String trim(); 去掉字符串两端的空白StringBuilder(☆☆☆) 作用 主要是为了用来拼接字符串的 构造方法: StringBuilder() 创建一个内容为空的字符串缓冲区对象 StringBuilder(String str) 根据字符串的内容来创建字符串缓冲区对象成员方法: StringBuilder append(任意类型); 向缓冲区中追加数据 StringBuilder reverse(); 将缓冲区的内容反转 String toString(); 将缓冲区的内容转成字符串 int length(); 获取缓冲区的长度两者转换: String s abc123; StringBulider sb new StringBulider(s);String s1 sb.toString;
- 上一篇: 公司网站建设开发国外创意设计网站
- 下一篇: 公司网站建设框架互动交流平台
