Featured Posts

[Travel][feat1]

BigDecimal Class in Java

January 20, 2019
BigDecimal Class in Java
BigDecimal Class in Java

BigDecimal Class in Java

BigDecimal supports arbitrary precision  floating point numbers.We can use them for accurate calculations like monetary or financial application .
BigDecimal objects are represented as an integer of arbitrary size and an scale that represents the number of decimal places in the given BigDecimal.

The structure of the BigDecimal class is given as:


public class java.math.BigDecimal extends
             java.lang.Number {
//Constructors
public BigDecimal(String val) throws NumberFormatException;
public BigDecimal(double val) throws NumberFormatException;
public BigDecimal(BigInteger val);
public BigDecimal(BigInteger val, int scale) throws NumberFormatException;
// Constants
public static final int ROUND_CEILING;
public static final int ROUND_DOWN;
public static final int ROUND_FLOOR;
public static final int ROUND_HALF_DOWN;
public static final int ROUND_HALF_EVEN;
public static final int ROUND_HALF_UP;
public static final int ROUND_UNNECESSARY;
public static final int ROUND_UP;
//Methods
public static BigDecimal valueOf(long val, int scale) throws NumberFormatException;
public static BigDecimal valueOf(long val);
public BigDecimal abs();
public BigDecimal add(BigDecimal val);
public int compareTo(BigDecimal val);
public BigDecimal divide(BigDecimal val, int scale, int roundingMode) throws 
ArithmeticException, IllegalArgumentException;
public BigDecimal divide(BigDecimal val, int roundingMode) throws 
ArithmeticException, IllegalArgumentException;
public double doubleValue();
public boolean equals(Object x);
public float floatValue(); 
public int hashCode();
public int intValue(); 
public long longValue(); 
public BigDecimal max(BigDecimal val);
public BigDecimal min(BigDecimal val);
public BigDecimal movePointLeft(int n);
public BigDecimal movePointRight(int n);
public BigDecimal multiply(BigDecimal val);
public BigDecimal negate();
public int scale();
public BigDecimal setScale(int scale, int roundingMode) throws
ArithmeticException, IllegalArgumentException;
public BigDecimal setScale(int scale) throws ArithmeticException,
IllegalArgumentException;
public int signum();
public BigDecimal subtract(BigDecimal val);
public BigInteger toBigInteger();
public String toString(); 
}

 
BigDecimal Class in Java BigDecimal Class in Java Reviewed by Animesh Chatterjee on January 20, 2019 Rating: 5

BigInteger Class In Java

January 20, 2019
BigInteger Class In Java
BigInteger Class In Java

BigInteger Class In Java:

BigInteger supports arbitrary precision integers.This means that we can accurately represent integral values of any size without loosing any information during operation. BigInteger is not limited to 64 bits (like long) . This class defines some methods that does the same thing as normal arithmetic operator or bit manipulation operators does.

The structure of the BigInteger class defined as:



public class java.math.BigInteger extends
             java.lang.Number {
//Constructors
public BigInteger(byte[] val) throws NumberFormatException;
public BigInteger(int signum, byte[] magnitude) throws NumberFormatException;
public BigInteger(String val, int radix) throws NumberFormatException;
public BigInteger(String val) throws NumberFormatException;
public BigInteger(int numBits, Random rndSrc) throws IllegalArgumentException;
public BigInteger(int bitLength, int certainty, Random rnd);
//Methods
public static BigInteger valueOf(long val);
public BigInteger abs();
public BigInteger add(BigInteger val) throws ArithmeticException;
public BigInteger and(BigInteger val);
public BigInteger andNot(BigInteger val);
public int bitCount();
public int bitLength();
public BigInteger clearBit(int n) throws ArithmeticException;
public int compareTo(BigInteger val);
public BigInteger divide(BigInteger val) throws ArithmeticException;
public BigInteger[] divideAndRemainder(BigInteger val) throws ArithmeticException;
public double doubleValue();
public boolean equals(Object x);
public BigInteger flipBit(int n) throws ArithmeticException;
public float floatValue(); 
public BigInteger gcd(BigInteger val);
public int getLowestSetBit();
public int hashCode(); 
public int intValue();
public boolean isProbablePrime(int certainty);
public long longValue();
public BigInteger max(BigInteger val);
public BigInteger min(BigInteger val);
public BigInteger mod(BigInteger m);
public BigInteger modInverse(BigInteger m) throws ArithmeticException;
public BigInteger modPow(BigInteger exponent, BigInteger m);
public BigInteger multiply(BigInteger val);
public BigInteger negate();
public BigInteger not();
public BigInteger or(BigInteger val);
public BigInteger pow(int exponent) throws ArithmeticException;
public BigInteger remainder(BigInteger val) throws ArithmeticException;
public BigInteger setBit(int n) throws ArithmeticException;
public BigInteger shiftLeft(int n);
public BigInteger shiftRight(int n);
public int signum();
public BigInteger subtract(BigInteger val);
public boolean testBit(int n) throws ArithmeticException;
public byte[] toByteArray();
public String toString(int radix);
public String toString();
public BigInteger xor(BigInteger val);
}

 
BigInteger Class In Java BigInteger Class In Java Reviewed by Animesh Chatterjee on January 20, 2019 Rating: 5

ItemSelectable interface in Java

January 16, 2019
ItemSelectable interface in Java
ItemSelectable interface in Java

ItemSelectable interface in Java:


ItemSelectable is an abstract interface that represents one or more items to the user and allow users to select zero or more from them.

The structure of ItemSelectable interface is given as:


public abstract interface java.awt.ItemSelectable {
//Methods
public abstract void addItemListener(ItemListener itl);
//adds ItemListener objects to be notified when an item is selected.
public abstract Object[] getSelectedObjects();
//Returns an array of selected objects or null.
public abstract void removeItemListener(ItemListener itl);
//removes ItemListener objects to be notified when an item is selected.
}
 
ItemSelectable interface in Java ItemSelectable interface in Java Reviewed by Animesh Chatterjee on January 16, 2019 Rating: 5

Adjustable interface in Java

January 16, 2019
Adjustable interface in Java
Adjustable interface in Java

Adjustable interface in Java:

Adjustable interface are applicable to the application which maintain an user adjustable numeric value by implementing several methods defined here.
The user specific value should have a maximum  and a minimum value. These value can be incremented at a time or a block at a time. A simple example of Adjustable interface is the ScrollBar of an application.
An Adjustable object generates an AdjustmentEvent that is adjusted and it maintains a list of adjustmentListener objects which may be notified when such an event occurs. Like Scollbar up and down and displays the values.

The interface Adjustable is defined as:


public abstract interface java.awt.Adjustable {
// Constants
public static final int HORIZONTAL;
public static final int VERTICAL;
//Methods
public abstract void addAdjustmentListener(AdjustmentListener l);
public abstract int getBlockIncrement();
public abstract int getMaximum();
public abstract int getMinimum();
public abstract int getOrientation();
public abstract int getUnitIncrement();
public abstract int getValue();
public abstract int getVisibleAmount();
public abstract void removeAdjustmentListener(AdjustmentListener l);
public abstract void setBlockIncrement(int b);
public abstract void setMaximum(int max);
public abstract void setMinimum(int min);
public abstract void setUnitIncrement(int u);
public abstract void setValue(int v);
public abstract void setVisibleAmount(int v);
}
 
Adjustable interface in Java Adjustable interface in Java Reviewed by Animesh Chatterjee on January 16, 2019 Rating: 5

DecimalFormat in Java

January 16, 2019
DecimalFormat in Java
DecimalFormat in Java

DecimalFormat in Java:

DecimalFormat class is subclass of Format class mostly used by NumberFormat class.
DecimalFormat works for all locales. It uses the base 10.
Most of the applications can use the static methods of NumberFormat to get the object for a desired locale and can perform minor locale independent customization on that object.
DecimalFormat uses pattern to format and parse the customized number.

The pattern of DecimalFormat may be as follows:


Character Meaning
# A digit,zeros shows as absent
0 A digit ,zeros shows as 0
. Locale specific decimal separator
, Locale specific grouping separator
- Locale specific negative prefix
% Show value in percentage
; Separates positive number format from optional
negative number format
positive numbers are on left
negative numbers on right
' Reserved character shown in the output
other shown in the output
We can provide pattern like-"$#,###0.00" etc.If we do not specify the format or pattern, the default local specific format is used

The class structure DecimalFormat is given as:


public class java.text.DecimalFormat extends 
             java.text.NumberFormat {
//Constructors
public DecimalFormat();
public DecimalFormat(String pattern);
public DecimalFormat(String pattern, DecimalFormatSymbols symbols);
//Methods
public void applyLocalizedPattern(String pattern);
public void applyPattern(String pattern);
public Object clone(); 
public boolean equals(Object obj); 
public StringBuffer format(double number, StringBuffer result,FieldPosition fieldPosition); 
public StringBuffer format(long number, StringBuffer result,FieldPosition fieldPosition); 
public DecimalFormatSymbols getDecimalFormatSymbols();
public int getGroupingSize();
public int getMultiplier();
public String getNegativePrefix();
public String getNegativeSuffix();
public String getPositivePrefix();
public String getPositiveSuffix();
public int hashCode(); 
public boolean isDecimalSeparatorAlwaysShown();
public Number parse(String text, ParsePosition status); 
public void setDecimalFormatSymbols(DecimalFormatSymbols newSymbols);
public void setDecimalSeparatorAlwaysShown(boolean newValue);
public void setGroupingSize(int newValue);
public void setMultiplier(int newValue);
public void setNegativePrefix(String newValue);
public void setNegativeSuffix(String newValue);
public void setPositivePrefix(String newValue);
public void setPositiveSuffix(String newValue);
public String toLocalizedPattern();
public String toPattern();
}
 
DecimalFormat in Java DecimalFormat in Java Reviewed by Animesh Chatterjee on January 16, 2019 Rating: 5

AreaAveragingScaleFilter in Java

January 16, 2019
AreaAveragingScaleFilter in Java
AreaAveragingScaleFilter in Java

AreaAveragingScaleFilter in Java:

AreaAveragingScaleFilter helps in scaling of an image to a specified pixels size. AreaAveragingScaleFilter also helps to communicate between image filter and the FilteredImageSource. To use this filter effectively, we can call Image.getScaledInstance() method with a hint constant.

AreaAveragingScaleFilter uses a scaling algorithm that averages the adjacent pixel values when shrinking or expanding an image. This algorithm produced a smooth scaled version of the image. However there is a super class of AreaAveragingScaleFilter called ReplicateScaleFilter uses a faster,no so smooth scaling algorithm.

The class Structure of AreaAveragingScaleFilter in Java is given as:


public class java.awt.image.AreaAveragingScaleFilter extends 
             java.awt.image.ReplicateScaleFilter{
//Constructor
public AreaAveragingScaleFilter(int width, int height);
//Methods
public void setHints(int hints);
public void setPixels(int x, int y, int w, int h, ColorModel model,
byte[] pixels, int off, int scansize);
public void setPixels(int x, int y, int w, int h, ColorModel model, int[]
pixels, int off, int scansize);
}
 
AreaAveragingScaleFilter in Java AreaAveragingScaleFilter in Java Reviewed by Animesh Chatterjee on January 16, 2019 Rating: 5

SimpleDateFormat in Java

January 16, 2019
SimpleDateFormat in Java
SimpleDateFormat in Java

SimpleDateFormat in Java:

SimpleDateFormat is sub class of Format class to handle parsing and formatting of dates. We can not use the SimpleDateFormat class directly as the Date may be affected by locale. It is used mostly by DateFormat class by getting the locale info.

SimpleDateFormat class is helpful to format a specified date and time as per specified patterns for a default locale or predefined locale. 

The applyPattern() method of the SimpleDateFormat clas is responsible for formatting the pattern used by an object.

The pattern table is given as:


On Filed Full Pattern Short Pattern
Year yyyy (4 digits) yy (2 digits)
Month MMM (Name) MM (2 digits)
M   (1/2 digits)
Day of Week EEEE EE
Day of the Month dd (2 digits) d (1/2 digits)
Day of week in month F
Day in year DDD (3 digits) D (1/2/3 digits)
Week in year ww
Era G
Timezone zzzz zz
AM/PM a
Hours [ 0-12] hh (2 digits) h (1/2 digits)
Hours [ 0-23] HH (2 digits) H (1/2 digits)
Hours [0-11] KK K
Hours [1-24] kk k
Minutes mm
Second ss
Miliseconds SSS

The Structure of SimpleDateFormat in Java is given as:


public class java.text.SimpleDateFormat extends 
             java.text.DateFormat {
//Constructors
public SimpleDateFormat();
public SimpleDateFormat(String pattern);
public SimpleDateFormat(String pattern, Locale loc);
public SimpleDateFormat(String pattern, DateFormatSymbols formatData);
//Methods
public void applyLocalizedPattern(String pattern);
public void applyPattern(String pattern);
public Object clone(); 
public boolean equals(Object obj); 
public StringBuffer format(Date date, StringBuffer toAppendTo,
FieldPosition pos);
public DateFormatSymbols getDateFormatSymbols();
public int hashCode(); 
public Date parse(String text, ParsePosition pos);
public void setDateFormatSymbols(DateFormatSymbols newFormatSymbols);
public String toLocalizedPattern();
public String toPattern();
}
 
SimpleDateFormat in Java SimpleDateFormat in Java Reviewed by Animesh Chatterjee on January 16, 2019 Rating: 5

Array Class in Java

January 16, 2019
Array Class in Java
Array Class in Java

Array Class in Java:

In this post I have talked about Array concepts and how to use it.In this post we are going to check the structure of class Array. Array class contains set of methods that set a value or query from the set of homogeneous objects.. This class also provide us method 
  • To determine the size of Array 
  • How to create a new instance of an Array.
  • How to manipulate an Array.
The methods of Array class class are static that applies to all array values.

The class structure of Array is given as:


public final class java.lang.reflect.Array extends
                   java.lang.Object {
//Methods
public static native Object get(Object array, int index) 
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
public static native boolean getBoolean(Object array, int index) 
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
public static native byte getByte(Object array, int index) 
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
public static native char getChar(Object array, int index) 
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
public static native double getDouble(Object array, int index) 
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
public static native float getFloat(Object array, int index) 
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
public static native int getInt(Object array, int index) 
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
public static native int getLength(Object array) 
throws IllegalArgumentException;
public static native long getLong(Object array, int index) 
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
public static native short getShort(Object array, int index) 
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
public static Object newInstance(Class componentType, int length) 
throws NegativeArraySizeException;
public static Object newInstance(Class componentType, int[] dimensions) 
throws IllegalArgumentException, NegativeArraySizeException;
public static native void set(Object array, int index, Object value)
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
public static native void setBoolean(Object array, int index, boolean z)
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
public static native void setByte(Object array, int index, byte b)
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
public static native void setChar(Object array, int index, char c) 
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
public static native void setDouble(Object array, int index, double d)
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
public static native void setFloat(Object array, int index, float f)
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
public static native void setInt(Object array, int index, int i) 
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
public static native void setLong(Object array, int index, long l)
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
public static native void setShort(Object array, int index, short s)
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
}
 
The get() method returns the element at the specified index as an Object. If the array elements are primitive data type,the value is converted to equivalent Wrapper class and returned.
we can use

  • getInteger()
  • getBytes()
  • getChar()
  • getDouble()
methods to query an Array to get primitive types.

Array Class in Java Array Class in Java Reviewed by Animesh Chatterjee on January 16, 2019 Rating: 5

Container Class In Java

January 16, 2019
Container Class In Java
Container Class In Java

Container Class In Java:

Container class can hold other components in Java application. It implements the Component class to hold or contain these other components.We need to use its sub classes like Panel,Frame,Dialog etc to hold components. We can not directly instantiate Container class.The Container , once created,can hold objects and position them using LayoutManager.

The structure of Container Class is given as:


public abstract class java.awt.Container extends
                      java.awt.Component {
// Constructor
protected Container();
// Methods
public Component add(Component comp);
public Component add(String name, Component comp);
public Component add(Component comp, int index);
public void add(Component comp, Object constraints);
public void add(Component comp, Object constraints, int index);
public void addContainerListener(ContainerListener l);
public void addNotify(); 
public int countComponents();
public void deliverEvent(Event e); 
public void doLayout(); 
public float getAlignmentX(); 
public float getAlignmentY(); 
public Component getComponent(int n);
public Component getComponentAt(int x, int y); 
public Component getComponentAt(Point p); 
public int getComponentCount();
public Component[] getComponents();
public Insets getInsets();
public LayoutManager getLayout();
public Dimension getMaximumSize(); 
public Dimension getMinimumSize(); 
public Dimension getPreferredSize(); 
public Insets insets();
public void invalidate(); 
public boolean isAncestorOf(Component c);
public void layout(); 
public void list(PrintStream out, int indent); 
public void list(PrintWriter out, int indent); 
public Component locate(int x, int y); 
public Dimension minimumSize(); 
public void paint(Graphics g); 
public void paintComponents(Graphics g);
public Dimension preferredSize(); 
public void print(Graphics g); 
public void printComponents(Graphics g);
public void remove(int index);
public void remove(Component comp);
public void removeAll();
public void removeContainerListener(ContainerListener l);
public void removeNotify(); 
public void setLayout(LayoutManager mgr);
public void validate(); 
protected void addImpl(Component comp, Object constraints, int index);
protected String paramString(); 
protected void processContainerEvent(ContainerEvent e);
protected void processEvent(AWTEvent e); 
protected void validateTree();
}
 
Container Class In Java Container Class In Java Reviewed by Animesh Chatterjee on January 16, 2019 Rating: 5

Calendar Class in Java

January 16, 2019

Calendar in Java
Calendar in Java
Calendar Class in Java:

Calendar class is an abstract class which provides several methods to perform date and time arithmetic. Calendar class also helps to convert dates and time to and from the millisecond format used by other Date class. The format can be minutes,hours,days,weeks, year. All these format can be either consumable by human or machine.
We can not directly instantiate Calendar class, it provides getInstance() method to get the default locale or default time zone or a specific locale or a specific timezone.

The Structure of the Calendar class is given as:


public abstract class Calendar extends Object implements Serializable, Cloneable {
//Constructors
protected Calendar();
protected Calendar(TimeZone zone, Locale aLocale);
// Constants
public static final int FIELD_COUNT;
// Member elements -Date anf Time Field constants
public static final int ERA;
public static final int YEAR;
public static final int MONTH;
public static final int WEEK_OF_YEAR, WEEK_OF_MONTH;
public static final int DATE, DAY_OF_MONTH;
public static final int DAY_OF_YEAR, DAY_OF_WEEK, DAY_OF_WEEK_IN_MONTH;
public static final int ZONE_OFFSET, DST_OFFSET;
public static final int AM_PM;
public static final int HOUR, HOUR_OF_DAY;
public static final int MINUTE;
public static final int SECOND;
public static final int MILLISECOND;
public static final int JANUARY, FEBRUARY, MARCH, APRIL;
public static final int MAY, JUNE, JULY, AUGUST;
public static final int SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER;
public static final int UNDECIMBER;
public static final int SUNDAY, MONDAY, TUESDAY, WEDNESDAY;
public static final int THURSDAY, FRIDAY, SATURDAY;
public static final int AM, PM;
protected boolean areFieldsSet;
protected int[] fields;
protected boolean[] isSet;
protected boolean isTimeSet;
protected long time;
//Methods
public static synchronized Locale[] getAvailableLocales();
public static synchronized Calendar getInstance();
public static synchronized Calendar getInstance(TimeZone zone);
public static synchronized Calendar getInstance(Locale aLocale);
public static synchronized Calendar getInstance(TimeZone zone, Locale aLocale);
public abstract void add(int field, int amount);
public abstract boolean after(Object when);
public abstract boolean before(Object when);
public final void clear();
public final void clear(int field);
public Object clone(); // Overrides Object
public abstract boolean equals(Object when); 
public final int get(int field);
public int getFirstDayOfWeek();
public abstract int getGreatestMinimum(int field);
public abstract int getLeastMaximum(int field);
public abstract int getMaximum(int field);
public int getMinimalDaysInFirstWeek();
public abstract int getMinimum(int field);
public final Date getTime();
public TimeZone getTimeZone();
public boolean isLenient();
public final boolean isSet(int field);
public abstract void roll(int field, boolean up);
public final void set(int field, int value);
public final void set(int year, int month, int date);
public final void set(int year, int month, int date, int hour, int minute);
public final void set(int year, int month, int date, int hour, int minute, int second);
public void setFirstDayOfWeek(int value);
public void setLenient(boolean lenient);
public void setMinimalDaysInFirstWeek(int value);
public final void setTime(Date date);
public void setTimeZone(TimeZone value);
protected void complete();
protected abstract void computeFields();
protected abstract void computeTime();
protected long getTimeInMillis();
protected final int internalGet(int field);
protected void setTimeInMillis(long millis);
}
 
Calendar Class in Java Calendar Class in Java Reviewed by Animesh Chatterjee on January 16, 2019 Rating: 5
Powered by Blogger.