java编程访问hdfs
许多不熟悉Java的开发人员首先要了解的一件事是Java的基本原始数据类型 ,其固定(与平台无关)的大小(以位或字节为单位用二进制补码表示 )以及它们的范围(Java中所有数字类型都是带符号的) )。 有许多不错的在线资源列出了这些特性,其中一些资源是有关原始数据类型的Java教程课程, Java的 八种数据类型 , Java的原始数据类型和Java基本数据类型。
 Java允许人们以编程方式访问基本Java基本数据类型的这些特征。 在Java中,大多数原始数据类型的最大值和最小值已通过相应的引用类型的MAX_VALUE和MIN_VALUE字段提供了一段时间。 J2SE 5为大多数类型引入了SIZE字段,该字段以位为单位提供每个类型的大小(二进制补码)。 现在,JDK 8为大多数此类提供了一个称为BYTES的新字段,该字段以字节为单位显示类型的大小(二进制补码)。 
DataTypeSizes.java
package dustin.examples.jdk8;import static java.lang.System.out;
import java.lang.reflect.Field;/*** Demonstrate JDK 8's easy programmatic access to size of basic Java datatypes.* * @author Dustin*/
public class DataTypeSizes
{/*** Print values of certain fields (assumed to be constant) for provided class.* The fields that are printed are SIZE, BYTES, MIN_VALUE, and MAX_VALUE.* * @param clazz Class which may have static fields SIZE, BYTES, MIN_VALUE,*    and/or MAX_VALUE whose values will be written to standard output.*/private static void printDataTypeDetails(final Class clazz){out.println("\nDatatype (Class): " + clazz.getCanonicalName() + ":");final Field[] fields = clazz.getDeclaredFields();for (final Field field : fields){final String fieldName = field.getName();try  {switch (fieldName){case "SIZE" :  // generally introduced with 1.5 (twos complement)out.println("\tSize (in bits):  " + field.get(null));break;case "BYTES" : // generally introduced with 1.8 (twos complement)out.println("\tSize (in bytes): " + field.get(null));break;case "MIN_VALUE" :out.println("\tMinimum Value:   " + field.get(null));break;case "MAX_VALUE" :out.println("\tMaximum Value:   " + field.get(null));break;default :break;}}catch (IllegalAccessException illegalAccess){out.println("ERROR: Unable to reflect on field " + fieldName);}}}/*** Demonstrate JDK 8's ability to easily programmatically access the size of* basic Java data types.* * @param arguments Command-line arguments: none expected.*/public static void main(final String[] arguments){printDataTypeDetails(Byte.class);printDataTypeDetails(Short.class);printDataTypeDetails(Integer.class);printDataTypeDetails(Long.class);printDataTypeDetails(Float.class);printDataTypeDetails(Double.class);printDataTypeDetails(Character.class);printDataTypeDetails(Boolean.class);}
}执行后,以上代码将以下结果写入标准输出。
输出
Datatype (Class): java.lang.Byte:Minimum Value:   -128Maximum Value:   127Size (in bits):  8Size (in bytes): 1Datatype (Class): java.lang.Short:Minimum Value:   -32768Maximum Value:   32767Size (in bits):  16Size (in bytes): 2Datatype (Class): java.lang.Integer:Minimum Value:   -2147483648Maximum Value:   2147483647Size (in bits):  32Size (in bytes): 4Datatype (Class): java.lang.Long:Minimum Value:   -9223372036854775808Maximum Value:   9223372036854775807Size (in bits):  64Size (in bytes): 8Datatype (Class): java.lang.Float:Maximum Value:   3.4028235E38Minimum Value:   1.4E-45Size (in bits):  32Size (in bytes): 4Datatype (Class): java.lang.Double:Maximum Value:   1.7976931348623157E308Minimum Value:   4.9E-324Size (in bits):  64Size (in bytes): 8Datatype (Class): java.lang.Character:Minimum Value: 更新:请注意,正如Attila-Mihaly Balazs在下面的注释中指出的那样,上面显示的java.lang.Float和java.lang.Double的MIN_VALUE值不是负数,即使这些常量值对Byte , Short是负值也是如此, Int和Long 。 对于Float和Double的浮点类型 , MIN_VALUE常量表示可以存储在这些类型中的最小绝对值 。 
尽管Java原始数据类型的特性可以随时在线获得,但是很高兴能够在需要时轻松地以编程方式访问这些细节。 我想用字节来考虑类型的大小,而JDK 8现在提供了查看以字节为单位直接测量这些大小的能力。
翻译自: https://www.javacodegeeks.com/2014/04/programmatic-access-to-sizes-of-java-primitive-types.html
java编程访问hdfs