Tuesday, September 7th, 2010
Java Language basics

Example of continue with a label in Java

start: for (int i = 0; i < 3; i++) { for (int j = 0; j < 4; j++) { ...

More Java Language basics

Produce three beeps with a 500 milliseconds interval between two beeps in Java

java.awt.Toolkit.getDefaultToolkit().beep(); try { Thread.currentThread().sleep(500); } catch (Exception e) { } java.awt.Toolkit.getDefaultToolkit().beep(); try { Thread.currentThread().sleep(500); } catch (Exception e) { } java.awt.Toolkit.getDefaultToolkit().beep();

Use if with a series of else statements in Java

if (a == 1) { System.out.println("one"); } else if (a == 2) { System.out.println("two"); } else if ...

Dangling else problem in Java

The else statement in the code below is dangling because it is not clear which if statement the else statement is ...

Character literals that are escape sequences in Java

'b' the backspace character 't' the tab character '\' the backslash ''' single quote '"' double quote 'n' linefeed 'r' carriage return

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 ...

Command to execute java jar application

To run an application packaged as a JAR file we require the Main-class manifest header. The command is:java -jar app.jar

Run an applet packaged as a JAR file

JAR file operations in Java

Operation ...

Reserved keywords in Java

abstract assert boolean break ...

Recursive factorial in Java

/** * This class shows a recursive method to compute factorials. This method * calls itself repeatedly based on the formula: n! = ...

Compute factorial of a number in Java

/** * A useful method for computing factorial of a given number **/public class Factorial { /** Compute and return x!, the factorial of ...

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; // ...

Fibonacci Series in Java

/** * This program prints out the first 20 numbers in the Fibonacci sequence. * Each term is formed by adding together the ...

Set classpath for Java

Under windows system:C:\> set CLASSPATH=.;c:\mysourcecodedirOn unix using a csh shell% setenv CLASSPATH .:/home/mani/mysourcecodedirWith the sh or bash shell, the command is:$ ...

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 ...

eXTReMe Tracker