1 Class 1 Lecture Topic Concepts, Definitions and Examples.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

Animation Mrs. C. Furman. Animation  We can animate our crab by switching the image between two pictures.  crab.png and crab2.png.
Georgia Institute of Technology DrJava Appendix A Barb Ericson Georgia Institute of Technology May 2006.
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
How to Create a Java program CS115 Fall George Koutsogiannakis.
Fall 2007ACS-1903 BlueJ Ron McFadyen Lab 1: Using BlueJ at UofW The purpose of this lab is to give you some experience with BlueJ. Over the course of the.
Getting Started with Java
Writing Methods. Create the method Methods, like functions, do something They contain the code that performs the job Methods have two parts.
CompSci Computer Science 4: Java for Video Games Jam Jenkins D305 LSRC Dietolf (Dee) Ramm D226 LSRC Instructor
Recitation 1 Programming for Engineers in Python.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
Karel J Robot An introduction to BlueJ and Object- Oriented Programming.
Visual Programming Fall 2012 – FUUAST Topic: Development environment.
CompSci 42.1Intro to Java Anatomy of a Class & Terminology Running and Modifying a Program.
Introduction to Object-Oriented Programming
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
The Java Programming Language
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
1 COSC3557: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University.
CPSC1301 Computer Science 1 Overview of Dr. Java.
How to Run a Java Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
Hello World in the Forte IDE An introduction to the Forte IDE (integrated development environment) writing the classic “Hello World” program in Java.
Unit 1: Java and Eclipse The Eclipse Development Environment.
Comments in Java. When you create a New Project in NetBeans, you'll notice that some text is greyed out, with lots of slashes and asterisks:
Output in Java Hello World!. Structure of a Java Program  All Java files in ICS3U1 have the following structure: class HelloWorld { }  Notice the open.
CSC1401 Classes - 1. Learning Goals Computing concepts Identifying objects and classes Declaring a class Declaring fields Default field values.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 6: Object-Oriented Programming.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 2 – Classes and objects.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Fall 2015CISC124 - Prof. McLeod1 CISC124 Have you filled out the lab section survey? (As of last night 54 left to fill out the survey.) TA names have been.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs -
1 Chapter Four Creating and Using Classes. 2 Objectives Learn about class concepts How to create a class from which objects can be instantiated Learn.
Introduction to Methods. Previously discussed There are similarities in make up of that can help you remember the construct of a class a class in the.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
EGR 2261 Unit 11 Classes and Data Abstraction  Read Malik, Chapter 10.  Homework #11 and Lab #11 due next week.  Quiz next week.
CS305j Introduction to Computing Classes II 1 Topic 24 Classes Part II "Object-oriented programming as it emerged in Simula 67 allows software structure.
Lecture 08. Since all Java program activity occurs within a class, we have been using classes since the start of this lecture series. A class is a template.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Topic 8Classes, Objects and Methods 1 Topic 8 l Class and Method Definitions l Information Hiding and Encapsulation l Objects and Reference Classes, Objects,
Introduction to Eclipse Programming with an Integrated Development Environment.
Java Programming, Second Edition Chapter Three Using Methods, Classes, and Objects.
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
CompSci 42.1Intro to Java Anatomy of a Class & Terminology Running and Modifying a Program.
Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 26, 2009.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Methods, classes, and Objects Dr. Jim Burns. Question  Which of the following access modifiers is the default modifier?  public  private  protected.
Appendix A Barb Ericson Georgia Institute of Technology May 2006
The eclipse IDE IDE = “Integrated Development Environment”
Topic: Classes and Objects
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Eclipse Navigation & Usage.
Chapter 3: Using Methods, Classes, and Objects
CompSci 230 Software Construction
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Introduction to Programming
The Boolean (logical) data type boolean
Introduction to Programming
Java Programming with BlueJ Objectives
Introduction to Object-Oriented Programming
Classes, Objects and Methods
Running a Java Program using Blue Jay.
Introduction to Programming
Workshop for Programming And Systems Management Teachers
Presentation transcript:

1 Class 1 Lecture Topic Concepts, Definitions and Examples

2 Introduction to Java Object-oriented programming Representation of reality Everything is an object and every object is a member of a class. What are the objects in this picture? What class does each object belong to? is-a relationship because you can say My dog Toby is a dog.

3 Instantiation An object is an instantiation of a class or a tangible example of a class. This object car is an example of the class car.

4 What are these is-a relationships?

5 Usefulness of Classes Reusable Objects inherit attributes and methods from classes

6 Sample Program Design When you were planning your spring schedule, what things did automatically know about a course? What is it that all course have in common?

7 Course Attributes Understand what a course entails from previous knowledge, these are the attributes. –attributes – these are your class variables a name, a number, etc. What things won’t you know? These are unique to the course?

8 Classes also have Methods associated with them. methods – actions get, set, doSomething You must set the date and time for a course. –setDate() –setTime() –getDate –getTime(). What you called functions in C are called methods in Java.

9 Two Parts to Object Oriented Programming 1.Create a class from which objects will be instantiated. 2.Write other classes to use the objects. a class client. CourseApplication is the client class of course.

10 Creating a Class Assign a name to the class. Determine attributes and methods that are part of class. For a class called Course, an instance variable (attribute) might be: –courseNumber Two methods might be to set the course number and get the course number. Instance Variable

11 First Step: Create a class header public class CourseApplicationAW An optional access modifier (public/abstract/final) The keyword class Legal identifier that you choose. After the above line is the opening { Closing } goes after all Instance Variables and Methods.

12 A Java class Course class Course { private int courseNo; public void setCourseNo(int cNo) { courseNo = cNo; } public int getCourseNo() { return courseNo; } Instance Variable Methods

13 Using Classes Declaring a class does not create actual object Class is an abstract description You might define an integer as int someValue; Define an object of Course as Course someCourse; Notify the compiler that an integer someValue exists and reserve computer memory When declaring someCourse not setting aside memory yet!

14 Creating Objects Allocating memory: –someCourse = new Course(); Or you could do in one step: Course someCourse = new Course(); –The keyword new indicates that someCourse is allocated memory. –Course() is the method that constructs the Course object.

15 Writing first program Need two classes First is called the driver class, –you will always have this class in your programs, –it will contain the main –Always call this class SomethingApplicationYourInitials, replace Something with term relevant to program, CourseApplicationAW Second class will be Course

16 The class CourseApplicationAW- First Attempt public class CourseApplicationAW { public static void main(String args[]) { Course someCourse = new Course(); } Allocates memory for someCourse, but no action takes place yet. CourseApplicationAW is the client class of course – (Has-A)

17 The class Course class Course { private int courseNo; public void setCourseNo(int cNo) { courseNo = cNo; } public boolean isFourThousandLevel() { if ((courseNo >=4000)&&(courseNo<5000)) return true; else return false; } The client class does not call these methods yet. Next Slide!

18 New class CourseApplicationAW – uses methods of Course public class CourseApplicationAW { public static void main(String args[]) { Course someCourse = new Course(); someCourse.setCourseNo(4567); System.out.println(someCourse.isFourThousandLevel()); } dot operator

19 Public and not Public All our classes are placed in same file. Only one public class allowed Other classes are private (not accessible from outside this program). Many other ways to approach this…

20 Improving the class Course What attributes can you add to the class Course? What methods can you add?

21 Moving On - Using Forte 1.Pictorially 2.Demonstrate Forte 3.You try it…

22 Starting Select/Open Forte for Java CE (slow) check the version number for Java

23 Forte for Java helpful hints window – close if appears tabs – select Editing tab indicates if a program is running

24 New Project Select Project/New Project Create New Project Window, name project – YourInitialsFirstProj select OK

25 Choose New If see above window – select Yes

26 Full Screen Image – working in window that says: Mount Directory

27 Mount Directory This is your working directory your files are saved here MUST be a directory Best to be a directory on floppy No directory on floppy, can make one at this stage.

28 Mount Directory make directory – if needed File Name refers to directory NOT a file. Mount – mounts working directory Created New Folder (you can name it), click on New Folder ONCE, Select Mount. New Folder appears as File Name.

29 Explorer Window Shows mounted directory, you can mount any number of directories this way. This Tab shows the project you created, any files you create go into project.

30 Java File all java program files end in.java done automatically compiled files are.class Need to create an empty java file.

31 Creating Program File highlight (left click on mounted directory) right click to bring up menu select new,classes,empty

32 Selecting Name – Must be IDENTICAL to public class VERY IMPORTANT – MUST MATCH CASE – Programming Convention – all Class Names – Capitalize each word Type Name Select Finish

33 Respond yes This places the file within the project you created. If select Project tab will see:

34 File Created and Ready to Code Your code goes here

35 Right Click in Source Editor will bring up menu to Save, Compile, Execute, etc. Reformat code – indents code for you – nice! Save Often – only lets you save if you’ve made a change to code Compile – checks for compilation error Execute – runs program

36 Type Code Here Save, Compile, Execute…

37 System.out.println – prints output to this window (usually at bottom of screen). true is the boolean value of the response to whether the courseNo is >=4000 and less than 5000

38 When You’re Finished Unmount file system exit Forte

39 Live Example

40 Lab Work Familiarization with Forte for Java Writing first program Improving program Writing second program

41 Next Week Survey Discussion List Assignment Quiz – see syllabus – (practice using Forte) write some small programs using two classes. Try the example programs pointed to from syllabus.