Java常用类总结

2023-05-16

一、字符串相关的类

String类及其常用方法

1.String声明为final的,不可被继承。
2.String实现了Serializable接口:表示字符串是支持序列化的;
实现了Comparable接口:表示String可以比较大小。
3.String内部定义final char[] value用于存储字符串数据。
4.String:代表不可变的字符序列。具有不可变性。
5.通过字面量的定义方式(不同于new)给一个字符串赋值,此时的字符串声明在字符串常量池中。
6.凡是对String进行的增删改查操作,全是在字符串常量池中新找一块内存进行,而不是更改源字符串,类似于Python中的不可变类型。

注意

1、字符串存在内存里的方法区中的字符串常量池中,字符串常量池中是不会存储相同内容的字符串的。
例如:

String str1 = "abc";//字面量的定义方式
String str2 = "abc";
System.out.Println(str1 == str2);//输出结果为true
str1 = "hello";//此时会在字符串常量池中新找一块内存,存储"hello";
			  //而不是在存储"abc"的内存里更改,这里体现了不可变性。
str1 += "world"//因为字符串的不可变性,这里也是在字符串常量池中新造的"helloworld"。

2、常量与常量的拼接结果在常量池。
3、只要其中有一个是变量,结果就在堆中。

String s1 = "hello";
String s2 = s1 + "world";
String s3 = "hello" + "world";
System.out.println(s2 == s3);//false
//相当于栈中有个s2,s3,
//s3直接指向常量池中的"helloworld"
//而s2指向堆中(保存"helloworld"的地址)的地址。

4、如果拼接的结果调用intern()方法,返回值就在常量池中。
 

String类的常用方法

序号返回值函数功能
1intlength()返回字符串的长度:return value.length
2charcharAt(int index)返回某索引处的字符:return value[index]
3booleanisEmpty()判断是否是空字符串:return value.length == 0
4StringtoLowerCase()使用默认语言环境,将String中的所有字符转换为小写
5StringtoUpperCase()使用默认语言环境,将String中的所有字符转换为大写
6Stringtrim()返回字符串的副本,忽略前导空白和尾部空白
7booleanequals(Object obj)比较字符串的内容是否相同
8booleanequalsIgnoreCase(String anotherString)与equals()方法类似,忽略大小写
9Stringconcat(String str)将指定字符串连接道此字符串的结尾。等价于用"+"
10intcompareTo(String anotherString)比较两个字符串的大小
11Stringsubstring(int beginIndex)返回一个新的字符串,它是此字符串的从beginIndex开始截取到最后的一个子字符串
12Stringsubstring(int beginIndex,int endIndex)返回一个新字符串,它是此字符串的从beginIndex开始截取到endIndex(不包含)的一个子字符串
13booleanensWith(String suffix)测试此字符串是否以指定的后缀结束
14booleanstartsWith(String prefix)测试此字符串是否以指定的前缀开始
15booleanstartsWith(String prefix,int toffset)测试此字符串从指定索引开始
16booleancontains(CharSequences s)当且仅当此字符串包含指定的char值序列时,返回true
17intindexOf(String str)返回指定子字符串在此字符串中第一次出现处的索引
18intindexOf(String str,int fromIndex)返回指定子字符串在此字符串中第一次出现处的索引,从指定的索引开始
19intlastIndexOf(String str)返回指定子字符串在此字符串中最右边出现处的索引
20intlastIndexOf(String str,int fromIndex)返回指定子字符串在此字符串中最后一次出现处的索引,从指定的索引开始反向搜索
21Stringreplace(char oldChar,char newChar)返回一个新的字符串,它是通过用newChar替换此字符串中出现的所有oldChar得到的
22Stringreplace(CharSequence target,CharSequence replacement)使用指定的字面值替换序列替换此字符串所有匹配字面值目标序列的子字符串
23StringreplaceAll(String regex,String replacement)使用给定的replacement替换此字符串所有匹配给定的正则表达式的子字符串
24StringreplaceFirst(String regex,String replacement)使用给定的replacement替换此字符串匹配给定的正则表达式的第一个子字符串
25booleanmatches(String regex)告知此字符串是否匹配给定的正则表达式
26String[]split(String regex)根据给定的正则表达式的匹配拆分此字符串
27String[]split(String regex,int limit)根据匹配给定的正则表达式来拆分此字符串,最多不超过limit个,如果超过了,剩下的全部都放到最后一个元素中

注:indexOf()和lastIndexOf()方法如果未找到都是返回-1
 

StringBuffer、StringBuilder及其常用方法

源码分析:

String str = new String();//char[] value = new char[0];
String str1 = new String("abc");//char[] value = new char[]{'a','b','c'};

StringBuffer sb1 = new StringBuffer();//char[] value = new char[16];底层创建了一个容量为16的char[]
sb1.append('a');//value[0] = 'a';
sb1.append('b');//value[1] = 'b';

StringBuffer sb2 = new StringBuffer("abc");//char[] value = new char["abc".length() + 16]

扩容问题:如果要添加的数据长度大于底层数组的剩余容量,那就需要扩容底层的数组,默认情况下,扩容为原来容量的2倍+2,同时将原有数组中的元素复制到新的数组中。
 

StringBuffer类的常用方法(跟StringBuilder差不多)

StringBuffer、StringBuilder都是可变的字符串序列,都是对原有的字符串进行操作

序号返回值函数作用
1StringBufferappend(xxx)提供了很多的append()方法,用于进行字符串拼接
2StringBufferdelete(int start,int end)删除指定位置的内容
3StringBufferreplace(int start,int end,Stringstr)把[start,end)位置替换为str
4StringBufferinsert(int offset,xxx)在指定位置插入xxx
5StringBufferreverse()把当前字符序列逆转

还定义了如下方法:

  • public int indexOf(String str);
  • public String substring(int start,int end);
  • public int length();
  • public char charAt(int n)
  • public void setCharAt(int n,char ch);

总结:
 增:append(xxx)
 删:delete(int start,int end)
 改:setCharAt(int n,char ch)
 查:charAt(int n)
 插:insert(int offset,xxx)
 长度:length()
 遍历:for() + charAt()
String、StringBuffer、StringBuilder三者的异同?
 String:不可变的字符序列;底层使用char[]存储。
 StringBuffer:可变的字符序列;线程安全的,效率低;底层使用char[]存储。
 StringBuilder:可变的字符序列;线程不安全的,效率高;底层使用char[]存储。
String、StringBuffer、StringBuilder三者效率:StringBuilder > StringBuffer > String。
线程中涉及安全问题的时候优先使用StringBuffer,不涉及操作共享数据的时候使用StringBuilder。
 

String与其他类型的常见转换

String与基本数据类型、包装类之间的转换

1、String – > 基本数据类型、包装类:调用包装类的parseXxx(str)

String str1 = "123";
int num = Integer.parseInt(str1);

2、基本数据类型、包装类-- >String:调用String重载的valueOf(数据类型)

String str = String.valueOf(num);
//或
String str = num + "";

String与字符数组之间的转换

1、字符数组 – > String:调用String的toCharArray()方法

String str = "abc123";
Char[] charArray = str.toCharArray();

2、String – > 字符数组:直接调用String的构造器即可

char[] arr = new char[]{'h','e','l','l','o'};
String str = new String(arr);

String与字节数组的转换

编码:字符串 – > 字节
解码:字节 – > 字符串
注:如果不想在编解码过程中出现乱码,应该指定同一编码集解码集进行编解码
1、String – > 字节数组(编码):调用String的getBytes()方法

String str = "abc123";
byte[] bytes = str.getBytes();//不加参数使用默认的字符集进行编码
//bytes为[97,98,99,49,50,51]

2、字节数组 – > String(解码):直接调用String的构造器就行

byte[] bytes = {97,98,99,49,50,51};
String str = new String(bytes);

 

二、JDK 8之前的日期时间API

System的一个静态方法currentTimeMillis():

long time = System.currentTimeMillis();
//返回当前时间与1970年0分0秒之间以毫秒为单位的时间差
//称为时间戳

Date类

java.util.Date类

  | - - -java.sql.Date类

1、两个构造器的使用(java.util.Date)
 >构造器一:创建一个对应当前时间的Date对象;
 >构造器二:创建指定毫秒数的Date对象
2、两个方法的使用
 >toString():显示当前的年月日、时分秒。
 >getTime():获取当前Date对象对应的时间戳

//构造器一:java.util.Date,创建一个对应当前时间的Date对象
Date date1 = new Date();
System.out.println(date1.toString());
System.out.println(date1.getTime());

//构造器二:创建指定毫秒数的Date对象
Date date2 = new Date(155032334432L);
System.out.println(date2.toString());//此处返回155032334432L毫秒对应的年月日、时分秒

java.sql.Date类:是数据库中使用的日期类型的类

java.sql.Date date = new java.sql.Date(2323425452345L);
System.out.println(date.toString());//仅返回年月日

补充:将java.util.Date对象转换为java.sql.Date对象:

java.util.Date date1 = new java.util.Date();
java.sql.Date date2 = new java.sql.Date(date1.getTime());

 

Calendar类(抽象类)

一、实例化:
 1、创建其子类(GregorianCalendar)的对象。
 2、调用其静态方法getInstance()。

Calendar calendar = Calendar.getInstance();

二、常用方法

  1. get() int days = Calendar.get(Calendar.DAY_OF_MONTH)//获取这是这个月的第几天
  2. set() int days = Calendar.set(Calendar.DAY_OF_MONTH,22)//把当前时间设置成这个月的第22天
  3. add() int days = Calendar.add(Calendar.DAY_OF_MONTH,-3)//把当前天数减3天
  4. getTime() Date date= Calendar.getTime()//Calendar -- > date
  5. setTime()
Date date = new Date();
Calendar.setTime(date)//Date --> 日历类

注意

获取月份时:一月是0,二月是1,一次类推,12月是11
获取星期时:周日是1,周二是2,…,周六是7。

 

SimpleDateFormat类

SimpleDateFormat的使用:SimpleDateFormat对日期Date类的格式化和解析
1、格式化:日期 - - > 字符串

//使用空参构造器进行格式化
SimpleDateFormat sdf = new SimpleDateFormat();
//格式化 日期 -》 字符串
Date date = new Date();
String str = sdf.format(date);

//使用带参数的构造器进行格式化
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String str = sdf.format();//2020-06-30 15:02:22

2、解析:字符串 - - > 日期

SimpleDateFormat sdf = new SimpleDateFormat();
String str = "19-12-02 下午14:57";
Date date = sdf.parse(str);

 

三、JDK 8中新日期时间API

LocalDate、LocalTime、LocalDateTime

LocalDate、LocalTime、LocalDateTime都具有不可变性。

public class LocalDateTimeTest {
    public static void main(String[] args) {
        LocalDate localDate = LocalDate.now();
        LocalDateTime localDateTime = LocalDateTime.now();
        LocalTime localTime = LocalTime.now();
        System.out.println(localDate);//当前日期
        System.out.println(localDateTime);//当前日期时间
        System.out.println(localTime);//当前时间
    }
}

常用方法:

序号方法描述
1now()/now(Zoneld zone)静态方法,根据当前时间创建对象/指定时区的对象
2of()静态方法,根据指定日期/时间创建对象
3getDayOfMonth()/getDayOfYear()获得月份天数(1-31)/获得年份天数(1-366)
4getDayOfWeek()获得星期几(返回一个DayOfWeek枚举值)
5getMonth()获得月份,返回一个Month枚举值
6getMonthValue()/getYear()获得月份(1-12)/获得年份
7getHour()/getMinute()/getSecond()获得当前对象对应的小时、分钟、秒
8withDayOfMonth()/withDayOfYear()/withMonth/withYear()将月份天数、年份天数、月份、年份、修改为指定的值并返回新的对象
9plusDays(),plusWeeks(),plusMonths(),plusYears(),plusHours()向当前对象添加几天、几周、几个月、几年、几小时
10minusMonths()/minusWeeks()/minusDays()/minusYears()/minusHours()从当前对象减去几月、几周、几天、几年、几小时

 

Instant(瞬时)

public class InstantTest {
    public static void main(String[] args) {
        //now()获取本初子午线对应的标准时间
        Instant instant = Instant.now();
        System.out.println(instant);
        //添加时间的偏移量,例如北京与本初子午线有8个小时的时差
        OffsetDateTime offsetDateTime = instant.atOffset(ZoneOffset.ofHours(8));
        System.out.println(offsetDateTime);
        //获取时间戳
        long l = instant.toEpochMilli();
        System.out.println(l);
        //2020-06-30T08:39:00.757Z;获取毫秒数对应的顺时时间点
        Instant instant1 = instant.ofEpochMilli(1593506340757L);
        System.out.println(instant1);
    }
}

 

DateTimeFormatter

格式化解析日期、时间,类似于SimpleDateFormat。

public class DateTimeFormatterTest {
    public static void main(String[] args) {
        //方式一:预定义的标准格式
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
        //格式化。日期 --> 字符串
        LocalDateTime localDateTime = LocalDateTime.now();
        String str1 = dateTimeFormatter.format(localDateTime);
        System.out.println(str1);//2020-06-30T16:51:23.2383483
        System.out.println(localDateTime);//2020-06-30T16:51:23.238348300
        //解析。 字符串 --> 日期
        String str = "2020-06-30T16:47:36.878030900";
        TemporalAccessor parse = dateTimeFormatter.parse("2020-06-30T16:47:36.8780309");
        System.out.println(parse);//{},ISO resolved to 2020-06-30T16:47:36.878030900

        //方式二:本地化相关的格式
        DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM);
        //格式化
        LocalDateTime localDateTime1 = LocalDateTime.now();
        String str2 = dateTimeFormatter1.format(localDateTime1);
        System.out.println(str2);//2020年6月30日 下午5:01:40

        //方式三:自定义的格式
        DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ofPattern("yy-MM-dd hh:mm:ss");
        //格式化
        String format = dateTimeFormatter2.format(LocalDateTime.now());
        System.out.println(format);//20-06-30 05:06:16
        //解析
        TemporalAccessor parse1 = dateTimeFormatter2.parse("20-06-30 05:06:16");
        System.out.println(parse1);
        //{HourOfAmPm=5, MilliOfSecond=0, MinuteOfHour=6, NanoOfSecond=0, MicroOfSecond=0, SecondOfMinute=16},ISO resolved to 2020-06-30
    }
}

与传统日期处理的转换

To遗留类From遗留类
java.time.Instant与java.util.DateDate.from(instant)date.toInstant()
java.time.Instant与java.sql.TimestampTimestamp.from(instant)timestamp.toInstant
java.time.ZonedDateTime与java.util.GregorianCalendarGregorianCalendar.from(zonedDateTime)cal.toZonedDateTime()
java.time.LocalDate与java.sql.TimeDate.valueOf(localDate)date.toLocalDate()
java.time.LocalTime与java.sql.TimeDate.valueOf(localDate)date.toLocalTime()
java.time.LocalDateTime与java.sql.TimestampTimestamp.value(localDateTime)timestamp.toLocalDateTime()
java.time.Zoneld与java.util.TimeZoneTimezone.getTimeZone(id)timeZone.toZoneId()
java.time.format.DateTimeFormatter与java.text.DateFormatformatter.toFormat()

 
 

四、Java比较器

通过实现Comparable、Comparator接口的方式来比较对象的大小。

Comparable接口(自然排序)

  • String、包装类等实现了Comparable接口,重写了compareTo()方法,实现了比较对象大小的功能。
  • String、包装类重写compareTo()方法以后,默认进行从小到大的方式排序
  • 重写compareTo()的规则:
      1.如果当前对象this大于形参对象obj,则返回正整数;
      2.如果当前对象this小于形参对象obj,则返回负整数;
      3.如果当前对象this等于形参对象obj,则返回0。
  • 对于自定义类来说,如果需要排序,就让自定义类实现Comparable接口,重写compareTo()方法,在compareTo()方法中指明排序的规则(按照哪一个属性排序)。

Comparator接口(定制排序)

当java.lang.Comparable接口的排序规则不适合当前操作的时候,可以采用定制排序。
排序策略:
  重写compare(Object o1,Object o2)方法,比较o1和o2的大小:
  如果方法返回正整数,则表示o1大于o2;
  如果方法返回0,则表示o1等于o2;
  如果方法返回负整数,则表示o1小于o2。
例如:

String[] arr = new String[]{"AA","CC","KK","GG","JJ","DD"};
Arrays.sort(new Comparator(){
	//按照字符串从大到小排序
	@Override
	compare(Object o1,Object o2){
		if(o1 instanceof String && o2 instanceof String){
			String s1 = (String)o1;
			String s2 = (String)o2;
			return -s1.compareTo(s2);
		}
		throws new RuntimeException("输入的数据类型不一致");
	}
})//匿名对象

Comparable接口与Comparator的使用对比

  • Comparable接口的方式一旦确定,保证Comparable接口实现类的对象在任何位置都可以比较大小;
  • Comparator接口属于临时性的比较。
     

五、System类

System系统类,定义的基本上都是一些静态方法,相当于工具类了。

  • native long currentTimeMillis():获取时间戳
  • void exit(int status):返回0代表正常,返回1代表异常退出
  • void gc()://请求系统进行垃圾回收,系统何时回收,取决于系统。
  • String getProperty(String key) :该方法的作用是获得系统中属性名为Key的属性对应的值。系统中常见的属性名以及属性的作用如下表所示:
属性名属性说明
java.versionJava运行时环境版本
java.homeJava安装目录
os.name操作系统的名称
os.version操作系统的版本
user.name用户的账户名称
user.home用户的主目录
user.dir用户当前工作目录
        String javaVersion = System.getProperty("java.version");
        String javaHome = System.getProperty("java.home");
        String osName = System.getProperty("os.name");
        String osVersion = System.getProperty("os.version");
        String userName = System.getProperty("user.name");
        String userHome = System.getProperty("user.home");
        String userDir = System.getProperty("user.dir");
        Properties properties = System.getProperties();

 

六、Math类

java.lang.Math类提供了一系统静态方法用于科学计算。

  • abs():绝对值
  • acos(),asin(),atan(),cos(),sin(),tan():三角函数
  • sqrt():平方根
  • pow(double a,double b):a的b次幂
  • log():自然对数
  • exp():e为底指数
  • max(double a,double b):最大值
  • min(double a,double b):最小值
  • random():返回0.0到1.0的随机数[0.0,1.0)
  • long round(double a):double型数据a转换为long型(四舍五入)
  • toDegrees(double angrad):弧度–》角度
  • toRadians(double angdeg):角度–》弧度

七、BigInteger与BigDecimal

BigInteger类(整型)

java.math包的BigInteger类可以表示不可变的任意精度大小的整数。
BigInteger提供所有Java的基本整数操作符的对应物,并提供java.lang.Math的所有相关方法。另外,BigInteger还提供模算术、GCD计算、质数测试、素数生成、位操作以及一些其他操作。
构造器:

  • BigInteger(String val):根据字符串构建BigInteger对象

常用方法:

序号返回值函数作用
1BigIntegerabs()返回此BigInteger的绝对值的BigInteger
2BigIntegeradd(BigInteger val)返回其值为(this+val)的BigInteger
3BigIntegersubtract(BigInteger val)返回其值为(this-val)的BigInteger
4BigIntegermultiply(BigInteger val)返回其值为(this*val)的BigInteger
5BigIntegerdivide(BigInteger val)返回其值为(this/val)的BigInteger。整数相除只保留整数部分
6BigIntegerremainder(BigInteger val)返回其值为(this%val)的BigInteger
7BigInteger[]divideAndRemainder(BigInteger val)返回包含(this/val)后跟(this%val)的两个BigInteger的数组
8BigIntegerpow(int exponent)返回其值为(this^exponent)的BigInteger

 

BigDecimal(浮点型)

计算中要求精度比较高的时候使用java.math.BigDecimal类。

构造器

  • public BigDecimal(double val)
  • public BigDecimal(String val)

常用方法

  • public BigDecimal add(BigDecimal augend)
  • public BigDecimal subtract(BigDecimal sutrahend)
  • public BigDecimal multiply(BigDecimal multiplicand)
  • public BigDecimal divide(BigDecimal divisor,int scale,int roundingMode)
BigInteger bi = new BigInteger("2342347923479283472983742");//任意大的整数
BigDecimal bd = new BigDecimal("12434.324");
BigDecimal bd2 = new BigDecimal("11");
System.out.println(bd.divide(bd2,BigDecimal.ROUND_HALF_UP));
System.out.println(bd.divide(bd2,25,BigDecimal.ROUND_HALF_UP));//小数点后精确到25位(任意精度)

八、枚举类

1、枚举类的使用:

  • 枚举类的理解:类的对象只有有限个且确定的,我们称此类为枚举类
  • 当需要定义一组常量时,强烈建议使用枚举类
  • 如果枚举类中只有一个对象,则可以作为单例模式的实现方法

2、如何定义枚举类:

  • jdk5.0之前,自定义枚举类
class Season{
	//1.声明Season对象的属性:private final修饰
	private final String seasonName;
	private final String seasonDesc;
	//2.私有化类的构造器,并给对象属性赋值
	private Season(String seasongName,String seasonDesc){
		this.seasonName = seasonName;
		this.seasonDesc = seasonDesc;
	}
	//3.提供当前枚举类的多个对象
	public static final Season SPRING = new Season("春天","春暖花开");
	public static final Season SUMMER = new Season("夏天","夏日炎炎");
	public static final Season AUTUMN = new Season("秋天","秋意盎然");
	public static final Season WINTER = new Season("冬天","诗意盎然");
	//4.可以根据诉求增加别的内容例如get()方法、重写toString()方法
}
  • jdk5.0 使用enum关键字定义枚举类
enum Season{
	//1、提供当前枚举类的对象,多个对象之间用","隔开,末尾对象";"结束
	SPRING("春天","春暖花开"),//上来就需要先写枚举类的对象
	SUMMER("夏天","夏日炎炎"),
	AUTUMN("秋天","秋意盎然"),
	WINTER("冬天","诗意盎然");
	//2.声明Season对象的属性:private final修饰
	private final String seasonName;
	private final String seasonDesc;
	//3.私有化类的构造器,并给对象属性赋值
	private Season(String seasongName,String seasonDesc){
		this.seasonName = seasonName;
		this.seasonDesc = seasonDesc;
	}
	//4.可以根据诉求增加别的内容例如get()方法
}

说明:定义的枚举类默认继承于java.lang.Enum类

3、Enum类的主要方法

  • values()方法:返回枚举类型的对象数组。该方法可以遍历所有的枚举值
  • valueOf(String str):可以把一个字符串转为对应的枚举类对象。要求字符串必须是枚举类对象的“名字”。如不是,会有运行时异常IllegalArgumentException
  • toString():返回当前枚举类对象常量的名称

4、使用enum关键字定义的枚举类实现接口的情况

情况一:实现接口,在enum类中实现抽象方法;
情况二:让枚举类的对象分别实现接口中的抽象方法。

例如:

interface Info{
	void show();
}

enum Season implements Info{
	SPRING("春天","春暖花开"){
		@override
		public void show(){
			System.out.println("春天在哪里?");
		}
	},
	SUMMER("夏天","夏日炎炎"){
		public void show(){
			//可在此处分别实现各自的抽象方法	
		}
	},
	AUTUMN("秋天","秋意盎然"){},
	WINTER("冬天","诗意盎然"){};
	private final String seasonName;
	private final String seasonDesc;
	private Season(String seasongName,String seasonDesc){
		this.seasonName = seasonName;
		this.seasonDesc = seasonDesc;
	}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Java常用类总结 的相关文章

  • MySQL索引分类

    主键索引 xff1a 设定为主键后数据库会自动建立索引 xff0c innodb为聚簇索引 单值索引 xff1a 即一个索引只包含单个列 xff0c 一个表可以有多个单列索引 唯一索引 xff1a 索引列的值必须唯一 xff0c 但允许有空
  • Docker 部署 MySQL 一主多从

    主从复制的原理 xff1a 1 主库 xff1a 创建一个有权访问binlog日志的从库账号 xff0c 配置需要主从复制的库 有写操作时 xff0c 可以将写操作或者写操作之后的数据记录到日志文件中 binlog 通过一个线程通知需要同步
  • Java笔记(8)——重载(Overload)与重写(Override)的区别

    1 重写 xff08 Override xff09 重写是子类对允许访问的父类的方法进行重新编写的过程 xff0c 方法名 返回值和参数列表不能变 xff0c 方法中的内容可以变化 特点就是 xff1a 子类可以根据自己的需要对父类的方法进
  • ShardingSphere介绍

    官网 xff1a https shardingsphere apache org index zh html 文档 xff1a https shardingsphere apache org document 5 1 1 cn overvi
  • ShardingSphere-JDBC读写分离

    基于之前搭建的mysql主从读写分离使用ShardingSphere JDBC实现读写分离 参考文章 xff1a Docker 部署 MySQL 一主多从 书启秋枫的博客 CSDN博客 CREATE DATABASE mydb2 USE m
  • ShardingSphere-JDBC垂直分片

    什么是数据分片 xff1f 简单来说 xff0c 就是指通过某种特定的条件 xff0c 将我们存放在同一个数据库中的数据分散存放到多个数据库 xff08 主机 xff09 上面 xff0c 以达到分散单台设备负载的效果 数据的切分 xff0
  • ShardingSphere-JDBC水平分片

    项目中可以使用ShardingSphere JDBC将数据存到不同库的表中 一 准备服务器 服务器规划 xff1a 使用docker方式创建如下容器 主服务器 xff1a 容器名server order0 xff0c 端口3310从服务器
  • ShardingSphere-JDBC绑定表

    一 什么是绑定表 指分片规则一致的一组分片表 使用绑定表进行多表关联查询时 xff0c 必须使用分片键进行关联 xff0c 否则会出现笛卡尔积关联或跨库关联 xff0c 从而影响查询效率 例如 xff1a t order 表和 t orde
  • ShardingSphere-JDBC广播表

    一 什么是广播表 指所有的分片数据源中都存在的表 xff0c 表结构及其数据在每个数据库中均完全一致 适用于数据量不大且需要与海量数据的表进行关联查询的场景 xff0c 例如 xff1a 字典表 广播具有以下特性 xff1a xff08 1
  • 01_JUC概述

    1 JUC是什么 xff1f 在 Java 5 0 提供了 java util concurrent 简称JUC 包 xff0c 在此包中增加了在并发编程中很常用的工具类 此包包括了几个小的 已标准化的可扩展框架 xff0c 并提供一些功能
  • 02_Lock锁

    首先看一下JUC的重磅武器 锁 xff08 Lock xff09 相比同步锁 xff0c JUC包中的Lock锁的功能更加强大 xff0c 它提供了各种各样的锁 xff08 公平锁 xff0c 非公平锁 xff0c 共享锁 xff0c 独占
  • 03_线程间通信

    面试题 xff1a 两个线程打印 两个线程 xff0c 一个线程打印1 52 xff0c 另一个打印字母A Z打印顺序为12A34B 5152Z xff0c 要求用线程间通信 public class Demo01 public stati
  • 04_并发容器类

    1 重现线程不安全 xff1a List 首先以List作为演示对象 xff0c 创建多个线程对List接口的常用实现类ArrayList进行add操作 public class NotSafeDemo public static void
  • Java笔记(10)——异常处理

    1 Java异常 Java运行时发生异常可以分为两类 xff1a Error xff1a JVM系统内部错误 资源耗尽等问题产生的异常 Exception xff1a 编程错误或偶然的外在因素导致的 2 常见的异常 2 1 RuntimeE
  • mariadb 数据库连接使用

    今天测试了使用mariadb的使用 xff0c 我使用的springboot 43 mariadb 来操作数据库 xff0c 和以前的代码基本一样 xff0c 就数据变成了mariadb xff0c 驱动还是使用mysql的 pom 文件如
  • 05_JUC强大的辅助类

    JUC的多线程辅助类非常多 xff0c 这里我们介绍三个 xff1a CountDownLatch xff08 倒计数器 xff09 CyclicBarrier xff08 循环栅栏 xff09 Semaphore xff08 信号量 xf
  • 06_Callable接口

    Thread 类 Runnable 接口使得多线程编程简单直接 但Thread类和Runnable接口都不允许声明检查型异常 xff0c 也不能定义返回值 没有返回值这点稍微有点麻烦 不能声明抛出检查型异常则更麻烦一些 public voi
  • 07_阻塞队列(BlockingQueue)

    目录 1 什么是BlockingQueue 2 认识BlockingQueue 3 代码演示 栈与队列概念 栈 Stack xff1a 先进后出 xff0c 后进先出 队列 xff1a 先进先出 1 什么是BlockingQueue 在多线
  • 08_ThreadPool线程池

    1 架构说明 Java中的线程池是通过Executor框架实现的 xff0c 该框架中用到了Executor xff0c ExecutorService xff0c ThreadPoolExecutor这几个类 Executor接口是顶层接
  • Docker 安装 elasticsearch、kibana、ik

    一 安装elasticsearch 1 拉取 elasticsearch 镜像 docker pull elasticsearch 7 6 2 2 创建 elasticsearch 容器 docker run name elasticsea

随机推荐

  • ElasticSearch 中 FieldType 详解

    date float long都是不能够被拆分的 64 Field type 61 FieldType Text analyzer 61 34 ik max word 34 表示该字段是一个文本 xff0c 并作最大程度拆分 xff0c 默
  • SpringBoot 使用 ElasticSearch 编程测试

    1 在 pom xml 准备依赖 lt dependency gt lt groupId gt org projectlombok lt groupId gt lt artifactId gt lombok lt artifactId gt
  • el-table-column中formatter格式化字典

    el table column中formatter格式化字典 vue 中使用 lt el table column gt 中的 formatter 格式化内容 x1f52e lt template gt lt 列表 gt lt el tab
  • cookie和session详解

    源自 xff1a https www cnblogs com l199616j p 11195667 html xff0c 有删减 另 xff0c cookie session与token的真正区别 xff1a https blog csd
  • 如何理解端到端

    1 非端到端 xff1a 典型的自然语言处理 xff08 Natural Language Processing xff09 过程 xff1a 分词 gt 词性标注 gt 句法分析 gt 语义分析 直至得出结果 多个独立步骤 xff0c 每
  • Java笔记(11)——Collection集合

    0 先创建一个Person类为例 span class token keyword public span span class token keyword class span span class token class name Pe
  • 笔记:QGC使用及姿态环仿真调节方式

    笔记 xff1a QGC使用及姿态环仿真调节方式 打开Gazebo及QGC 进入终端管理员权限 sudo s 在终端打开Gazebo cd Firmware make px4 sitl default gazebo 点击文件夹中的QGC x
  • springboot集成freemarker模板,项目打成jar包到生产环境显示找不到模板文件

    文章目录 一 问题描述二 原始代码三 解决方案四 注意点 一 问题描述 1 使用springboot集成freemarker模版后 xff0c 在本地运行正常 xff1b 打成jar包后到线上测试报如下错误 xff1a 2 原因 xff1a
  • Linux网络设置

    文章目录 引言一 查看网络配置1 查看网络接口信息ifconfig2 修改网络配置文件3 设置网络接口参数 二 主机名称配置文件hostname1 hostname命令2 三种修改主机名的方式2 1 临时修改主机名 xff08 hostna
  • Java中的集合类

    Java中所有的类都位于java util包下 xff0c 主要由两个接口派生出来 分别是Collection xff08 集合 xff09 和Map Collection xff08 映射集合 xff09 xff0c 包含了List和Se
  • 退出VM VirtualBox独占的键盘和鼠标

    今天无意之间点了菜单栏的 热键 鼠标集成 xff0c 结果鼠标被锁在了里面出不来 xff0c 试了好多方法都不行 xff0c 有点奔溃 xff0c 最后发现 右边的Alt 43 Ctrl组合键可以跳出
  • Linux - 第11节 - 网络入门

    目录 1 计算机网络背景 1 1 网络发展 1 2 认识 34 协议 34 2 网络协议初识 2 1 协议分层 2 2 OSI七层模型 2 3 TCP IP五层 xff08 或四层 xff09 模型 3 网络传输基本流程 3 1 同局域网的
  • @PathVariable注解的用法和作用

    64 PathVariable注解的用法和作用 64 PathVariable 映射 URL 绑定的占位符 通过 64 PathVariable 可以将 URL 中占位符参数绑定到控制器处理方法的入参中 URL 中的 xxx 占位符可以通过
  • 最新虚拟机中Ubuntu18.04安装教程(傻瓜教程)

    1 文件和软件下载 下载Ubuntu18 04文件 可以直接点下方的链接下载 Ubuntu18 04安装链接 下载VMware Workstation 笔者这边使用的是VMware Workstation15 5pro xff0c 大家也可
  • optimizer优化器详解

    在机器学习中 xff0c 优化器 xff08 optimizer xff09 是一种用于更新模型参数以最小化训练误差的算法 它可以将损失函数的梯度作为输入 xff0c 并根据该梯度调整模型参数的值 常见的优化器算法包括随机梯度下降 xff0
  • Java创建多线程的四种方式

    一 继承Thread类 1 创建一个继承于Thread类的子类 2 重写Thread类的run gt 将此线程执行的操作声明在run 中 3 创建Thread类的子类的对象 4 通过此对象调用start 启动当前线程 调用当前线程的run
  • MySQL基础

    本单元目标 一 为什么要学习数据库 二 数据库的相关概念 DBMS DB SQL 三 数据库存储数据的特点 四 初始MySQL MySQL产品的介绍 MySQL产品的安装 MySQL服务的启动和停止 MySQL服务的登录和退出 MySQL的
  • Thread类中的常用方法

    Thread类中的常用方法 xff08 学习总结 xff09 xff1a 序号函数作用1start 启动当前线程 xff1b 调用当前线程的run 2run 通常需要重写Thread类中的此方法 xff0c 将创建的线程要执行的操作生命在此
  • 线程的同步机制

    方式一 xff1a 同步代码块 span class token keyword synchronized span span class token punctuation span 同步监视器 span class token punc
  • Java常用类总结

    一 字符串相关的类 String类及其常用方法 1 String声明为final的 xff0c 不可被继承 2 String实现了Serializable接口 xff1a 表示字符串是支持序列化的 xff1b 实现了Comparable接口