Download presentation
Presentation is loading. Please wait.
Published byDortha Lyons Modified over 6 years ago
1
Object-Oriented programming for Beginners LEAPS Computing 2015
Ioannis Efstathiou (slides originally made by Rajiv Murali) Heriot-Watt University
2
Learning Outline Setting up Eclipse Simple HelloWorld program.
Basic Object-Oriented Programming Concept What is an Object? What is a Class? Language Basics Variables Operators Expressions, Statements and Blocks Control Flow Statements Conditional Statements,Loop statements Methods
3
Simple Eclipse Start-Up
4
Creating a Java Project in Eclipse IDE
Step 1: Start Eclipse Step 2: Click File > New > Java Project Step 3: Enter a Project name, e.g. “JavaTutorial”, and click “Finish”. Step 4: Right-click on the project folder and select New > Class. Step 5: Enter “HelloWorldDemo” as the name, and click “Finish”. Step 6: Edit the HelloWorldDemo.class file as follows: public class HelloWorldDemo { public static void main(String args[ ]) { System.out.println("Hello World!"); } Step 7: Run the HelloWorldDemo.class.
5
Assignment HelloWorld
In this assignment I want you to use the HelloWorldDemo Class to: output the following message : “Hello World! my name is #your name here#!”
6
Object-Oriented Programming
7
Object-Oriented Programming
Java is an Object-Oriented Programming Language. Before you begin writing Java code, you will need to learn a few basic object-oriented concepts. This lesson will introduce you to: what is an Object? what is a Class? To help better understand these concepts, we will relate them to examples Java code that you will run in your Eclipse IDE.
8
What is an Object? Look around right now and you'll find many examples of real-world objects: your desk, your books, your computers and even yourselves. Objects share two characteristics: State and Behaviour. For example an object Person may have: state - name, age, weight, etc. behavior - walking, eating, sleeping, etc. Take a minute and think of some examples of Objects around you, with some state and behaviour.
9
Objects in Software Similar to real-world objects, software objects also consist of state and behaviour. A software object stores its... states in fields, also known as variables in most programming languages. while its behaviour is exposed through methods. age name eating sleeping walking weight an Object - Student Methods help to operate an object's internal state.
10
What is a Class? Often there are many individual objects of the same kind. There are billions of people in existence, and all people fall under the kind human. A Class helps to capture the common features of objects. And from a Class, many instances of Objects may be created. In object-oriented terms, we say that an Object person is an instance of a Class Human.
11
What does Class Human look like in code?
int age; string name; void increaseAge() { age++; } void setNameandAge(String parameterName, int parameterAge) { name = parameterName; age = parameterAge; void printHumanInfo() { System.out.println(“Name: ”+ name); System.out.println(“Age: ” +age); Field / Variable Methods
12
Creating an object from Human Class…
We want to create a person from our human class... But the Human class is not a complete application! It does not contain a main method. The responsibility of creating and using people from the human class belongs to another application….
13
HumanDemo Class The HumanDemo Class helps creates an instance frank of the Human class. We then set the name and age of Frank to 10. class HumanDemo { public static void main(String[] args){ Human frank = new Human(); frank.setNameandAge(“Frank”, 10); frank.printHumanInfo(); } Program Execution Creates an instance frank from the Human Class. Sets the name and age of frank. Prints the information of frank.
14
Assignment HumanDemo In this assignment I want you to use the HumanDemo Class to: 1. Set the age of frank to 100. 2. Set the name of frank to “Frankenstein”. 3. Print the current information. 4. Then increase Franks age by 3. 5. And finally, print the information again.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.