标签:ati opened sys sig eth closed system pre struct
用记事本编写两个java文件
第一个Employee.java
import java.io.*; public class Employee{ String name; int age; String designation; double salary; // This is the constructor of the class Employee public Employee(String name){ this.name = name; } // Assign the age of the Employee to the variable age. public void empAge(int empAge){ age = empAge; } /* Assign the designation to the variable designation.*/ public void empDesignation(String empDesig){ designation = empDesig; } /* Assign the salary to the variable salary.*/ public void empSalary(double empSalary){ salary = empSalary; } /* Print the Employee details */ public void printEmployee(){ System.out.println("Name:"+ name ); System.out.println("Age:" + age ); System.out.println("Designation:" + designation ); System.out.println("Salary:" + salary); } }
第二个EmployeeTest.java
import java.io.*; public class EmployeeTest{ public static void main(String args[]){ /* Create two objects using constructor */ Employee empOne = new Employee("James Smith"); Employee empTwo = new Employee("Mary Anne"); // Invoking methods for each object created empOne.empAge(26); empOne.empDesignation("Senior Software Engineer"); empOne.empSalary(1000); empOne.printEmployee(); empTwo.empAge(21); empTwo.empDesignation("Software Engineer"); empTwo.empSalary(500); empTwo.printEmployee(); } }
打开cmd
进入文件所在目录
运行 javac Employee.java
看目录变化,会出现一个Employee.class
在运行 javac EmployeeTest.java
又会多出来一个EmployeeTest.java
在运行 java EmployeeTest
会出现运行结果
这说明了什么呢?
命令 javac 是编译器,将java源文件编译成了可以被JVM(java虚拟机)读懂的文件
命令 java 是执行代码,JVM将class文件编译为字节码文件 让计算机可以读懂
所以 常常说的编译,是将源文件编译成JVM(虚拟机)需要的class文件
常常说的执行 是JVM读class文件并让计算机运行代码
C :> javac Employee.java C :> javac EmployeeTest.java C :> java EmployeeTest Name:James Smith Age:26 Designation:Senior Software Engineer Salary:1000.0 Name:Mary Anne Age:21 Designation:Software Engineer Salary:500.0
标签:ati opened sys sig eth closed system pre struct
原文地址:https://www.cnblogs.com/tanfuchao/p/9718617.html