Showing posts with label simple java code. Show all posts
Showing posts with label simple java code. Show all posts

Thursday, 24 January 2013

Java Program to convert Lower Case Letter in to Uppper Case

Conversion of Lower Case letter to UpperCase in JAVA

toUpperCase(char ch) and toLowerCase(char ch) functions in Java

Syntax: public static char toUpperCase(char ch)

Converts the character argument to uppercase using case mapping information from the UnicodeData file. Note that Character.isUpperCase (Character.toUpperCase(ch)) does not always return true for some ranges of characters, particularly those that are symbols or

Wednesday, 16 January 2013

Java Separators

Separators in Java

Separators used in Java Programming Lanuage

Separators help define the structure of a program. The separators used in HelloWorld are parentheses, ( ), braces, { }, the period, ., and the semicolon, ;. The table lists the six Java separators (nine if you count opening and closing separators as two). Following are the some characters which are generally used as the separators in Java.

It is used to separate the package name from sub-package name & class name. It is also used to separate variable or method from its object or instance.
It is used to separate the consecutive parameters in the method definition. It is also used to separate the consecutive variables of same type while declaration.
It is used to terminate the statement in Java.
This holds the list of parameters in method definition. Also used in control statements & type casting.
This is used to define the block/scope of code, class, methods.
It is used in array declaration.
Separators in Java

Saturday, 5 January 2013

Creating First Java Application

Java Simple Hello World! Program

A program to print the Hello World! message on the Computer screen.

You can use the notepad as an editor to write your first program. Read the below codes and carefully write on your editor as Java is case sensitive.

Hello World! code

class HelloWorld {
    public static void main (String args[]) {
System.out.println(“Hello World!”);

This is the simple base program of Java. I will explain you line by line to get an idea about the unique features that constitute a Java Program. 

Class Declaration: class HelloWorld

This line declares a class, which is an object oriented construct. We must place all codes inside a class in Java. class is a keyword and declares that a new class definition follows. HelloWorld is the Java identifier that specifies the name of the class to be defined. 

Opening and Closing Braces :{  }

Every class definition in Java begins wih an opening brace "{" and ends with a matching closing brace "}", appearing in the last line in the example.

The Main Line: public static void main (String args[])

This line defines a method named main. Conceptually, this is similar to the main() fuctnion in C and C++; Every Java application program must include main() method. This is the starting point for the interpreter to begin the execution of the program. 

public : The keyword public is an access specifier that declares the main method as unprotected and therefore making it accessible to all other classes.
static:  Static declares this method as one that belongs to the entire class and not a part of any objects of the class. The main method must always be declared as static since the interpreter uses this method before any objects are created. 
void: The type modifier void states that the main method does not return any value.

The Output Line: System.out.println(“Hello World!”);

This is similar to a printf() statement in C++. Since Java is Object Oriented, every method must be part of an object. The println() method is member of the out object, which is a static data member of System class. 

Every Java statement must end with a semicolon.

Note: We must save this program in a file called ensuring that the file name contains class name properly. This file is called the source file. If the program contains multiple classes, the file name must be the class name of the class containing the main method. 

Compiling the Program

To compile the Program, we should run the Java Compiler javac with the name of then source file on the command line as shown below:

Running the Program

We need to use the Java interpreter to run stand alone program. See the below line. 

java Helloworld