My Opera is closing 1st of March

Java

Java programming

Java programs

Java programs: Java programming code consists of instructions which will be executed on your computer system to perform a task as an example say arrange given integers in ascending order. This page contains examples for beginners to understand how to use java programming for beginners to write simple Java programs. These codes demonstrate how to get input from user, working with loops, strings and arrays. Programs are provided with output (image file) and you can also download class file and execute it directly without compiling the source file.

Compiling and executing java programs
To compile and run Java program code you need to download JDK (Java Development Kit).

To compile type: javac file_name.java where file_name is name of file containing java source code.
Javac is the Java compiler which converts java code into bytecode.

To run type: java main_method_class where main_method_class is the name of class which defines main method.

Java program example
Example 1: Display message on computer screen.

class First {
public static void main(String[] arguments) {
System.out.println("Let's do something using Java technology.");
}
}
This is similar to hello world java program. Download java programming class file.

Output of program:
Java program output

Example 2: Print integers

class Integers {
public static void main(String[] arguments) {
int c; //declaring a variable

/* Using for loop to repeat instruction execution */

for (c = 1; c <= 10; c++) {
System.out.println(c);
}
}
}
Output:
10 natural numbers java program

If else control instructions:

class Condition {
public static void main(String[] args) {
boolean learning = true;

if (learning) {
System.out.println("Java programmer");
}
else {
System.out.println("What are you doing here?");
}
}
}
Output:
If else java program

Command line arguments:

class Arguments {
public static void main(String[] args) {
for (String t: args) {
System.out.println(t);
}
}
}
Command line arguments
Java programming language
Below is the list of java programs which will help you in learn java programming language.
java web hosting

Write a comment

New comments have been disabled for this post.

February 2014
M T W T F S S
January 2014March 2014
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28