学习笔记之Java

All contents are moved to haoran119/java (github.com).


Java (programming language) - Wikipedia

Java | Oracle

面试总结之JAVA - 浩然119 - 博客园 (cnblogs.com)

学习笔记之Java程序设计实用教程 - 浩然119 - 博客园 (cnblogs.com)

学习笔记之JAVA多线程 - 浩然119 - 博客园 (cnblogs.com)


 


一文详解 Java 的八大基本类型!

【Java基础内容总结】Java基础看这个就足够了

自己动手一个HashMap

如何检查 Java 数组中是否包含某个值 ?

终于明白为什么要加 final 关键字了!

字符串拼接还在用StringBuilder?快试试Java8中的StringJoiner吧,真香! (qq.com)

从String中移除空白字符的多种方式!?差别竟然这么大! (qq.com)

在Java中如何优雅地判空

是否注意过isEmpty 和 isBlank 区别?

为什么阿里巴巴禁止在 foreach 循环里进行元素的 remove/add 操作 - Java编程

为什么建议使用你 LocalDateTime ,而不是 Date?

YYYY-MM-dd 的Bug 

Java 8:一文掌握 Lambda 表达式 | CSDN 博文精选

Java泛型背后的秘密

Java程序员必备:异常的十个关键知识点

Java 异常处理的 20 个最佳实践,你知道几个?| CSDN 博文精选

多线程

线程最最基础的知识

线程池学习总结

为什么 Java 进程使用的 RAM 比 Heap Size 大?​ | CSDN博文精选

死磕 java线程——自己动手写一个线程池

很遗憾,没有一篇文章能讲清楚线程的生命周期!

如何线程安全地遍历List

IO通信模型—同步阻塞模式BIO

Java多线程优化

一文足以了解什么是 Java 中的锁

图解 | 你管这玩意叫线程池? (qq.com)

volatile和synchronized到底啥区别?多图文讲解告诉你 (qq.com)

SimpleDateFormat线程不安全的5种解决方案! (qq.com)


BEST PRACTICE

熬了 3 天夜,小吴肝出了万字 Java 知识地图手册! (qq.com)

硬核!如何全面系统地自学Java (qq.com)

憋了半个月的 PDF:精通 Java (qq.com)

学会 Java 数据结构,想不飘都难! (qq.com)

Java 那些最常用的工具类库 | 原力计划

写了那么多年 Java 代码,终于 debug 到 JVM 了

java虚拟机内存模型

大白话带你认识JVM

JVM核心知识体系

看完这篇垃圾回收,和面试官扯皮没问题了

JDK源码中,都有哪些NB的设计模式?

一份阿里员工排查Java问题的命令列表

Java 语言中十大“坑爹”功能!

从 0 开始手写一个 Mybatis 框架,三步搞定!


Q & A

How to halt the program ?

  • System.exit(1);

How to convert double to long ?

 1 public class DoubleToLong {
 2    
 3     
 4     public static void main(String args[]){
 5         
 6         // first example - converting double to long using longValue() method        
 7         double d = 102.9520;
 8         long l = (new Double(d)).longValue();
 9         System.out.println("double value=" + d + ", long=" + l);
10         
11         // second example - rather simple just cast double to long
12         double bill = 293.05;
13         long myBill = (long) bill;
14         System.out.println("double value=" + bill + ", long=" + myBill);
15                
16         
17         // third example - rounding double value to long in Java
18         double dbl = 3421.56;
19         long rnd = Math.round(dbl);
20         System.out.println("double value=" + dbl + ", long=" + rnd);
21          
22     }
23    
24 }
25 
26 Output
27 double value=102.952, long=102
28 double value=293.05, long=293
29 double value=3421.56, long=3422
30 
31 
32 Read more: https://www.java67.com/2014/11/how-to-convert-double-to-long-in-java-example.html#ixzz6vAnV7wT7
View Code

How to convert long to string ?

How to compare string ?

How to check if double is 0 ?

What's the Java equivant of Python List ?

What's LinkedHashMap ?

What's LinkedHashSet and HashSet ?

What's Stream ?

How to get fields with Java reflection ?

  • Class (Java SE 10 & JDK 10 ) (oracle.com)
    • public Field[] getFields() throws SecurityException
    • Returns an array containing Field objects reflecting all the accessible public fields of the class or interface represented by this Class object.
    • If this Class object represents a class or interface with no accessible public fields, then this method returns an array of length 0.
    • If this Class object represents a class, then this method returns the public fields of the class and of all its superclasses and superinterfaces.
    • If this Class object represents an interface, then this method returns the fields of the interface and of all its superinterfaces.
    • If this Class object represents an array type, a primitive type, or void, then this method returns an array of length 0.
    • The elements in the returned array are not sorted and are not in any particular order.
    • Returns:
      • the array of Field objects representing the public fields
  • Class (Java SE 10 & JDK 10 ) (oracle.com)
    • public Field[] getDeclaredFields() throws SecurityException
    • Returns an array of Field objects reflecting all the fields declared by the class or interface represented by this Class object. This includes public, protected, default (package) access, and private fields, but excludes inherited fields.
    • If this Class object represents a class or interface with no declared fields, then this method returns an array of length 0.
    • If this Class object represents an array type, a primitive type, or void, then this method returns an array of length 0.
    • The elements in the returned array are not sorted and are not in any particular order.
    • Returns:
      • the array of Field objects representing all the declared fields of this class
  • Java.lang.Class.getField() Method - Tutorialspoint
  • Java.lang.Class.getDeclaredFields() Method - Tutorialspoint
  • To access private fields, need to set accessible with Method (Java SE 11 & JDK 11 ) (oracle.com)
    • public void setAccessible​(boolean flag)
    • Description copied from class: AccessibleObject
    • Set the accessible flag for this reflected object to the indicated boolean value. A value of true indicates that the reflected object should suppress checks for Java language access control when it is used. A value of false indicates that the reflected object should enforce checks for Java language access control when it is used, with the variation noted in the class description.
    • This method may be used by a caller in class C to enable access to a member of declaring class D if any of the following hold:
      • C and D are in the same module.
      • The member is public and D is public in a package that the module containing Dexports to at least the module containing C.
      • The member is protectedstaticD is public in a package that the module containing D exports to at least the module containing C, and C is a subclass of D.
      • D is in a package that the module containing Dopens to at least the module containing C. All packages in unnamed and open modules are open to all modules and so this method always succeeds when D is in an unnamed or open module.
    • This method cannot be used to enable access to private members, members with default (package) access, protected instance members, or protected constructors when the declaring class is in a different module to the caller and the package containing the declaring class is not open to the caller's module.
    • If there is a security manager, its checkPermission method is first called with a ReflectPermission("suppressAccessChecks") permission.
  • What is the difference between getFields and getDeclaredFields in Java reflection - Stack Overflow
    • getFields()
      • All the public fields up the entire class hierarchy.
    • getDeclaredFields()
      • All the fields, regardless of their accessibility but only for the current class, not any base classes that the current class might be inheriting from.
posted on 2019-02-16 09:24  浩然119  阅读(456)  评论(0编辑  收藏  举报