Data Types Comparison

Java Data Types

Java has two types, Primitive and Reference Types

Primitives

Following primitive types are supported
  • byte, int, short, long, char
  • float, double

Ranges of Primitive types

  • byte, from -128 to 127, inclusive
  • short, from -32768 to 32767, inclusive
  • int, from -2147483648 to 2147483647, inclusive
  • long, from -9223372036854775808 to 9223372036854775807, inclusive
  • char, from ‘u0000’ to ‘uffff’ inclusive, that is, from 0 to 65535
public class PrimitiveDataTypes {
    public static void main(String[] args) {
        byte b = 127;
        short sh = 32767;
        int i = 5;
        float f = 1.0f;
        char c = '\u0000';
        double d = 1.000004d;
        long l = 9223372036854775807L;
        String str ="This is a String";

        System.out.println("int i:" + i);
        System.out.println("float f:" + f);
        System.out.println("char c:" + c);
        System.out.println("double d:" + d);
        System.out.println("long l:" + l);
        System.out.println("String s:" + str);
    }
}

Reference Types

Any type which extends java.lang.Object

Force.com Data Types

Supports multiple of data types.

Primitive Data Type

A primitive, such as a Integer, Double, Long, Date, Datetime, String, ID, or Boolean

Boolean bool = true;
Double d=3.14159;
Integer i = 100000;
ID id='00300000003T2PGAA0';
Long l = 2147483648L;
String s = 'This is a string.';

System.debug('Boolean:' + bool);
System.debug('Double:' + d);
System.debug('Integer:' + i);
System.debug('Long:' + l);
System.debug('String:' + s);
Date myDate = Date.newInstance(1999, 1, 1);
System.debug('Date:' + myDate);

Output

03:05:42:021 USER_DEBUG [14]|DEBUG|Date:1999-01-01 00:00:00

Complex Data Types

  • An sObject: a generic sObject or as a specific sObject, such as an Account, Contact, or CustomObject__c

  • A collection including:
    • A list (or array) of primitives, sObjects, user defined objects, objects created from Apex classes, or collections
    • A set of primitives
    • A map from a primitive to a primitive, sObject, or collection
  • A typed list of values, also known as an enum

  • Objects created from user-defined Apex classes

  • Objects created from system supplied Apex classes

  • Null (for the null constant, which can be assigned to any variable)