![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Java
文章平均质量分 54
Yiduwang
这个作者很懒,什么都没留下…
展开
-
内存的单位转换(从bit到terabite)
bit(字节) - either 1 or 0byte(B) - sequence of 8 bitskilobyte(KB) - 1024 bytes = 2^10 bytesmegabyte(MB) - 2^20 bytesgigabyte(GB) - 2^30 bytesterabyte(TB) - 2^40 bytes原创 2017-12-24 11:10:46 · 1460 阅读 · 0 评论 -
Java 变量x++ 和 ++x的区别
若为x++, 那么先执行x在本语句中的任务,执行完毕后+1。若为++x,则先+1然后再执行x在本语句中的任务。Example 1: (++x)int x = 7;System.out.println(++x);System.out.println(x);输出为:88Example 2: (x++)int x = 7;System.out.println(x+原创 2017-12-24 15:28:00 · 7795 阅读 · 0 评论 -
Java运算符优先级
Unary Operator: !, ++, --, -, +;(此处+-代表特性,例如-a, +b)multiplicative: *, /, %;addition: +, -;comparative: , =;equality: ==, !=;and: &&;or: ||;assignment: %=, /=, *=, -=, +=, =;(以上优先级依原创 2017-12-28 14:59:08 · 160 阅读 · 0 评论 -
Java late binding后期绑定与polymorphism多态的结合
若没有学习继承,可先前往以下网址先学习inheritance:inheritance继承类应用与子母类访问权限讨论Motivation: Consider the following example:Faculty carol = new Faculty("Carol Tuffteacher", 458, 1995);Person p = carol;System.out.pr原创 2017-12-29 14:16:55 · 512 阅读 · 0 评论 -
Java inheritance继承类应用与子母类访问权限讨论
• Inheritance: is the process by which one new class, called the derived class, is created from another class, called thebase class.• The derived class is also called: subclass orchild class•原创 2017-12-29 13:36:30 · 482 阅读 · 0 评论 -
Java inheritance的upcasting和downcasting
upcasting一般是安全的,因为子类继承了母类所有的方法,不会报错。downcasting一般不被允许,非法downcasting会有run time error: ClassCastException。Example:/* This code generates a java.lang.ClassCastException */public class UpCastingDo原创 2017-12-29 14:58:48 · 1089 阅读 · 0 评论 -
Java一行代码可声明多个同类变量
Java支持一句语句声明多个同类变量。Example:String a = "Hello", c = "hello";int x = 5, y = 5;原创 2017-12-28 14:57:34 · 39677 阅读 · 1 评论 -
Java abstract class/method——抽象类/方法的应用
如何理解抽象类?举个例子,比如创建的母类名为“Shape”,它有子类“Circle”和“Rectangle”。母类定义了一个方法叫“drawMe()”,“画我”。然而圆和正方形都可以画出来,但是他们的母类,并不拥有一个能够画出来的具体形状。因此,母类的drawMe()无意义。但是作为要被子类继承的一种方法,它必须存在。这时我们就可以将母类定义为“抽象类”"abstract原创 2017-12-29 16:17:32 · 4638 阅读 · 0 评论 -
Java 将equals override为比较所有object的方法
Java 默认的equals只能比较同类型的object,一旦比较对象类型不同就会报错。下面是当类型不同时返回false避免报错的方法。Example:public class Student implements Comparable { private String name; private int id; public Student(String name, int原创 2017-12-29 13:00:38 · 1102 阅读 · 0 评论 -
Java数据类型内存大小与hierarchy
long - 8 bytesint - 4 bytesshort - 2 bytesdouble - 8 bytesfloat - 4 bytes原创 2017-12-24 13:55:11 · 438 阅读 · 0 评论 -
Java two dimensional array
two dimensional array 拥有两个不同的内存地址int[][] a = new int[3][];a[0] = new int[2];a[1] = new int[3];a[2] = new int[4];a[1][2] = 5;Example:package twoDimensionalArrays;public class Init原创 2017-12-27 10:49:59 · 1078 阅读 · 0 评论 -
Java深拷贝和浅拷贝举例详解
浅拷贝将原来对象的内存地址复制给一个新的对象,但不创建新的object。而深拷贝创建新的对象,并将需要拷贝的值复制到新的object里。Example:package CDExamples;public class CDCollectionOwner { private String name; private CD[] myFavorites; public CDCo原创 2017-12-27 10:24:21 · 309 阅读 · 0 评论 -
Java Scanner的简单应用
Scanner 可以用于检测并捕捉键盘输入的各种字符串。Example 1:import java.util.Scanner;public class Scanner1 { /** * Shows basic use of the scanner */ public static void main(String[] args) { Scanner keyboa原创 2017-12-24 14:29:23 · 367 阅读 · 0 评论 -
Java标识符的命名规则
Identifier:A-Z; a-z; 0-9; $ dollar sign; "_" underscore;Can't begin with a digit!Avoid keywordsCapitalization: Camel Case(驼峰式)Camel Case 驼峰式Variable/MethodClassnumberOfCats原创 2017-12-24 14:41:20 · 431 阅读 · 0 评论 -
Java final变量的声明和使用
final变量(never be changed):final int NUMBER_OF_CATS = 10;//never be changedfinal double PI = 3.1415927;final NUMBER_OF_WHEELS = 2;原创 2017-12-24 15:00:23 · 3369 阅读 · 3 评论 -
Java do-while的使用
do-while是while的特殊种类,do-while会先运行一次do里的代码,然后进行while的Boolean判定,然后返回按照do里的方法重新运行。(先执行,后判断的while loop)Example:public class SimpleDoWhile { public static void main(String[] args) { int index = 1原创 2017-12-24 15:09:50 · 18775 阅读 · 0 评论 -
Java String和StringBuffer的区别
简要的说, String 类型和 StringBuffer 类型的主要性能区别其实在于 String 是不可变的对象, 因此在每次对 String 类型进行改变的时候其实都等同于生成了一个新的 String 对象,然后将指针指向新的 String 对象,所以经常改变内容的字符串最好不要用 String ,因为每次生成对象都会对系统性能产生影响,特别当内存中无引用对象多了以后, JVM 的 GC原创 2017-12-25 13:20:30 · 652 阅读 · 0 评论 -
Java run-off error(on float and double)
We can't store real 3.9 in Base 2.double a = 3.9;boolean b = false;if(a == 3.9){ b = true;}System.out.println(b);输出为:false(3.9)Base 10 = (1 1 . 1 1 1 00 1 1.原创 2017-12-25 11:38:37 · 234 阅读 · 0 评论 -
Java基础知识缩写大全
CPU - Central Processing UnitIDE - Integrated Development EnvironmentCVS - Concurrent Versioning SystemMain Memory: RAM - Random Access MemorySecondary Memory - hard drive(permanent), CD, DVD原创 2017-12-24 10:55:00 · 506 阅读 · 0 评论 -
Java try catch throw exception 和 finally用法举例详解
Example:import javax.swing.*;public class DateReader { public static int getYear(String d) { String yearString = d.substring(6, 10); System.out.println("Done with substring method..."); r原创 2017-12-25 12:26:04 · 3108 阅读 · 0 评论 -
Java enumerated types枚举类的创建和遍历
枚举(enum)类型是Java 5新增的特性,它是一种新的类型,允许用常量来表示特定的数据片段,而且全部都以类型安全的形式来表示。Example:public enum Color { Red, Green, Blue }public class ColorEnumDriver { public static void main(String[] args) { /* Poss原创 2018-01-18 15:33:05 · 717 阅读 · 0 评论