Tuesday, January 22, 2013

Core Java Concept

                              Core Java Concept Drive 1


Introduction:

What is Java?
Java is an object-oriented, cross platform, Multi purpose programming language produced by Sun Micro systems  First released in 1995, it was developed to be a machine independent web technology. It was based on C and C++ syntax to make it easy for programmers from those communities to learn.
Platform independence - Many languages are compatible with only one platform. Java was specifically designed so that it would run on any computer, regardless if it was running Windows, Linux, Mac, Unix or any of the other operating systems.
Simple and easy to use - Java's creators tried to design it so code could be written efficiently and easily.
Multi-functional - Java can produce many applications from command-line programs to applets to Swing windows (basically, sophisticated graphical user interfaces).

Major release versions of Java, along with their release dates:
JDK 1.0 (January 21, 1996)
JDK 1.1 (February 19, 1997)
J2SE 1.2 (December 8, 1998)
J2SE 1.3 (May 8, 2000)
J2SE 1.4 (February 6, 2002)
J2SE 5.0 (September 30, 2004)
Java SE 6 (December 11, 2006)
Java SE 7 (July 28, 2011) <=Latest
Platform independent ("Write Once, Run Anywhere")
àIn other languages, the source code (code that is written by the programmer), is compiled by a compiler into an executable file. This file is in machine language, and is intended for a single operating system/processor combination, so the programmer would have to re-compile the program separately for each new operating system/processor combination.
àBut Java is different in that it does not compile the code directly into machine language code. Compilation creates bytecode out of the source code.
àWhen the code is run by the user, it is processed by something called the Java Virtual Machine (JVM). The JVM is essentially an interpreter for the bytecode. It goes through the bytecode and runs it. There are different versions of the JVM that are compatible with each OS and can run the same code.




Fetch Employee Details using Java Array

First Step:
Employee.java

package EmployeePayroll;

public class Employee 
{

public int[] Emp_id;
public String[] Emp_Name;

public int[] getEmpId() 
{
return Emp_id;
}

public void setEmpId(int[] empId)
{
Emp_id = empId;
}

public String[] getEmp_Name() {
return Emp_Name;
}

public void setEmp_Name(String[] emp_Name) {
Emp_Name = emp_Name;
}

}
---------------------------------------------------------------------------------------------------------------------------

After Then:

Executable.java


package EmployeePayroll;

import java.util.Scanner;

public class Executable {



private static Scanner input;

public static void main(String args[])
{
input = new Scanner(System.in);
System.out.print("eNTER ID");
Employee e=new Employee();
int Emp_id[]=new int[10]; 
String Emp_Name[]=new String[10];
 

 
for (int i = 0; i <10; i++){

Emp_id[i] = input.nextInt();
Emp_Name[i]=input.next();

e.setEmpId(Emp_id);
e.setEmp_Name(Emp_Name);
 


}
 for (int i = 0; i <10; i++){

 
 
System.out.println(e.getEmpId()[i]+"and "+e.getEmp_Name()[i]);


}
 
 


}
}


Intput Command Line:

ENTER ID
1
arpit
2
dshdk
3
dskdh
4
fdfd
5
fdfd
6
dfdf
7
dfd
8
dfd
9
fdf
10
fdf
Output: 
1and arpit
2and dshdk
3and dskdh
4and fdfd
5and fdfd
6and dfdf
7and dfd
8and dfd
9and fdf
10and fdf