Friday, May 13, 2016

Java Introduction

Introduction of Java

Java is a powerful tool for internet development projects. It is a simplified version of C++. According to Sun Microsystems, Java is a simple, object-oriented, statically typed, complied, architecture neutral, multi-threaded, garbage collected, robust, secure, and extensible.
Java can be used to create two types of programs:
-applets applications
-standalone applications

Below shown are some of the important things to keep in mind about Java program:
• Case Sensitivity - Java is case sensitive, which means identifier Hello and hello would have different meaning in Java.
• Class Names - For all class names, the first letter should be in Upper Case.   If several words are used to form a name of the class, each inner word's first letter should be in Upper Case.  Example class MyFirstJavaClass
 • Method Names - All method names should start with a Lower Case letter.   If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case.  Example public void myMethodName()
• Program File Name - Name of the program file should exactly match the class name.   When saving the file, you should save it using the class name (Remember Java is case sensitive) and append '.java' to the end of the name (if the file name and the class name do not match your program will not compile).  Example : Assume 'MyFirstJavaProgram' is the class name, then the file should be saved as'MyFirstJavaProgram.java'
public static void main(String args[]) - Java program processing starts from the main() method, which is a mandatory part of every Java program.


OOP(Object Oriented Programming)

It enables us to think of program elements as objects. It is just a way to hide the details of program. The main concepts that are the backbones of OOP should  be understood to learn about OOP. They are
1.       Encapsulation
2.       Inheritance
3.       Polymorphism

Java Development Kit(JDK)

We needs to get a recent copy of the Java JDK in order to get started in Java programming. This can be obtained for free by downloading it from the Sun Microsystems website
In order to program for java, there are certain IDEs that helps us to work easily for programming. Some of the IDEs are as follows:
You can use any one of these IDEs.


First Java Program
public class Example1 {
public static void main(String args []) {
System.out.println("Hello this is my first java program");
}
}

Run the above program and the output will be :


OUTPUT:
Hello this is my first java program


example for getset array

Here i am going to show you the use of get set array in java.


package setgetarray;
import java.util.Scanner;
public class SetGetArray {

    int i;

    Scanner sc= new Scanner(toString());
    int rollNo[]=new int[2];
    float marks[] = new float[2];
    String info[]=new String[2];

    public void setInfo(){

        System.out.println("Enter the student no:");
        //this.n= sc.nextInt();
        for (i=0;i<2;i++){
            System.out.println("student roll:");
            sc.nextInt();
            System.out.println("student marks");
            sc.nextFloat();
            System.out.println("student info");
            sc.nextLine();
        }

    }
    public void getInfo(){
        System.out.println("student info:");
        for(i=0;i<2;i++){

            System.out.println("student roll:"+rollNo);
            System.out.println("student marks"+marks);
            System.out.println("student info"+info);
        }

    }
}

Thursday, May 12, 2016

Example of array

Simple example of array is shown below:


package monthactual;

import java.util.Scanner;

public class MonthActual {
    int n;
    String[] month= { "january","february","march","april","may","june","july","august","september","october","november","december"};
    Scanner sc=new Scanner();
    public void actualMonth(){
        for (int i=0;i<month.length; i++){
            System.out.println("Enter the no of month:");
            this.n=sc.nextInt();
            System.out.println("the actual month is" +month[n]);

        }
    }
}

Tuesday, May 10, 2016

java functions

java Functions are most strong to handle the operations with global variables and arguments passed to it. the variables defined inside the java functions are always local and  are only available inside function only. Function can return any value of the class type. We can consider data type int, float, String etc as a Class type. In function one can return Object typed java.
Here is one simple function illustrated for concept of java array.
 public void setStudentArray(){
        for(int i=0;i<num;i++){

            HasStudent student=new HasStudent();
            System.out.println("======***********========");
            student.name=setName();
            student.Address=setAddress();
            student.rollNo=setRoll();
            stdArray[i]=student;
            System.out.println("======***********========");

        }
    }
In this function there is no return type and no argument. only local and global variables available inside the functions are processed with this function and are available when callng the function

we can declare function with the return type as follows:

(Access_Specifier) (ClassName) functionName(arguments.
class definintions;
processing of local and global datas.
return(Object of class);
}