`
leonzhx
  • 浏览: 798615 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论
文章列表
已经存在一个.java 文件如下: package mypackage; public class ArrayList { public void add(Object b) { System.out.println("My ArrayList"); } }   请输出以下程序的输出 package mypackage; import java.util.*; class Test { public static void main(String[] arg) { ArrayList a = ...
已经存在一个.java 文件如下: package mypackage; public class ArrayList { public void add(Object b) { System.out.println("My ArrayList"); } }   ,以下哪个java程序会编译出错 1) package mypackage; import java.util.*; class Test { public static void main(String[] arg) { ArrayList a = n ...
以下关于Java SE5的描述错误的是: 1) 没有一种方法可以import 默认包(default package) 2) 一个.java文件中可没有public 的 class 3) 如果import a.b.*; 那 class a.b.c.d 也会被导入 4) 在设置CLASSPATH时,不能只设置jar包所在的目录的路径,而要设置jar包的全路径(包括文件名) 5) 在没有设置CLASSPATH的时候(CLASSPATH为空),当前目录("./")将被默认作为搜索.class文件的路径。反之一但CLASSPATH被设置后,则当前目录不会作为搜索路径。(除非 ...
public class Test { static void f(int[] b, int... a) { System.out.println(b.getClass() == a.getClass()); } public static void main(String[] argu) { f(new int[] { 1, 2, 3 }, new int[0]); } }  请问以上代码的输出是:
public class Test { public static String f(short a, double b) { return "a is short"; } public static String f(int a, float b) { return "a is int"; } public static String f(double a, double b) { return "a is double"; } public static ...
public class Test { public static String f(short a, double b) { return "a is short"; } public static String f(int a, float b) { return "a is int"; } public static String f(double a, double b) { return "a is double"; } public static ...
  public class Test { public static void main(String[] argu) { byte b = -1; b >>>= 5; int a = -1; a >>>= 32; System.out.println(a == b); } }  求以上代码的输出:  
public class Test { public static void main(String[] argu) { float a = 5 / 3.0; float b = 5 / (6 / 2.0); System.out.println(a == b); } }  求以上代码的打印结果?
Proper use of synchronization guarantees that no method will ever observe the object in an inconsistent state.   Without synchronization, one thread’s changes might not be visible to other threads.   The language specification guarantees that reading or writing a variable is atomic unless the v ...
近日另一友人也去google面试,被问及一算法题如下: x,y为两个有序数组(升序),长度分别为M和N,矩阵m为一M*N的两维数组,其中m[i][j] = x[i] + y[j]。 设计一算法求矩阵中第K小的元素。 我所想的算法如下,与大家分享交流,看看有什么可以改进的。首先这题让我直觉上就想到了merge sort。其实每个m[i] ( 0<=i<M )本身就是一个升序的一维数组。也就是说m是由M个有序数组组成,只要两两对这两个有序数组做merge sort,取前K个结果即可,代码的时间复杂度应该是O(K * min(M,N) )   import java.util.Ar ...
Immutable objects are simply objects whose state (the object's data) cannot change after construction. Examples of immutable objects from the JDK include String and Integer. Immutable objects greatly simplify your program, since they : are simple to construct, test, and use are automatically ...
Class invariants are methods which check the validity of an object's state (its data). The idea is to define validation methods for fields, and to perform these validations whenever the fields change. As usual, this should be done without repeating any code. An object's state may become invalid for ...
1.  One advantage of static factory methods is that, unlike constructors, they have names. BigInteger(int, int, Random), which returns a BigInteger that is probably prime, would have been better expressed as a static factory method named BigInteger.probablePrime. In cases where a class seems to req ...
Lazy initialization is a performance optimization. It's used when data is deemed to be 'expensive' for some reason. For example: if the hashCode value for an object might not actually be needed by its caller, always calculating the hashCode for all instances of the object may be felt to be unneces ...
Copy constructors : provide an attractive alternative to the rather pathological clone method are easily implemented simply extract the argument's data, and forward to a regular constructor are unnecessary for immutable objects Example public final class Galaxy { public Galaxy (doub ...
Global site tag (gtag.js) - Google Analytics