Download presentation
Presentation is loading. Please wait.
Published byVictor Blair Modified over 8 years ago
1
Introduction to java (class and object)
2
Programming languages: –Easier to understand than CPU instructions –Needs to be translated for the CPU to understand it Java –“Most popular” language –Runs on a “virtual machine” (JVM) –More complex than some (eg. Python) –Simpler than others (eg. C++)
3
First Program class Hello { public static void main(String[] arguments) { // Program execution begins here System.out.println("Hello world."); }
4
How to run?
5
Create the path information file: –Open txt file –Use the command set to refer to: Java home Bin file –Save the file name.bat Run a command DOS windows Run the path file first Use the command javac to compile your java file Use the command java to execute your.class file Can you see any out put? set JAVA_HOME=C:\jdk set PATH=%PATH%;c:\jdk\bin;
6
Java code structure class CLASSNAME { public static void main(String[] arguments) { STATEMENTS }
7
Can you write a program to print a student card. Name: Mohamed Elshaikh School : Computer ID: 0990981 Job: Student
8
Assignment Used to give values to the variables. Example: Name= ali; class Hello3 { public static void main(String[] arguments) { String name = “Mohamed elshaikh"; String school=“ computer”; String job=“student”; Int id=123432; System.out.println(“Name :”+name); System.out.println(“ School :”+school); System.out.println(“ID :”+id); System.out.println(“ Job :”+job); }
9
Card example as a class Attributes –Name –School –Id Methods –Print the card –Get the name
10
Card in java Create the class –Create the instructor –Declare the attributes –Declare the methods The object –A new variable for the class type –Created by the constructor –Can use the methods –Created in the program body
11
Lets cod it public class Card { // the Card class has three fields public String name; public String school; public int id; public String job; // the Card class has one constructor public Card(String n,String s,String j,int i) { name = n; school =s; job = j; id = i; } // the Card class has three methods public void setName(String s) { name = s; } public String getName() { return name; } public void printCard() { System.out.println("Name :"+name); System.out.println("School :"+school); System.out.println("ID :"+id); System.out.println("Job :"+job); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.