Java Primitives and Bits

Integer

when processors were 16 bit, an int was 2 bytes. Nowadays, it‘s most often 4 bytes on a 32 bits system or 8 bytes on 64 bits system.

Character

  • An ASCII character in 8-bit ASCII encoding is 8 bits (1 byte), though it can fit in 7 bits.
  • An ISO-8895-1 character in ISO-8859-1 encoding is 8 bits (1 byte).
  • A Unicode character in UTF-8 encoding is between 8 bits (1 byte) and 32 bits (4 bytes).

Java uses unicode system. Character in the java class file is encoded with UTF-8 while running in JVM is encoded with UTF-16.

Long & Double

Writing longs and doubles is not atomic in Java.

It‘s not atomic because it‘s a multiple-step operation at the machine code level. That is, longs and doubles are longer than the processor‘s word length. doubles and longs are not read or written to atomically unless they‘re declared volatile.

Java‘s primitive types are guaranteed to be a particular length across all machines. On some 64 bits JVMs nowadays, the operations of longs and doubles are effectively atomic.

时间: 2024-11-11 15:15:48

Java Primitives and Bits的相关文章

[LeetCode][Java][JavaScript]Counting Bits

Counting Bits Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array. Example:For num = 5 you should return [0,1,1,2,1,2]. Follow up

Java Programming Tutorial Java Native Interface (JNI)

1.  Introduction At times, it is necessary to use native codes (C/C++) to overcome the memory management and performance constraints in Java. Java supports native codes via the Java Native Interface (JNI). JNI is difficult, as it involves two languag

111个知名Java项目集锦,包括url和描述

转:http://www.cnblogs.com/wangs/p/3282183.html 项目名称   项目描述 ASM Java bytecode manipulation framework AspectWerkz AspectWerkz - Dynamic AOP for Java Axis Axis - an implementation of the SOAP (Simple Object Access Protocol) submission to W3C Batik Batik

12.JAVA编程思想——集合的类型

12.JAVA编程思想--集合的类型 欢迎转载,转载请标明出处:http://blog.csdn.net/notbaron/article/details/51100510 标准Java 1.0 和1.1 库配套提供了非常少的一系列集合类.但对于自己的大多数编程要求,它们基本上都能胜任.Java 1.2 提供的是一套重新设计过的大型集合库. 1      Vector Vector 的用法很简单,大多数时候只需用addElement()插入对象,用elementAt()一次提取一个对象,并用el

使用Serializable接口进行JAVA的序列化和反序列化

OBJECT STREAMS – SERIALIZATION AND DESERIALIZATION IN JAVA EXAMPLE USING SERIALIZABLE INTERFACE Hitesh Garg | November 7, 2014 | io | 9 Comments In the previous java tutorials I have discussed about basic of java streams, byte streams, then a modifie

Java 位运算超全面总结

1.原码.反码.补码 关于原码.反码.补码的相关知识作者不打算在这里长篇大论,相关知识已有别的大佬总结很好了,还请老铁自行 Google,不过有篇知乎回答是作者学编程以来见过对相关知识最通俗易懂,生动简洁的解释:对原码.反码.补码最通俗易懂,生动简洁的解释,墙裂建议大家先看完这篇科普文章.在继续讨论之前你要先明白一点:整数在计算机内部都是以补码形式存储的. 2.Java 位运算概览 OK 都看到这儿了那我就假定你已经掌握了原码.反码.补码相关知识(虽然上面那段几乎啥也没讲,纯凑字数) 不废话了.

JNI Tutorial

原文链接: https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html 1.  Introduction At times, it is necessary to use native codes (C/C++) to overcome the memory management and performance constraints in Java. Java supports native cod

Spring核心技术(三)——Spring的依赖及其注入(续)

本文将继续前文,针对依赖注入的细节进行描述 依赖注入细节 如前文所述,开发者可以通过定义Bean的依赖的来引用其他的Bean或者是一些值的,Spring基于XML的配置元数据通过支持一些子元素<property/>以及<constructor-arg/>来达到这一目的. 内在值类型(Java Primitives类型,字符串等) 元素<property/>有value属性来对人友好易读的形式配置一个属性或者构造参数.Spring的便利之处就是用来将这些字符串的值转换成指

关于Hibernate的查询从数据库映射到JavaBean

Hibernate除了HQL外,还支持SQL的查询,API为createSQLQuery(sql),如果数据库使用的是Oracle,由于数据库表中的列都是大写,所以在从resultset到javabean的时候,需要完全匹配. 一般我们会用DTO或者作为DTO的Entity,无论是采用addEntity(Class class)还是 setResultTransformer(new AliasToBeanResultTransformer (CatDTO.class)) 都会遇到数据库字段到Ja