Skip to content

Yet another programming solutions log

Sample bits from programming for the future generations.

Technologies Technologies
  • Algorithms and Data Structures
  • Java Tutorials
  • JUnit Tutorial
  • MongoDB Tutorial
  • Quartz Scheduler Tutorial
  • Spock Framework Tutorial
  • Spring Framework
  • Bash Tutorial
  • Clojure Tutorial
  • Design Patterns
  • Developer’s Tools
  • Productivity
  • About
Expand Search Form

Java primitive types sizes

farenda 2015-05-24 0

Problem:

What are sizes of Java primitive types?

Solution:

The following program answers the question:

package com.farenda.solved;

public class JavaSolved {
    public static void main(String[] args) {
        System.out.println("Sizes of Java primitive types:");
        int charMin = Character.MIN_VALUE;
        int charMax = Character.MAX_VALUE;
        System.out.println("Character min: " + charMin +           ", max: " + charMax);
        System.out.println("     Byte min: " + Byte.MIN_VALUE +    ", max: " + Byte.MAX_VALUE);
        System.out.println("    Short min: " + Short.MIN_VALUE +   ", max: " + Short.MAX_VALUE);
        System.out.println("  Integer min: " + Integer.MIN_VALUE + ", max: " + Integer.MAX_VALUE);
        System.out.println("     Long min: " + Long.MIN_VALUE +    ", max: " + Long.MAX_VALUE);
        System.out.println("    Float min: " + Float.MIN_VALUE +   ", max: " + Float.MAX_VALUE);
        System.out.println("   Double min: " + Double.MIN_VALUE +  ", max: " + Double.MAX_VALUE);
    }
}

Result:

Sizes of Java primitive types:
Character min: 0, max: 65535
     Byte min: -128, max: 127
    Short min: -32768, max: 32767
  Integer min: -2147483648, max: 2147483647
     Long min: -9223372036854775808, max: 9223372036854775807
    Float min: 1.4E-45, max: 3.4028235E38
   Double min: 4.9E-324, max: 1.7976931348623157E308

As you can see all numeric types are with sign!

Share with the World!
Categories Java Tags java-basics
Previous: Java primitive types default values
Next: Java 8 write to a text file

Recent Posts

  • Java 8 Date Time concepts
  • Maven dependency to local JAR
  • Caesar cipher in Java
  • Java casting trick
  • Java 8 flatMap practical example
  • Linked List – remove element
  • Linked List – insert element at position
  • Linked List add element at the end
  • Create Java Streams
  • Floyd Cycle detection in Java

Pages

  • About Farenda
  • Algorithms and Data Structures
  • Bash Tutorial
  • Bean Validation Tutorial
  • Clojure Tutorial
  • Design Patterns
  • Java 8 Streams and Lambda Expressions Tutorial
  • Java Basics Tutorial
  • Java Collections Tutorial
  • Java Concurrency Tutorial
  • Java IO Tutorial
  • Java Tutorials
  • Java Util Tutorial
  • Java XML Tutorial
  • JUnit Tutorial
  • MongoDB Tutorial
  • Quartz Scheduler Tutorial
  • Software Developer’s Tools
  • Spock Framework Tutorial
  • Spring Framework

Tags

algorithms bash bean-validation books clojure design-patterns embedmongo exercises git gof gradle groovy hateoas hsqldb i18n java java-basics java-collections java-concurrency java-io java-lang java-time java-util java-xml java8 java8-files junit linux lists log4j logging maven mongodb performance quartz refactoring regex rest slf4j solid spring spring-boot spring-core sql unit-tests

Yet another programming solutions log © 2021

sponsored
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok