Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

[an error occurred while processing this directive]

Java: Summary - Data

Vanilla Java

Basic types to know: int, double, String, boolean, and char.

Primitive types

Classes

There are 8 primitive types: boolean (true and false); char (Unicode characters); byte, short, int, and long (integers); float and double (floating point). The most commonly used pre-defined object type is String. Primitive types have corresponding "wrapper" class whose objects are immutable (values can not be changed).

Autoboxing. Conversion between the primitive and the wrapper classes is largely automatic as of Java 5.

Integers - primitive types

Integer classes

The integer types byte, short, int, and long are stored as two's complement, signed binary integers. char, which is technically also an integer type, is stored as an unsigned binary number. Expressions are computed as ints, so a cast is needed to store in a smaller type.
Type BytesRange Literals
byte 1-128..+127 none
short2-32,768..+32,767 none
int 4-2,147,483,648..+2,147,483,64723, 0xAF
long 8-9,223,372,036,854,775,808.. 23L, 0xAFL
Operators: arithmetic, comparison, bitwise, assignment.
Wrapper classes Integer (not Int), Short, Byte, Long contain utility methods, eg, Integer.parseInt(s), MAX_VALUE, MIN_VALUE, ...

Math class has many useful utility methods.

java.math.BigInteger is useful for arithmetic on unbounded integers.

Several other integer classes have limited or special utility: Number, AtomicInteger, and AtomicLong.

Floating-point - primitive types

Floating-point classes

The floating-point types, float and double, are stored in IEEE-754 format. Calculations may produce NaN (Not a Number) or +/- infinity. Calculations are done as doubles, so a cast is needed to store in a float.
Type Bytes Range Accuracy Literals
float 4-3.4E38..+3.4E38 6-7 digits 3.14F 6.02e23F
double8-1.7E308..+1.7E30814-15 digits3.14 6.02e23
Operators: arithmetic, comparison, assignment.
Wrapper classes: Double and Float contain utility methods (eg, Double.parseDouble(s)), MAX_VALUE, MIN_VALUE, ...

Math class has many useful utility methods.

java.math.BigDecimal for arithmetic on unbounded floating-point numbers.

Special utility: Number.

boolean - primitive type

Boolean class

boolean has values true or false.
Operators: logical, ==, !=, assignment.
Boolean: wrapper class with little utility.

char - primitive types

Character, String, ... classes

char type is a Unicode character stored as an unsigned number in two bytes (range 0..65,535 or '\u0000'..'\uFFFF'). char is an integer type.
char literals
  • 'A' (single character)
  • Unicode '\uxxxx' where x is a hexadecimal digit. Eg '\u0041'
  • Octal '\nnn' where n is an octal digit.
  • Escape combinations: '\n' newline, '\\' backslash, '\'' single quote, '\"' double quote, '\r' carriage return, '\t' tab, '\b' backspace, '\f' form feed.
Character wrapper class contains useful methods for working with characters.

String immutable 0 or more characters.

java.util.StringBuilder (as of Java 5) and java.util.StringBuffer (slower than StringBuilder because it's synchronized) used for dynamically building or modifying strings.

java.util.regex.Pattern and java.util.regex.Matcher used for regular expression matching. java.util.StringTokenizer is earlier class to break strings into "tokens".

CharSequence is basic character interface.


Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (
post your own) View All Comments Latest 10 Comments:
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.