List of usage examples for java.lang Short MIN_VALUE
short MIN_VALUE
To view the source code for java.lang Short MIN_VALUE.
Click Source Link
From source file:Main.java
public static void main(String[] args) { System.out.println(Short.MIN_VALUE); System.out.println(Short.MAX_VALUE); }
From source file:Main.java
public static void main(String args[]) { System.out.println("Min value from Short class:" + Short.MIN_VALUE); }
From source file:Main.java
public static void main(String[] args) { System.out.println("Byte.MIN = " + Byte.MIN_VALUE); System.out.println("Byte.MAX = " + Byte.MAX_VALUE); System.out.println("Short.MIN = " + Short.MIN_VALUE); System.out.println("Short.MAX = " + Short.MAX_VALUE); System.out.println("Integer.MIN = " + Integer.MIN_VALUE); System.out.println("Integer.MAX = " + Integer.MAX_VALUE); System.out.println("Long.MIN = " + Long.MIN_VALUE); System.out.println("Long.MAX = " + Long.MAX_VALUE); System.out.println("Float.MIN = " + Float.MIN_VALUE); System.out.println("Float.MAX = " + Float.MAX_VALUE); System.out.println("Double.MIN = " + Double.MIN_VALUE); System.out.println("Double.MAX = " + Double.MAX_VALUE); }
From source file:Main.java
public static void main(String args[]) { System.out.println("Min byte value = " + Byte.MIN_VALUE); System.out.println("Max byte value = " + Byte.MAX_VALUE); System.out.println("Min short value = " + Short.MIN_VALUE); System.out.println("Max short value = " + Short.MAX_VALUE); System.out.println("Min int value = " + Integer.MIN_VALUE); System.out.println("Max int value = " + Integer.MAX_VALUE); System.out.println("Min float value = " + Float.MIN_VALUE); System.out.println("Max float value = " + Float.MAX_VALUE); System.out.println("Min double value = " + Double.MIN_VALUE); System.out.println("Max double value = " + Double.MAX_VALUE); }
From source file:MinVariablesDemo.java
public static void main(String args[]) { // integers/*from w ww . j a v a 2 s .c om*/ byte smallestByte = Byte.MIN_VALUE; short smallestShort = Short.MIN_VALUE; int smallestInteger = Integer.MIN_VALUE; long smallestLong = Long.MIN_VALUE; // real numbers float smallestFloat = Float.MIN_VALUE; double smallestDouble = Double.MIN_VALUE; // display them all System.out.println("The smallest byte value is " + smallestByte); System.out.println("The smallest short value is " + smallestShort); System.out.println("The smallest integer value is " + smallestInteger); System.out.println("The smallest long value is " + smallestLong); System.out.println("The smallest float value is " + smallestFloat); System.out.println("The smallest double value is " + smallestDouble); }
From source file:Main.java
/** Helper method - gets a named attribute's value as a <I>short</I>. @param pNodeMap The <I>NamedNodeMap</I>. @param strName Name of the attribute. @return Value of the attribute.//from ww w. j a v a2 s . c o m */ public static short getAttributeShort(NamedNodeMap pNodeMap, String strName) throws ClassCastException, NumberFormatException { int nReturn = getAttributeInt(pNodeMap, strName); if (Integer.MIN_VALUE == nReturn) return Short.MIN_VALUE; return (short) nReturn; }
From source file:Main.java
/** Helper method - gets a named element's value as a <I>short</I>. @param pElement The parent <I>Element</I>. @param strName Name of the element./*from w ww . j av a 2 s. c om*/ @return Value of the element. */ public static short getElementShort(Element pElement, String strName) throws ClassCastException, NumberFormatException { int nReturn = getElementInt(pElement, strName); if (Integer.MIN_VALUE == nReturn) return Short.MIN_VALUE; return (short) nReturn; }
From source file:Main.java
public static short toShort(long l) { if (l < Short.MIN_VALUE || l > Short.MAX_VALUE) throw new ArithmeticException("Value (" + l + ") cannot fit into short"); return (short) l; }
From source file:NumberUtils.java
/** * Convert the given number into an instance of the given target class. * * @param number the number to convert * @param targetClass the target class to convert to * @return the converted number// www .jav a 2 s .com * @throws IllegalArgumentException if the target class is not supported * (i.e. not a standard Number subclass as included in the JDK) * @see java.lang.Byte * @see java.lang.Short * @see java.lang.Integer * @see java.lang.Long * @see java.math.BigInteger * @see java.lang.Float * @see java.lang.Double * @see java.math.BigDecimal */ public static Number convertNumberToTargetClass(Number number, Class targetClass) throws IllegalArgumentException { if (targetClass.isInstance(number)) { return number; } else if (targetClass.equals(Byte.class)) { long value = number.longValue(); if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { raiseOverflowException(number, targetClass); } return number.byteValue(); } else if (targetClass.equals(Short.class)) { long value = number.longValue(); if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) { raiseOverflowException(number, targetClass); } return number.shortValue(); } else if (targetClass.equals(Integer.class)) { long value = number.longValue(); if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { raiseOverflowException(number, targetClass); } return number.intValue(); } else if (targetClass.equals(Long.class)) { return number.longValue(); } else if (targetClass.equals(Float.class)) { return number.floatValue(); } else if (targetClass.equals(Double.class)) { return number.doubleValue(); } else if (targetClass.equals(BigInteger.class)) { return BigInteger.valueOf(number.longValue()); } else if (targetClass.equals(BigDecimal.class)) { // using BigDecimal(String) here, to avoid unpredictability of BigDecimal(double) // (see BigDecimal javadoc for details) return new BigDecimal(number.toString()); } else { throw new IllegalArgumentException("Could not convert number [" + number + "] of type [" + number.getClass().getName() + "] to unknown target class [" + targetClass.getName() + "]"); } }
From source file:NumberUtils.java
/** * Convert the given number into an instance of the given target class. * @param number the number to convert//from ww w . j ava 2 s . c o m * @param targetClass the target class to convert to * @return the converted number * @throws IllegalArgumentException if the target class is not supported * (i.e. not a standard Number subclass as included in the JDK) * @see java.lang.Byte * @see java.lang.Short * @see java.lang.Integer * @see java.lang.Long * @see java.math.BigInteger * @see java.lang.Float * @see java.lang.Double * @see java.math.BigDecimal */ public static Number convertNumberToTargetClass(Number number, Class targetClass) throws IllegalArgumentException { if (targetClass.isInstance(number)) { return number; } else if (targetClass.equals(Byte.class)) { long value = number.longValue(); if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Byte(number.byteValue()); } else if (targetClass.equals(Short.class)) { long value = number.longValue(); if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Short(number.shortValue()); } else if (targetClass.equals(Integer.class)) { long value = number.longValue(); if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Integer(number.intValue()); } else if (targetClass.equals(Long.class)) { return new Long(number.longValue()); } else if (targetClass.equals(Float.class)) { return new Float(number.floatValue()); } else if (targetClass.equals(Double.class)) { return new Double(number.doubleValue()); } else if (targetClass.equals(BigInteger.class)) { return BigInteger.valueOf(number.longValue()); } else if (targetClass.equals(BigDecimal.class)) { // using BigDecimal(String) here, to avoid unpredictability of BigDecimal(double) // (see BigDecimal javadoc for details) return new BigDecimal(number.toString()); } else { throw new IllegalArgumentException("Could not convert number [" + number + "] of type [" + number.getClass().getName() + "] to unknown target class [" + targetClass.getName() + "]"); } }