/* Q.38) Develop a java application to represent one employee - TopicsExpress



          

/* Q.38) Develop a java application to represent one employee information Give data to Employee & display the same ? */ // EmployeeInfoGiveAndDisplay.java class EmployeeInfoGiveAndDisplay { int empno; String name; float salary; void giveDataToEmployee() { empno = 1001; name = Ram; Salary = 5000; }//giveDataToEmployee Method(this instance method give some state to the object) void displayEmployeeDetails() { System.out.println(Employee Number : +empno); System.out.println(Employee Name : +name); System.out.println(Employee Salary : +Salary); }//displayEmployeeDetails(this Instance Method Displays State of the Object) }//class EmployeeInfoGiveAndDisplay class CallEmployeeInfoGiveAndDisplay { public static void main(String args[]) { EmployeeInfoGiveAndDisplay e = new EmployeeInfoGiveAndDisplay() e.giveDataToEmployee(); e.displayEmployeeDetails(); }//main method }//class CallEmployeeInfoGiveAndDisplay /* OUTPUT riddhi@debian7:~$ javac CoreJava/EmployeeInfoAcceptAndDispay.java riddhi@debian7:~$ cd CoreJava/ riddhi@debian7:~/CoreJava$ java EmployeeInfoAcceptAndDispay Enter The Employee Number/id : 12 Enter The Employee Name : we Enter The Employee Gender : m The Employee id/number is : 12 The Employee name is : we The Employee Gender is : m riddhi@debian7:~/CoreJava$ *//* what happens in background When followong command is given to commandLine java CallEmployeeInfoGiveAndDisplay JVM loads CallEmployeeInfoGiveAndDisplay Application.class file from secondary memory (hard Disk) into Primary Memory(RAM) , but EmployeeInfoGiveAndDisplay.class file not yet loaded JVM encounters bytecode of the following source code once it invoked the main method. EmployeeInfoGiveAndDisplay e = new EmployeeInfoGiveAndDisplay() JVM Loads EmployeeInfoGiveAndDisplay.class into memory as it encoutered the syntax to create the object. Actual Object creation Systax in that line of code is new EmployeeInfoGiveAndDisplay() once JVM receive the above instructions, it does 4 things in the background 1.JVM Construct the object 2.JVM gives Default Values to the instance variables of the object. 3.JVM calls the constructor. 4.JVM Generates a unique number call HashCode by taking the starting byte address of the object as input & returns the same to the application that is stored in the reference variable. Note :- e is the reference variable or simply reference in the above example. An Object is uniquley identified through hashcode only and that hashcode is stored in reference only therefore , reference (reference variable ) acts as the name of the object. e.giveDataToEmployee(); main method is calling giveDataToEmployee() method on the EmployeeInfoGiveAndDisplay object using the EmployeeInfoGiveAndDisplay Reference. Limitation of above (program)application => Any number of object we created from the same class, all the object will have same structure and behaviour. For practical reasons it is not available to have the SAME STATE to multiple objects. giveDataToEmployee() method providing same state to every object of Employee class in the application. This method is a not parameteries method in EmployeeInfoGiveAndDisplay class by making it parameteries, the above limitation can overcome. for eg. void giveDataToEmployee(int eno,String nm,float sal) { empno=eno; name=nm; Salary=sal; }//giveDataToEmployee() method During method Defination, within the method header(i.e. within parenthesis declared variables or) parameters during method call; Supplied values call arguments; */ https://facebook/pages/Java-HELPS/254782647876155?ref_type=bookmark https://facebook/groups/LetsTalkOnJavaProjects/ https://facebook/VitthalAradwad
Posted on: Mon, 14 Jul 2014 12:53:00 +0000

Trending Topics



Recently Viewed Topics




© 2015