Exception class hierarchy in Java

Exception AclNotFoundException ActivationException UnknownGroupException UnknownObjectException AlreadyBoundException ApplicationException AWTException BadLocationException ClassNotFoundException CloneNotSupportedException ServerCloneException DataFormatException ExpandVetoException GeneralSecurityException CertificateException CertificateEncodingException CertificateExpiredException CertificateNotYetValidException CertificateParsingException CRLException DigestException InvalidAlgorithmParameterException InvalidKeySpecException InvalidParameterSpecException KeyException InvalidKeyException KeyManagementException KeyStoreException NoSuchAlgorithmException NoSuchProviderException SignatureException UnrecoverableKeyException IllegalAccessException InstantiationException InterruptedException IntrospectionException InvocationTargetException IOException ChangedCharSetException CharConversionException EOFException FileNotFoundException InterruptedIOException MalformedURLException ObjectStreamException InvalidClassException InvalidObjectException NotActiveException NotSerializableException OptionalDataException StreamCorruptedException WriteAbortedException ProtocolException RemoteException […]
Continue reading…

Enjoyed this post? Share it!

 
 

Recursively calculate Fibonacci Sequence in Java

public class Fibonacci {   private int calculate(int length) { if (length < 0) { throw new IllegalArgumentException("Input must be greater than zero"); } if (length <= 1) { return length; } else { return calculate(length – 1) + calculate(length – 2); } } public static void main(String[] args) { Fibonacci fibonacci = new Fibonacci(); […]
Continue reading…

Enjoyed this post? Share it!

 
 

Calculate factorial using recursion in Java

package com.w3mentor.examples.factorial;   public class Factorial {   int calculate(int number) { if (number < 0) { throw new IllegalArgumentException("integer must be greater than zero"); } if( number == 0) { return 1; } else { return number * calculate (number – 1); } }   public static void main(String[] args) { Factorial factorial = […]
Continue reading…

Enjoyed this post? Share it!

 
 

Separators in Java

Symbol Name Description () Parentheses Used in: method signatures to contain lists of arguments. expressions to raise operator precedence. narrowing conversions. loops to contain expressions to be evaluated {} Braces Used in: declaration of types. blocks of statements array initialization. [] Brackets Used in: array declaration. array value dereferencing < > Angle brackets Used to […]
Continue reading…

Enjoyed this post? Share it!

 
 

Reserved keywords in Java

abstract assert boolean break byte case catch char class   const continue default do double else enum extends final   finally float for goto if implements import instanceof   int interface long native new package private protected public   return short static strictfp super switch synchronized this throw   throws transient try void volatile while
Continue reading…

Enjoyed this post? Share it!

 
 

Read commandline arguments in Java

/** * This program prints out all its command-line arguments. **/ public class EchoArgs { public static void main(String[] args) { int i = 0; // Initialize the loop variable while(i < args.length) { // Loop until the end of array System.out.print(args[i] + " "); // Print each argument out i++; // Increment the loop […]
Continue reading…

Enjoyed this post? Share it!

 
 

Hello world in Java

To run this program, use javac Hello.java at the command prompt. This will compile the code to an executable. To run it, type java Hello at the command prompt. public class Hello { // Everything in Java is a class public static void main(String[] args) { // All programs must have main() System.out.println("Hello World!"); // […]
Continue reading…

Enjoyed this post? Share it!