热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Java开发入门与实战!能让程序员头痛不已

3.金额数值计算精度的坑看下这个浮点数计算的例子吧:publicclassDoubleTest{publicstaticvoidmain(String[]args

3.金额数值计算精度的坑

看下这个浮点数计算的例子吧:

public class DoubleTest {public static void main(String[] args) {System.out.println(0.1+0.2);System.out.println(1.0-0.8);System.out.println(4.015*100);System.out.println(123.3/100);double amount1 = 3.15;double amount2 = 2.10;if (amount1 - amount2 == 1.05){System.out.println("OK");}}
}

运行结果:

0.30000000000000004
0.19999999999999996
401.49999999999994
1.2329999999999999

可以发现,结算结果跟我们预期不一致,其实是因为计算机是以二进制存储数值的,对于浮点数也是。对于计算机而言,0.1无法精确表达,这就是为什么浮点数会导致精确度缺失的。因此,金额计算,一般都是用BigDecimal 类型


对于以上例子,我们改为BigDecimal,再看看运行效果:

System.out.println(new BigDecimal(0.1).add(new BigDecimal(0.2)));
System.out.println(new BigDecimal(1.0).subtract(new BigDecimal(0.8)));
System.out.println(new BigDecimal(4.015).multiply(new BigDecimal(100)));
System.out.println(new BigDecimal(123.3).divide(new BigDecimal(100)));

运行结果:

0.3000000000000000166533453693773481063544750213623046875
0.1999999999999999555910790149937383830547332763671875
401.49999999999996802557689079549163579940795898437500
1.232999999999999971578290569595992565155029296875

发现结果还是不对,其实,使用 BigDecimal 表示和计算浮点数,必须使用字符串的构造方法来初始化 BigDecimal,正例如下:

public class DoubleTest {public static void main(String[] args) {System.out.println(new BigDecimal("0.1").add(new BigDecimal("0.2")));System.out.println(new BigDecimal("1.0").subtract(new BigDecimal("0.8")));System.out.println(new BigDecimal("4.015").multiply(new BigDecimal("100")));System.out.println(new BigDecimal("123.3").divide(new BigDecimal("100")));}
}

在进行金额计算,使用BigDecimal的时候,我们还需要注意BigDecimal的几位小数点,还有它的八种舍入模式哈


4. static静态变量依赖spring实例化变量,可能导致初始化出错

之前看到项目有类似的代码。静态变量依赖于spring容器的bean。

private static SmsService smsService = SpringContextUtils.getBean(SmsService.class);

这个静态的smsService有可能获取不到的,因为类加载顺序不是确定的,正确的写法可以这样,如下:

private static SmsService smsService =null;//使用到的时候采取获取public static SmsService getSmsService(){if(smsService==null){smsService = SpringContextUtils.getBean(SmsService.class);}return smsService;}

5. FileReader默认编码导致乱码问题

public class FileReaderTest {public static void main(String[] args) throws IOException {Files.deleteIfExists(Paths.get("jay.txt"));Files.write(Paths.get("jay.txt"), "你好,捡田螺的小男孩".getBytes(Charset.forName("GBK")));System.out.println("系统默认编码:"+Charset.defaultCharset());char[] chars = new char[10];String content = "";try (FileReader fileReader = new FileReader("jay.txt")) {int count;while ((count = fileReader.read(chars)) != -1) {content += new String(chars, 0, count);}}System.out.println(content);}
}

运行结果:

系统默认编码:UTF-8
���,�����ݵ�С�к�

从运行结果,可以知道,系统默认编码是utf8,demo中读取出来,出现乱码了。为什么呢?


FileReader 是以当前机器的默认字符集来读取文件的,如果希望指定字符集的话,需要直接使用 InputStreamReader 和 FileInputStream。


正例如下:

public class FileReaderTest {public static void main(String[] args) throws IOException {Files.deleteIfExists(Paths.get("jay.txt"));Files.write(Paths.get("jay.txt"), "你好,捡田螺的小男孩".getBytes(Charset.forName("GBK")));System.out.println("系统默认编码:"+Charset.defaultCharset());char[] chars = new char[10];String content = "";try (FileInputStream fileInputStream = new FileInputStream("jay.txt");InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, Charset.forName("GBK"))) {int count;while ((count = inputStreamReader.read(chars)) != -1) {content += new String(chars, 0, count);}}System.out.println(content);}
}

6. Integer缓存的坑

public class IntegerTest {public static void main(String[] args) {Integer a = 127;Integer b = 127;System.out.println("a==b:"+ (a == b));Integer c = 128;Integer d = 128;System.out.println("c==d:"+ (c == d));}
}

运行结果:

a==b:true
c==d:false

为什么Integer值如果是128就不相等了呢?编译器会把 Integer a = 127 转换为 Integer.valueOf(127)。 我们看下源码。

public static Integer valueOf(int i) {if (i >&#61; IntegerCache.low && i <&#61; IntegerCache.high)return IntegerCache.cache[i &#43; (-IntegerCache.low)];return new Integer(i);}

可以发现&#xff0c;i在一定范围内&#xff0c;是会返回缓存的。


默认情况下呢&#xff0c;这个缓存区间就是[-128, 127]&#xff0c;所以我们业务日常开发中&#xff0c;如果涉及Integer值的比较&#xff0c;需要注意这个坑哈。还有呢&#xff0c;设置 JVM 参数加上 -XX:AutoBoxCacheMax&#61;1000&#xff0c;是可以调整这个区间参数的&#xff0c;大家可以自己试一下哈



7. 使用ThreadLocal&#xff0c;线程重用导致信息错乱的坑

使用ThreadLocal缓存信息&#xff0c;有可能出现信息错乱的情况。看下这个例子吧。

private static final ThreadLocal currentUser &#61; ThreadLocal.withInitial(() -> null);&#64;GetMapping("wrong")
public Map wrong(&#64;RequestParam("userId") Integer userId) {//设置用户信息之前先查询一次ThreadLocal中的用户信息String beforeUser &#61; Thread.currentThread().getName() &#43; ":" &#43; currentUser.get();//设置用户信息到ThreadLocalcurrentUser.set(userId);//设置用户信息之后再查询一次ThreadLocal中的用户信息String afterUser &#61; Thread.currentThread().getName() &#43; ":" &#43; currentUser.get();//汇总输出两次查询结果Map map &#61; new HashMap();map.put("before", beforeUser);map.put("after", afterUser);return map;
}

按理说&#xff0c;每次获取的beforeUser应该都是null&#xff0c;但是呢&#xff0c;程序运行在 Tomcat 中&#xff0c;执行程序的线程是 Tomcat 的工作线程&#xff0c;而 Tomcat 的工作线程是基于线程池的。


线程池会重用固定的几个线程&#xff0c;一旦线程重用&#xff0c;那么很可能首次从 ThreadLocal 获取的值是之前其他用户的请求遗留的值。这时&#xff0c;ThreadLocal 中的用户信息就是其他用户的信息。


把tomcat的工作线程设置为1

server.tomcat.max-threads&#61;1

用户1&#xff0c;请求过来&#xff0c;会有以下结果&#xff0c;符合预期&#xff1a;

用户2请求过来&#xff0c;会有以下结果&#xff0c;不符合预期&#xff1a;

因此&#xff0c;使用类似 ThreadLocal 工具来存放一些数据时&#xff0c;需要特别注意在代码运行完后&#xff0c;显式地去清空设置的数据&#xff0c;正例如下&#xff1a;

&#64;GetMapping("right")
public Map right(&#64;RequestParam("userId") Integer userId) {String beforeUser &#61; Thread.currentThread().getName() &#43; ":" &#43; currentUser.get();currentUser.set(userId);try {String afterUser &#61; Thread.currentThread().getName() &#43; ":" &#43; currentUser.get();Map map &#61; new HashMap();map.put("before", beforeUser);map.put("after", afterUser);return map;} finally {//在finally代码块中删除ThreadLocal中的数据&#xff0c;确保数据不串currentUser.remove();}
}

8. 疏忽switch的return和break

这一点严格来说&#xff0c;应该不算坑&#xff0c;但是呢&#xff0c;大家写代码的时候&#xff0c;有些朋友容易疏忽了。

/** 关注公众号&#xff1a;* 捡田螺的小男孩*/
public class SwitchTest {public static void main(String[] args) throws InterruptedException {System.out.println("testSwitch结果是&#xff1a;"&#43;testSwitch("1"));}private static String testSwitch(String key) {switch (key) {case "1":System.out.println("1");case "2":System.out.println(2);return "2";case "3":System.out.println("3");default:System.out.println("返回默认值");return "4";}}
}

输出结果&#xff1a;

测试switch
1
2
testSwitch结果是&#xff1a;2

switch 是会沿着case一直往下匹配的&#xff0c;知道遇到return或者break。 所以&#xff0c;在写代码的时候留意一下&#xff0c;是不是你要的结果。


9. Arrays.asList的几个坑


9.1 基本类型不能作为 Arrays.asList方法的参数&#xff0c;否则会被当做一个参数。

public class ArrayAsListTest {public static void main(String[] args) {int[] array &#61; {1, 2, 3};List list &#61; Arrays.asList(array);System.out.println(list.size());}
}

运行结果&#xff1a;

1

Arrays.asList源码如下&#xff1a;

public static List asList(T... a) {return new ArrayList<>(a);
}

9.2 Arrays.asList 返回的 List 不支持增删操作。

public class ArrayAsListTest {public static void main(String[] args) {String[] array &#61; {"1", "2", "3"};List list &#61; Arrays.asList(array);list.add("5");System.out.println(list.size());}
}

运行结果&#xff1a;

Exception in thread "main" java.lang.UnsupportedOperationExceptionat java.util.AbstractList.add(AbstractList.java:148)at java.util.AbstractList.add(AbstractList.java:108)at object.ArrayAsListTest.main(ArrayAsListTest.java:11)

Arrays.asList 返回的 List 并不是我们期望的 java.util.ArrayList&#xff0c;而是 Arrays 的内部类ArrayList。内部类的ArrayList没有实现add方法&#xff0c;而是父类的add方法的实现&#xff0c;是会抛出异常的呢。


9.3 使用Arrays.asLis的时候&#xff0c;对原始数组的修改会影响到我们获得的那个List

public class ArrayAsListTest {public static void main(String[] args) {String[] arr &#61; {"1", "2", "3"};List list &#61; Arrays.asList(arr);arr[1] &#61; "4";System.out.println("原始数组"&#43;Arrays.toString(arr));System.out.println("list数组" &#43; list);}
}

运行结果&#xff1a;

原始数组[1, 4, 3]
list数组[1, 4, 3]

从运行结果可以看到&#xff0c;原数组改变&#xff0c;Arrays.asList转化来的list也跟着改变啦&#xff0c;大家使用的时候要注意一下哦&#xff0c;可以用new ArrayList(Arrays.asList(arr))包一下的。


10. ArrayList.toArray() 强转的坑

public class ArrayListTest {public static void main(String[] args) {List list &#61; new ArrayList(1);list.add("公众号&#xff1a;捡田螺的小男孩");String[] array21 &#61; (String[])list.toArray();//类型转换异常}
}

因为返回的是Object类型&#xff0c;Object类型数组强转String数组&#xff0c;会发生ClassCastException。解决方案是&#xff0c;使用toArray()重载方法toArray(T[] a)

String[] array1 &#61; list.toArray(new String[0]);//可以正常运行

11. 异常使用的几个坑


11.1 不要弄丢了你的堆栈异常信息

public void wrong1(){try {readFile();} catch (IOException e) {//没有把异常e取出来&#xff0c;原始异常信息丢失 }
}public void wrong2(){try {readFile();} catch (IOException e) {//只保留了异常消息&#xff0c;栈没有记录啦log.error("文件读取错误, {}", e.getMessage());}
}

正确的打印方式&#xff0c;应该酱紫

public void right(){try {readFile();} catch (IOException e) {//把整个IO异常都记录下来&#xff0c;而不是只打印消息log.error("文件读取错误", e);}
}

11.2 不要把异常定义为静态变量

public void testStaticExeceptionOne{try {exceptionOne();} catch (Exception ex) {log.error("exception one error", ex);}try {exceptionTwo();} catch (Exception ex) {log.error("exception two error", ex);}
}private void exceptionOne() {//这里有问题throw Exceptions.ONEORTWO;
}private void exceptionTwo() {//这里有问题throw Exceptions.ONEORTWO;
}

exceptionTwo抛出的异常&#xff0c;很可能是exceptionOne的异常哦。正确使用方法&#xff0c;不是静态变量&#xff0c;而是应该new 一个出来。

private void exceptionTwo() {throw new BusinessException("业务异常", 0001);
}

11.3 生产环境不要使用e.printStackTrace();

public void wrong(){try {readFile();} catch (IOException e) {//生产环境别用它e.printStackTrace();}
}

因为它占用太多内存&#xff0c;造成锁死&#xff0c;并且&#xff0c;日志交错混合&#xff0c;也不易读。正确使用如下&#xff1a;

//放弃使用e.printStackTrace();
log.error("异常日志正常打印方式",e);

11.4 线程池提交过程中&#xff0c;出现异常怎么办&#xff1f;

public class ThreadExceptionTest {public static void main(String[] args) {ExecutorService executorService &#61; Executors.newFixedThreadPool(10);IntStream.rangeClosed(1, 10).forEach(i -> executorService.submit(()-> {if (i &#61;&#61; 5) {System.out.println("发生异常啦");throw new RuntimeException("error");}System.out.println("当前执行第几:" &#43; Thread.currentThread().getName() );}));executorService.shutdown();}
}

运行结果&#xff1a;

当前执行第几:pool-1-thread-1
当前执行第几:pool-1-thread-2
当前执行第几:pool-1-thread-3
当前执行第几:pool-1-thread-4
发生异常啦
当前执行第几:pool-1-thread-6
当前执行第几:pool-1-thread-7
当前执行第几:pool-1-thread-8
当前执行第几:pool-1-thread-9
当前执行第几:pool-1-thread-10

可以发现&#xff0c;如果是使用submit方法提交到线程池的异步任务&#xff0c;异常会被吞掉的&#xff0c;所以在日常发现中&#xff0c;如果会有可预见的异常&#xff0c;可以采取这几种方案处理&#xff1a;


  • 1.在任务代码try/catch捕获异常
  • 2.通过Future对象的get方法接收抛出的异常&#xff0c;再处理
  • 3.为工作者线程设置UncaughtExceptionHandler&#xff0c;在uncaughtException方法中处理异常
  • 4.重写ThreadPoolExecutor的afterExecute方法&#xff0c;处理传递的异常引用

11.5 finally重新抛出的异常也要注意啦

public void wrong() {try {log.info("try");//异常丢失throw new RuntimeException("try");} finally {log.info("finally");throw new RuntimeException("finally");}
}

一个方法是不会出现两个异常的呢&#xff0c;所以finally的异常会把try的异常覆盖。正确的使用方式应该是&#xff0c;finally 代码块负责自己的异常捕获和处理

public void right() {try {log.info("try");throw new RuntimeException("try");} finally {log.info("finally");try {throw new RuntimeException("finally");} catch (Exception ex) {log.error("finally", ex);}}
}

12.JSON序列化,Long类型被转成Integer类型&#xff01;

public class JSONTest {public static void main(String[] args) {Long idValue &#61; 3000L;Map data &#61; new HashMap<>(2);data.put("id", idValue);data.put("name", "捡田螺的小男孩");Assert.assertEquals(idValue, (Long) data.get("id"));String jsonString &#61; JSON.toJSONString(data);// 反序列化时Long被转为了IntegerMap map &#61; JSON.parseObject(jsonString, Map.class);Object idObj &#61; map.get("id");System.out.println("反序列化的类型是否为Integer&#xff1a;"&#43;(idObj instanceof Integer));Assert.assertEquals(idValue, (Long) idObj);}
}

运行结果&#xff1a;

Exception in thread "main" 反序列化的类型是否为Integer&#xff1a;true
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Longat object.JSONTest.main(JSONTest.java:24)

注意啦&#xff0c;序列化为Json串后&#xff0c;Josn串是没有Long类型呢。而且反序列化回来如果也是Object接收&#xff0c;数字小于Interger最大值的话&#xff0c;给转成Integer啦&#xff01;



13. 使用Executors声明线程池&#xff0c;newFixedThreadPool的OOM问题

ExecutorService executor &#61; Executors.newFixedThreadPool(10);for (int i &#61; 0; i {try {Thread.sleep(10000);} catch (InterruptedException e) {//do nothing}});}

IDE指定JVM参数&#xff1a;-Xmx8m -Xms8m :

运行结果&#xff1a;

我们看下源码&#xff0c;其实newFixedThreadPool使用的是无界队列&#xff01;

public static ExecutorService newFixedThreadPool(int nThreads) {return new ThreadPoolExecutor(nThreads, nThreads,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue());
}public class LinkedBlockingQueue extends AbstractQueueimplements BlockingQueue, java.io.Serializable {.../*** Creates a {&#64;code LinkedBlockingQueue} with a capacity of* {&#64;link Integer#MAX_VALUE}.*/public LinkedBlockingQueue() {this(Integer.MAX_VALUE);}
...
}

newFixedThreadPool线程池的核心线程数是固定的&#xff0c;它使用了近乎于无界的LinkedBlockingQueue阻塞队列。当核心线程用完后&#xff0c;任务会入队到阻塞队列&#xff0c;如果任务执行的时间比较长&#xff0c;没有释放&#xff0c;会导致越来越多的任务堆积到阻塞队列&#xff0c;最后导致机器的内存使用不停的飙升&#xff0c;造成JVM OOM。



14. 直接大文件或者一次性从数据库读取太多数据到内存&#xff0c;可能导致OOM问题

如果一次性把大文件或者数据库太多数据达到内存&#xff0c;是会导致OOM的。所以&#xff0c;为什么查询DB数据库&#xff0c;一般都建议分批。

读取文件的话&#xff0c;一般文件不会太大&#xff0c;才使用Files.readAllLines()。为什么呢&#xff1f;因为它是直接把文件都读到内存的&#xff0c;预估下不会OOM才使用这个吧&#xff0c;可以看下它的源码&#xff1a;

public static List readAllLines(Path path, Charset cs) throws IOException {try (BufferedReader reader &#61; newBufferedReader(path, cs)) {List result &#61; new ArrayList<>();for (;;) {String line &#61; reader.readLine();if (line &#61;&#61; null)break;result.add(line);}return result;}
}

如果是太大的文件&#xff0c;可以使用Files.line()按需读取&#xff0c;当时读取文件这些&#xff0c;一般是使用完需要关闭资源流的哈


15. 先查询&#xff0c;再更新/删除的并发一致性问题

再日常开发中&#xff0c;这种代码实现经常可见&#xff1a;先查询是否有剩余可用的票&#xff0c;再去更新票余量。

if(selectIsAvailable(ticketId){ 1、deleteTicketById(ticketId) 2、给现金增加操作
}else{ return “没有可用现金券”
}

如果是并发执行&#xff0c;很可能有问题的&#xff0c;应该利用数据库更新/删除的原子性&#xff0c;正解如下&#xff1a;

if(deleteAvailableTicketById(ticketId) &#61;&#61; 1){ 1、给现金增加操作
}else{ return “没有可用现金券”
}

16. 数据库使用utf-8存储&#xff0c; 插入表情异常的坑

低版本的MySQL支持的utf8编码&#xff0c;最大字符长度为 3字节&#xff0c;但是呢&#xff0c;存储表情需要4个字节&#xff0c;因此如果用utf8存储表情的话&#xff0c;会报SQLException: Incorrect string value: &#39;\xF0\x9F\x98\x84&#39; for column&#xff0c;所以一般用utf8mb4编码去存储表情。


17. spring事务未生效的坑

日常业务开发中&#xff0c;我们经常跟事务打交道&#xff0c;事务失效主要有以下几个场景&#xff1a;


  • 底层数据库引擎不支持事务
  • 在非public修饰的方法使用
  • rollbackFor属性设置错误
  • 本类方法直接调用
  • 异常被try…catch吃了&#xff0c;导致事务失效。

其中&#xff0c;最容易踩的坑就是后面两个&#xff0c;注解的事务方法给本类方法直接调用&#xff0c;伪代码如下&#xff1a;

public class TransactionTest{public void A(){//插入一条数据//调用方法B (本地的类调用&#xff0c;事务失效了)B();}### 最后**经过日积月累&#xff0c; 以下是小编归纳整理的深入了解Java虚拟机文档&#xff0c;希望可以帮助大家过关斩将顺利通过面试。**
由于整个文档比较全面&#xff0c;内容比较多&#xff0c;篇幅不允许&#xff0c;下面以截图方式展示 。如有需要获取资料文档的朋友&#xff0c;[可以点击这里免费获取](https://gitee.com/vip204888/java-p7)
![](https://img-blog.csdnimg.cn/img_convert/bbe3aba6b784f08071bc751ff1018526.png)
![](https://img-blog.csdnimg.cn/img_convert/a26c3bdb78e211bad7bf29c48509abe2.png)
![](https://img-blog.csdnimg.cn/img_convert/2c6164bc188da85d6cdb0222017b9cb6.png)
![](https://img-blog.csdnimg.cn/img_convert/27f28f98347c78f085d12176698291cf.png)
![](https://img-blog.csdnimg.cn/img_convert/34e14979d162e52b189593dd01bf5db5.png)
![](https://img-blog.csdnimg.cn/img_convert/1b06cd007537f2ed7270a610f7e96365.png)
![](https://img-blog.csdnimg.cn/img_convert/dc4be0e24b9558de6cb96a9296675506.png)**主要有以下几个场景&#xff1a;* 底层数据库引擎不支持事务
* 在非public修饰的方法使用
* rollbackFor属性设置错误
* 本类方法直接调用
* 异常被try...catch吃了&#xff0c;导致事务失效。其中&#xff0c;最容易踩的坑就是后面两个&#xff0c;**注解的事务方法给本类方法直接调用**&#xff0c;伪代码如下&#xff1a;

public class TransactionTest{
public void A(){
//插入一条数据
//调用方法B (本地的类调用&#xff0c;事务失效了)
B();
}


最后

经过日积月累&#xff0c; 以下是小编归纳整理的深入了解Java虚拟机文档&#xff0c;希望可以帮助大家过关斩将顺利通过面试。
由于整个文档比较全面&#xff0c;内容比较多&#xff0c;篇幅不允许&#xff0c;下面以截图方式展示 。如有需要获取资料文档的朋友&#xff0c;可以点击这里免费获取
[外链图片转存中…(img-7e5v26Jn-1628133116821)]
[外链图片转存中…(img-9CODty7u-1628133116822)]
[外链图片转存中…(img-s60Sy7js-1628133116823)]
[外链图片转存中…(img-wVhDv9Ec-1628133116824)]
[外链图片转存中…(img-2AqwcakF-1628133116824)]
[外链图片转存中…(img-S1URUTgf-1628133116825)]
[外链图片转存中…(img-HTgiyBIj-1628133116826)]

由于篇幅限制&#xff0c;文档的详解资料太全面&#xff0c;细节内容太多&#xff0c;所以只把部分知识点截图出来粗略的介绍&#xff0c;每个小节点里面都有更细化的内容&#xff01;


推荐阅读
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • Java学习笔记之面向对象编程(OOP)
    本文介绍了Java学习笔记中的面向对象编程(OOP)内容,包括OOP的三大特性(封装、继承、多态)和五大原则(单一职责原则、开放封闭原则、里式替换原则、依赖倒置原则)。通过学习OOP,可以提高代码复用性、拓展性和安全性。 ... [详细]
  • Go Cobra命令行工具入门教程
    本文介绍了Go语言实现的命令行工具Cobra的基本概念、安装方法和入门实践。Cobra被广泛应用于各种项目中,如Kubernetes、Hugo和Github CLI等。通过使用Cobra,我们可以快速创建命令行工具,适用于写测试脚本和各种服务的Admin CLI。文章还通过一个简单的demo演示了Cobra的使用方法。 ... [详细]
  • Spring学习(4):Spring管理对象之间的关联关系
    本文是关于Spring学习的第四篇文章,讲述了Spring框架中管理对象之间的关联关系。文章介绍了MessageService类和MessagePrinter类的实现,并解释了它们之间的关联关系。通过学习本文,读者可以了解Spring框架中对象之间的关联关系的概念和实现方式。 ... [详细]
  • 先看官方文档TheJavaTutorialshavebeenwrittenforJDK8.Examplesandpracticesdescribedinthispagedontta ... [详细]
  • Java太阳系小游戏分析和源码详解
    本文介绍了一个基于Java的太阳系小游戏的分析和源码详解。通过对面向对象的知识的学习和实践,作者实现了太阳系各行星绕太阳转的效果。文章详细介绍了游戏的设计思路和源码结构,包括工具类、常量、图片加载、面板等。通过这个小游戏的制作,读者可以巩固和应用所学的知识,如类的继承、方法的重载与重写、多态和封装等。 ... [详细]
  • SpringBoot uri统一权限管理的实现方法及步骤详解
    本文详细介绍了SpringBoot中实现uri统一权限管理的方法,包括表结构定义、自动统计URI并自动删除脏数据、程序启动加载等步骤。通过该方法可以提高系统的安全性,实现对系统任意接口的权限拦截验证。 ... [详细]
  • 本文介绍了一个Java猜拳小游戏的代码,通过使用Scanner类获取用户输入的拳的数字,并随机生成计算机的拳,然后判断胜负。该游戏可以选择剪刀、石头、布三种拳,通过比较两者的拳来决定胜负。 ... [详细]
  • 本文介绍了Oracle数据库中tnsnames.ora文件的作用和配置方法。tnsnames.ora文件在数据库启动过程中会被读取,用于解析LOCAL_LISTENER,并且与侦听无关。文章还提供了配置LOCAL_LISTENER和1522端口的示例,并展示了listener.ora文件的内容。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 展开全部下面的代码是创建一个立方体Thisexamplescreatesanddisplaysasimplebox.#Thefirstlineloadstheinit_disp ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • C++字符字符串处理及字符集编码方案
    本文介绍了C++中字符字符串处理的问题,并详细解释了字符集编码方案,包括UNICODE、Windows apps采用的UTF-16编码、ASCII、SBCS和DBCS编码方案。同时说明了ANSI C标准和Windows中的字符/字符串数据类型实现。文章还提到了在编译时需要定义UNICODE宏以支持unicode编码,否则将使用windows code page编译。最后,给出了相关的头文件和数据类型定义。 ... [详细]
  • 本文介绍了如何使用C#制作Java+Mysql+Tomcat环境安装程序,实现一键式安装。通过将JDK、Mysql、Tomcat三者制作成一个安装包,解决了客户在安装软件时的复杂配置和繁琐问题,便于管理软件版本和系统集成。具体步骤包括配置JDK环境变量和安装Mysql服务,其中使用了MySQL Server 5.5社区版和my.ini文件。安装方法为通过命令行将目录转到mysql的bin目录下,执行mysqld --install MySQL5命令。 ... [详细]
author-avatar
丰田高耗能妨功害能侠盗飞车_948
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有