Java: Java Programming For Beginners a simple Start To Java Programming (Written By a software Engineer)


Download 0.82 Mb.
Pdf ko'rish
bet12/95
Sana09.01.2022
Hajmi0.82 Mb.
#261112
1   ...   8   9   10   11   12   13   14   15   ...   95
Bog'liq
Java Programming For Beginners - A Simple Start to Java Programming ( PDFDrive )

Java Packages
Basically,  it  is  a  method  for  classifying  the  classes  and  interfaces.  At  the  point  when
creating  applications  in  Java,  many  classes  and  interfaces  will  be  composed.  In  such  a
scenario, ordering these classes is an unquestionable requirement and makes life much less
demanding.  In  Java,  if  a  completely  qualified  name,  which  incorporates  the  class  and
package name, is given, then the compiler can without much of a stretch find the source
code  or  classes.  Import  declarations  is  a  method  for  giving  the  correct  area  for  the
compiler to find that specific class.
Case  in  point,  in  order  to  load  all  the  classes  accessible  in  java_installation/java/io,  you
must use the following statement:
import java.io.*;
A sample implementation for this concept is given below:
The  following  code  uses  two  classes  Employeerecord  and  Employeerecordtest.  The  first
step is to open the text editor you intend to use at your system and copy and paste the code
shown below into the text editor application. Keep in mind that the public class in the code
is Employeerecord. Therefore, the name of the file should be Employeerecord.java. This
class uses the variables, methods and constructor as shown below:
import java.io.*;
public class Employeerecord {
int empage;
String empname;
double empcompensation;
public Employee(string empname){
this.empname = empname;
}
public void employeeage(int employeeage){
empage = employeeage;
}


public void empcompensation(double empcompensation){
empcompensation = empcompensation;
}
public void printemp(){
System.out.println(“empname:”+ empname );
System.out.println(“empage:” + empage );
System.out.println(“empcompensation:” + empcompensation);
}
As  specified  awhile  ago  in  this  exercise,  handling  begins  from  the  main  function.
Accordingly,  with  this  goal,  we  should  create  a  main  function  for  this  Employeerecord
class.  Given  beneath  is  the  Employeerecordtest  class,  which  makes  two  instances  of  the
class  Employeerecord  and  conjures  the  techniques  for  each  one  item  to  allot  values  for
every variable. You can save this file as Employeerecordtest.java.
import java.io.*;
public class Employeerecordtest{
public static void main(String args[]){
Employeerecord employee1 = new Employeerecord(“Jack Wright”);
Employeerecord employee2 = new Employeerecord(“Mary John”);
employee1.employeeage(32);
employee1.empcompensation(5000);
employee2.employeeage(25);
employee2.empcompensation(2000);
employee1.printemp();
employee2.printemp();
}
}
Upon compilation and execution, you must get the following output:
empname: Jack Wright


empage: 32
empcompensation: 5000
empname: Mary John
empage: 25
empcompensation: 2000




Download 0.82 Mb.

Do'stlaringiz bilan baham:
1   ...   8   9   10   11   12   13   14   15   ...   95




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling