How I may help
LinkedIn Profile Email me!
Call me using Skype client on your machine

Reload this page Field/Data Types and Data Typing

Here are notes comparing the intricacies of how various programming environments use and convert among different data types.


Topics this page:

  • Data Naming Conventions
  • Data Types
  • Primitive Data Types
  • MS-SQL Data Types
  • BLOB/SQL3 Data Types
  • Literals & Constants, Hex
  • Strings
  • Currencies
  • Wrapper Classes
  • Type Casting/Conversion
  • Your comments???

    Site Map List all pages on this site 
    About this site About this site 
    Go to first topic Go to Bottom of this page

    Set screen Primitive (Inherent) Datatypes

      Different languages use the same word to mean different sizes.

      Size Value Range
      printf Lotus
      Unsigned Integer
      (Whole numbers, no decimals. positive integer values)
      All Java primitive numeric data types are signed. 8 bits
      1 byte
      0 to 28-1
      - - - - Byte b byte
      8 bits
      1 byte
      0 to 215-1
      - - - - - ushort
      32 bits
      4 bytes
      0 to 231-1
      (to 2,147,483,648)
      0L - - - - uint
      64 bits
      8 bytes
      0 to 263 - 1 0UL - - - ulong
      Signed Integer
      (Whole numbers, no decimals. Half the range handles negative integer values, the remaining half handles positive integer values)


      8 bits
      1 byte
      -2-7 to 27-1
      ( -128 to +127 )
      0 TINYINT - - - sbyte


      16 bits
      2 bytes
      -2-15 to 215-1
      ( -32,768 to +32,767 )
      0 SMALLINT - Integer Short short


      32 bits
      4 bytes
      -2-31 to 231
      (±2,147,483,648 )
      0 INTEGER %d
      - Single int


      64 bits
      8 bytes
      -263 to +263 - 1 0L BIGINT - Long long
      IEEE 754 Signed Floating point A website external to this site precision


      32 bits
      4 bytes
      -1.4e-45 to +3.4e38
      -1.40239846-45 to
      [7 significant digits]
      0.0F REAL %f
      Single Integer


      64 bits
      8 bytes
      -4.9e-324 to +1.797e308
      -4.94065645841246544-324-324 to
      [15-16 significant digits]
      0.0D FLOAT,
      Double Long
      - - 128 bits
      16 bytes
      -1.0x10-28 to +1.0x1028
      [28 significant digits]
      0M - - - - Decimal
      A Single two-byte Unicode character


      16 in Java
      8 in C
      0 to 216-1
      ( 0 to 65,535 )
      \u0000 to \uFFFF
      - %c - Char
      2 bytes

      booleananother page on this site

      1 bit true or false false BIT - - 2 bytes bool
      A sequence of plain-text characters Reminder In C, an array of characters.
      Reminder In Java, a string of characters is NOT considered a primitive data type but a complex data type implemented as a Java class.
      - %s
      String -
      Date (In VB.NET, from January 1, 0001 to December 31, 9999) - - - - Date
      8 bytes

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen MS .NET Framework Bittable

      When data is transferred between Microsoft's dot Net Framework and unmanaged (DCOM) code (through P/Invoke), data types which do have the same in-memory representations -- known as non-blittable types -- require conversion (marshaling) as they are passed back and forth. These are Boolean, Char, String, Object, and arrays of these types.

    Set screen C# Number Formatting

      Character Description Example Code Output
      C or c Currency Console.Write("{0:C}",2.5);
      D or d Decimal Console.Write("{0:D5}",25); 00025
      E or e Scientific Console.Write("{0:E}",250000); 2.500000E+005
      F or f Fixed-point Console.Write("{0:F2}",25);
      G or g General Console.Write("{0:G}",2.5); 2.5
      N or n Number Console.Write("{0:N}",2500000); 2,500,000.00
      X or x Hexadecimal Console.Write("{0:X}",250);

      The presentation of numbers (for the current culture) can be automatically formatted by specifying these codes within curly braces, listed in alphabetical order:

      public void WriteAsBytes(int value){
      	bytes[] = BitConverter.GetBytes(value);
      	foreach(byte b in bytes){
      		Console.Write("0x{0:X2}", b);
      		string message = String.Format("0x{0:X2}", b);

      If the above code is called by WriteAsBytes(32), then this would display 0x20 0x00 0x00 0x00.

      Parsing strings is the opposite process from formatting.

    Set screen Implicit conversions & Casting

      This table ablove lists data types from smallest to largest such that implicit conversions can flow from top to bottom, but not upstream.

        byte > short > int > long > float > double

      To explicitly cast to a smaller datatype in Java:

        myInteger = (int) myLongInteger

        Reminder java automatically casts to a larger datatype, but will throw a fit rather than going smaller.

      To expliciitly cast to a smaller datatype in C#:

        long longValue = Int64.MaxValue; 
        int intValue = (int) longValue; 

        Note the .MaxValue property avialable only to C# programmers.

      Also, with C#, unsigned can go signed, but not the other way. Reminder

        C# data types are divided into Value types and Reference types.

        Value types Reference types
        allocated on the stack allocated on the heap
        Directly contain their data Store references to their data (known as objects)
        Each has its own copy of data Two reference variables can reference same object
        Operations on one cannot affect another Operations on one can affect another

        "Boxing" transforms a value type to a reference type by creating a temporary reference type "box" on the heap.

      A similar table

      To convert a String to a double:

        doubleOffset = Double.valueOf( offset ).doubleValue();

      To convert a String to a floating point in Ruby (since the language is object oriented):

        "1".to_i + 1

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Object Identifier Naming Conventions

      Are there industry standards for terse names used when objects are instantiated???

      Instance identifiers (names) cannot be a Word Reserved for Javaanother page on this site. Prefix to field names for indicating how the datum is stored:

      include file provides constants for values identifying data type:

      adInteger 3
      adSingle 4
      adDouble 5
      adCurrency 6
      adDate 7
      adBoolean 11
      adVariant 12
      adBinary 128
      adChar 129
      adNumeric 131
      adDBDate 133
      adDBTime 134
      adDBTimeStamp 135


    Terse Primitive or Object
    Data Type
    Example Component
    a array aObjectProperties()
    con connection to a database  
    d,dbl floating point double number  
    evt event  
    e Exception  
    f frame  
    g graphics Swing paintComponent()
    gi global integer giUsersLoggedInNow
    h handle (long) hWnd
    i integer iRowCount
    l long lDistance2Pluto
    o object oFlowchart
    p parameter  
    pS printStream  
    ptr pointer float* ptrX1;
    ptrX1 = &ptrX2;
    r reference by Java like a C pointer
    s, str string sUserPassword
    RS Record Set from a database query  
    sa string array sa
    seg segment in database  
    tbl table in database  
    u user-defined type uSmoots
    v variant vPropertyValue
    v vector  
    w window  

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Data Types

    • Jave primitive data type declarations for char, int, float, long, double are similar to the C language:
        Char theChar = 'a'; // Character are defined 16-bit unsigned unique code values.
        int ndays; // an instance of an integer
        Date cdt; // an instance of an abstract data type identified as Date
      UML Data Types
    • Java reference data types include array, interface, and class.
    • Scalar data is atomic - not made up of other variable components. such as PL/SQL record and table.
    • Data types can be extended to create new data types which inherit from existing data types.
        Rectangle r = new Rectangle(); // Creates new Rectangle "r"
        Integer p = new Integer(); // Creates new Integer "p"
    • The PrintStream instance writes String instances using system print & println methods from the SDK's java.util class.
        import ...
        FileOutputStream fOS = new FileOutputStream( filestream );
        PrintStream pS = new PrintStream( fOS );
        pS.print("I am writing to a file");
        pS.println("Just like System.out");
        fOS.close( );
    • Each variable defined within a class is considered a member of that class. So Instance Variables are also referred to as Member data or Properties. Class variables, which can be shared among all objects of its class, are defined using the static keyword.
    • The behavior of an object is determined by instance variables (mouseover = on, etc.) The Java Beans API considers methods whose names begin with set or get to represent special design patterns for manipulating the properties of an object.
    • The current values of an object defines its state.
    • An object can change its state by sending it a message, invoking its methods, or calling its member functions.

    Go to Top of this page.
    Previous topic this page
    Next topic this page

      Set screen Numeric Sign Default

      This C program (from Christopher Sawtell) tests whether the char inherent data type is signed or unsigned.

      This is dependent on the design of the processor used by your compiler.

      Early PDP-11 and VAX-11 computers had automatic sign extention of char. This means that the range of char is from -128 through to +127. The trend is toward unsigned char as the default.


            char a;
            unsigned char b;
            a = b = 128;
            a >>= 1;
            b >>= 1;
    	printf ( "\nChar is %ssigned by default.\n\n", 
    		a == b ? "un" : "" );

    Go to Top of this page.
    Previous topic this page
    Next topic this page

      Set screen SQL Data Types

      Data Type Usage Max Bytes


      Fixed length 8,000


      value 1 or 0 1


      Fixed length 8,000


      Fixed length two-byte "national" Unicode 4,000
      For efficiency, MS-SQL physically stores data in fixed length blocks.

      Oracle-SQL has no data type boolean. The Oracle character set can be displayed by using these SQL statements:

        SQL> select * from nls_database_parameters;
        SQL> select * from nls_database_parameters where parameter like '%CHARACTERSET%';

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen BLOBs and Other SQL3 Datatypes

      Java Type SQL Type from java.sql.Types
      java.sql.Date DATE
      java.sql.Time TIME
      java.sql.Timestamp TIMESTAMP
      java.sql.Blob BLOB
      java.sql.Clob CLOB
      java.sql.Array ARRAY
      java.sql.Ref REF
      java.sql.Struct STRUCT
      java.math.BigDecimal NUMERIC
      java.lang.String VARCHAR or LONGVARCHAR
      byte[] array VARBINARY or LONGVARBINARY
      BLOB (Binary Large OBject) and CLOBs (Character Large OBject) data types (a collection of data stored as a single entity in a database) are typically held at the server until specifically requested after a proxy is processed. These and other advanced datatypes introduced by SQL3 (Array, Blob, Clob, Ref, SQLData, SQLInput, SQLOutput, and Struct) ability to manipulate large objects without bringing them to the client from the DB server)

      Type conversion between SQL and Java in Castor

      Unlike C or C++, Java primitive (inherent) datatypes are portable because they each occupy exactly the same amount of memory on all Java-supporting machines.

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Type Conversion Functions

      Unlike VB or LotusScript, Java (and now MS.NET) do not have a variant data type that can change type.

      Java does not have a method to convert boolean data types (False == 0) to numeric data type.

      tool Roedy Green presents Java type conversion code as a HTML table or a Java 1.4 applet with source code that considers implied encoding translation when interconverting byte [] and String. "8859_1" encoding simply chops the high byte off or pads the high byte with 0s.

      When arithmetic is performed using two variables of different types, the value of the variables with the norrower type is promoted to wider type. This is called arithmetic-promotion conversion.

      Built-in Javascript Function Action  
      escape(charstring) Returns the conversion of charstring into a form that displays in the browser without HTML markup.
      unescape(charstring) Returns the conversion of charstring back into a form that displays in the browser with HTML markup (the opposite of escape).
      eval(codestring) Evaluates codestring as JavaScript code, returning anything that JavaScript returns.
      isNaN(numvalue) Returns true if numvalue is not a number, otherwise returns false — used with parseFloat and parseInt.
      parseFloat(numstring) Returns numstring converted to a floating point number. If it cannot be converted, returns the reserved value NaN.
      parseInt(numstring) Returns numstring converted to an integer. If it cannot be converted, returns the reserved value NaN.

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Literals

      Literal values are entered directly into Java declaration statements.

      Data Type Java Coding Sample Note
      Boolean boolean isBig = true;
      boolean isSmall = false;
      Identifier prefix is "is". True or false value spec is not encased.
      Character char c = "w";
      char c1 = '\u1234';
      Single quotes are used to encase value spec
      Integer (32 bit) int X = 256;  
      Long Integer (64 bit) long longL = 24445345L; Don't use lower-case l to avoid confusion.
      Single Float float floatA = 1.32E+2F; Don't use lower-case f to avoid confusion.
      Double Float float floatB = 1.32E+2D; Don't use lower-case d to avoid confusion.

      Because, by default, a numeric literal is either a double or an int, double and float literals are declared a special way. So remember to append the symbol shown in the "Default Value" column above.

      To avoid confusion, use the upper-case code (L) even though the lower case (l) is valid.

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Constants

      Constant values are not variables, but get translated into values that never change. midi

        ~=3.14... — the ratio of the circumference of a circle to its diameter, represented by the Greek lower case letter $\pi$ pi, pronounced "pie") defined by
        Math.PI in Java and M_PI in C's Math library.

        ~=2.718281828459045... — Leonhard Euler's number e, the base of natural logarithms, such that ln(e^1) = 1 defined by
        Math.E in Java and M_E in C's Math library.

      Reminder The names of constants are by convention UPPER CASE. However, in Java boolean true and false are in lower case.

      The C programming languageanother page on this site defines these constants as double datatypes in its ISO C99 Standard: 7.12 Mathematics C /usr/include/Math.h library:

      Constant Description BSD/GNU Name BSD/GNU Value
      The maximum value of a single-precision floating-point number. HUGE 3.40282347e+38F
      Positive infinity: +infinity on machines that support IEEE-754 and DBL_MAX otherwise. HUGE_VAL 1e500
      The maximum value of a non-infinite single-precision floating point number. MAXFLOAT 3.40282347e+38F
      The base of natural logarithms (e). M_E
      The base-2 logarithm of e. M_LOG2E
      The base-10 logarithm of e. M_LOG10E M_LOG10El 0.43429448190325182765
      The natural logarithm of 2. M_LN2
      The natural logarithm of 10. M_LN10
      $\pi$. M_PI
      $\pi$/2 (Pi divided by 2). M_PI_2
      $\pi$/4 (Pi divided by 4). M_PI_4
      1/$\pi$ (inverse of Pi). M_1_PI
      2/$\pi$ (2 divided by Pi). M_2_PI
      2/$\sqrt{\pi}$ (2 divided by the square root of Pi). M_2_SQRTPI
      The positive square root of 2. M_SQRT2
      The positive square root of 1/2. M_SQRT1_2
      Bessel function limit of significance pi*2**52 — the maximum absolute value of the ordinate before we assume total loss of significance, per ISO/IEC 10967-1:1994 Information Technology - Language Independent Arithmetic - Part 1: Integer and floating-point arithmetic. Defined in <values.h> X_TLOSS 1.41484755040568800000e+16

      Other constants:

      Constant Description BSD/GNU Name BSD/GNU Value
      Avogadro's number NA 6.025 X 1023g mole-1
      Planck's constant h 6.626068 X 10-34 Js (Joule seconds)
      Free space velocity of light c 3.00 X 108ms-1
      Electron charge e 1.602 X 10-19C
      Electron rest mass me 9.11 X 10-13kg
      Specific electron charge e/m 1.760 X 1011Ckg-1
      Atomic mass unit amu 1.660 X 10-27kg
      Proton rest mass mp 1.6724 X 10-27kg
      Stefan-Boltzmann constant sigma 5.67 X 10-8Jm-2K-4S-1
      Universal gas constant R 8.31JK-1g mole-1
      Universal gravitation constant G 6.673 x 10-11Nm2kg-2
      Boltzmann constant k 1.381 x 1023JK-1

      Golden spirals and triangles Java does not automatically declare φ (Greek letter Phi pronounced "fee") ~=1.61803... — (1+the square root of 5)/2 — the basis for the Golden Rectangles and Spirals found in nature (sunflowers, nautilus shells, and the formation of galaxies). Phi is the limit of the ratios of the numbers in the Fibonnacci sequence, where each number is the sum of the two before it (q = 1 + 1/q) for

        0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

        Dividing each number by the number before it (eg., 55/34) yields Phi (through convergence by oscillation).

        To define constant PHI in Java:

        private static final int PHI = 1.61803;

        To define constant PHI in Oracle SQL:

        PHI := 1.618034;

      The trianglular spiral is obtained by adding the second and third previous number:

        2, 3, 4, 5, 7, 9, 12, 16, 21

      from the formula (1/p + 1/p2 or p3 - p - 1), called the Padovan sequence series after architect Richard Padovan of Padua (100 miles from Pisa where Fibonacci lived) [Nexus Network Journal, vol 4, no. 3 (Summer 2002)]

      The ratio between adjacent numbers yield a constant ratio of 1.324718. This was nicknamed the "Plastic Number" in 1928 by its discoverer Dom Hans Van Der Laan because it generates amazing, interconnected commensurate design patterns, many of which suggest 3D applications.

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Hex

      Integer constants are considered decimal unless
      • a leading 0 (zero) means octal;
      • a leading 0x or 0X means Hexadecimal, such as 0xFFFFFF

      For example, decimal 63 is written as '63' in decimal, '077' in octal, or 0x3F, 0X3F, 0x3f, or 0X3f in hexadecimal format. All integer constants are treated as 32-bit integers. Negative numbers are obtained by prefacing the integer constant with the unary negation operator (-).

      Java Literal References defined in the java.lang package are used to test Bit Patterns of returned values defined in IEEE 754:

        Erroneous calculation IEEE 754 return value
        Divide by zero n/a - ArithmeticException is thrown
        ??? Float.NaN
        square root of a negative number Float.NEGATIVE_INFINITY

        Reminder These literals are considered non-ordinal. Tthe comparison x == Float.NaN returns false even if x contains Float.NaN. So test for them using static methods Float.isNaN(float) or Double.isNaN(double) from the java.lang package.

        Method Constant
        .isDigit -
        .isLetter -
        .isLetterOrDigit -
        .isLowerCase .LOWERCASE_LETTER
        .isUpperCase .UPPERCASE_LETTER
        .isSpaceChar -
        .isDefined in Unicode -
        - .MATH_SYMBOL

        To determine the properties, use the java.lang.Character class in the SDK:

        char ch;
        if (Character.isLetter(ch));
        if (Character.getType('a') == Character.LOWERCASE_LETTER);

        With JavaScript, isNaN(numvalue) returns true if numvalue from parseFloat and parseInt is Not a Number.

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen String Objects

      char* s,t; const char* cs, ct;
      c is an char converted to type int; int n;
      Code Usage
      char *strcpy(s,ct) copy ct into s, including ``\0''; return s
      char *strncpy(s,ct,n) copy ncharcater of ct into s,
      return s
      char *strncat(s,ct) concatenate ct to end of s;
      return s
      char *strncat(s,ct,n) concatenate n character of ct to end of s,
      terminate with ``\0''; return s
      int strcmp(cs,ct) compare cs and ct;
      return 0 if cs=ct, <0 if cs0 if cs>ct
      char *strchr(cs,c) return pointer to first occurence of c in cs
      or NULL if not encountered
      size_t strlen(cs) return length of cs
      Without special operators to manipulate strings, the C language manipulates strings using routines in the standard string library string.h and pointers. The name of an array is a pointer to its first element.

        char *string_1 = "Hello";
        char string_2[] = "Hello"; // compiler calculates
        char string_3[6] = "Hello"; // 5+null character

      The C language reads a string until it encounters a null character (\0). So a trick C programmers use to quickly truncate a string is to inserting a null character in that string causes all remaining characters in that string to be ignored.

      strcat(dest, src); is therefore risky.
      To code defensively:

        assert(dest != NULL);
        assert(src != NULL);
        strncat(dest, src, sizeof(dest)-strlen(dest)-1);
        dest[sizeof(dest)-1] = '\0';

      strcpy(dest, src); is risky.
      To code defensively,

        assert(dest != NULL);
        assert(src != NULL);
        strncpy(dest, src, sizeof(dest));

      Caution! Unlike later versions of the javac compiler, awareness of assert is disabled by default in version 1.4. So you will have to activate it as part of the compilation command:

        javac -source 1.4 com/myDirectory/


      Java string literals are represented internally by an instance of a String object, with
      the tostring() method automatically created for every class.

        This Java code initializes a string object:
        String s1 = "something";

        But the Java compiler actually interprets:
          String s1 = new String( "something" );

        Reminder Java does not actually create another object if both s1 and s2 have the same value. So initialize strings with different values or use StringBuffer.

        The use of "==" between two strings will always return false because that operator evaluates the addresses rather than the value of two objects.
        So use one of these string methods to test the difference between two string objects:

        if( s1.equals(s2) )
        if( s1.equalsIgnoreCase(s2) )
        if( s1.compareTo(s2) < 0 )

        Best of all, make localized comparisons using the default locale:

        To compare the same key several times, or to compare strings which are likely to be different even from the first characters, convert objects for bitwise comparison using CollationKey

        Insteading of hard-coding strings in programs, use a resource file method that looks up the value of the string. This allows you to dynamically change the text without recompiling.

        Idea For best performance, such as within tight running loops threads, 1) declare the size of strings, 2) use StringBuffer, and 3) append to strings rather than concatenating them with the + plus operator. Examples:

        StringBuffer sb = new StringBuffer(50); sb.append("Hello"); sb.append("there");

        Unlike a String, StringBuffers are mutable (can be modified).

      Set screen Currency Data Type

        LotusScript has a Currency data type (±922,337,203,685,411.5807).
        Java does not have a Currency data type. Java displays currency using a function that is sensitive to formatting requirements specific to the user's locale.

        More on currenciesanother page on this site

      Set screen Dates

      Java dates are not a primitive within java.lang._____.TYPE, but from class java.util.Date. Programming Date, Time, and Calendar Functionsanother page on this site

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Wrapper Classes

      Each primitive class in Java has an associated Wrapper class, which simply contains the primitive value.

      The primitive name is usually the lowercase version of the wrapper, except for char and int.

        Integer is the wrapper class for the int primitive.
        Character is the wrapper class for the char primitive.

      A Wrapper class object is created by calling the Wrapper class constructor with the appropriate primitive value as a parameter to the constructor. For every Wrapper class except character, you can also construct a Wrapper class object by passing in a string representation of the value into the constructor. For example:

        int MyInt = 409;
        Integer intObject = new Integer(MyInt);
        Integer intObject2 = new Integer("409");

      If the string you pass to the constructor is not formatted correctly for the Wrapper class type, the constructor will throw a NumberFormatException exception error. equals method provided by the base Object class. For example, based on the previous example, the following would be true:


      To get a primitive value back out of a wrapper, use a method provided by each Wrapper class object:

        Byte -> public byte byteValue();

      Any of the numeric Wrapper classes can also be retrieved into any numeric type. The Wrapper classes include a valueOf() method which accepts a string parameter representing a value, then constructs and returns a Wrapper class instance of the same class.

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Portions ©Copyright 1996-2014 Wilson Mar. All rights reserved. | Privacy Policy |

    Related Topics:

  • Escape Characters
  • Java Programming
  • Free Training!
  • Tech Support

  • How I may help

    Send a message with your email client program

    Your rating of this page:
    Low High

    Your first name:

    Your family name:

    Your location (city, country):

    Your Email address: 

      Top of Page Go to top of page

    Thank you!