Objects, Classes and Syntax Dr. Andrew Wallace PhD BEng(hons) EurIng

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Written by: Dr. JJ Shepherd
 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
Introduction to Primitives. Overview Today we will discuss: –The eight primitive types, especially int and double –Declaring the types of variables –Operations.
1 Data types, operations, and expressions Overview l Primitive Data Types l Variable declaration l Arithmetical Operations l Expressions.
Some basic I/O.
1 Data types, operations, and expressions Overview l Format of a Java Application l Primitive Data Types l Variable Declaration l Arithmetic Operations.
Programming Principles Data types and Variables. Data types Variables are nothing but reserved memory locations to store values. This means that when.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Classes, Objects, Arrays, Collections and Autoboxing Dr. Andrew Wallace PhD BEng(hons) EurIng
BPJ444: Business Programming Using Java Classes and Objects Tim McKenna
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.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
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.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Copyright Curt Hill Variables What are they? Why do we need them?
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Java Nuts and Bolts Variables and Data Types Operators Expressions Control Flow Statements Arrays and Strings.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Chapter One Lesson Three DATA TYPES ©
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Java: Variables and Methods By Joshua Li Created for the allAboutJavaClasses wikispace.
A data type in a programming language is a set of data with values having predefined characteristics.data The language usually specifies:  the range.
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
Data Types References:  Data Type:  In computer science and computer programming, a data type or simply type is a.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
Object Oriented Programming Lecture 2: BallWorld.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Java: Base Types All information has a type or class designation
Topics introduced today (these topics would be covered in more detail in later classes) – Primitive Data types Variables Methods “for” loop “if-else” statement.
Information and Computer Sciences University of Hawaii, Manoa
Topic: Classes and Objects
Objects as a programming concept
3 Introduction to Classes and Objects.
Java: Base Types All information has a type or class designation
Yanal Alahmad Java Workshop Yanal Alahmad
Lecture 2: Data Types, Variables, Operators, and Expressions
Variables and Primative Types
Selenium WebDriver Web Test Tool Training
Chapter 2.
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
Chapter 3 Introduction to Classes, Objects Methods and Strings
Unit-2 Objects and Classes
Computers & Programming Languages
Introduction to Java Programming
An Introduction to Java – Part I, language basics
Classes & Objects: Examples
Chapter 2: Java Fundamentals
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Recap Week 2 and 3.
Java Basics Data Types in Java.
Names of variables, functions, classes
Chap 2. Identifiers, Keywords, and Types
Introduction to java Part I By Shenglan Zhang.
Presentation transcript:

Objects, Classes and Syntax Dr. Andrew Wallace PhD BEng(hons) EurIng

Overview Objects Classes Syntax

Objects

A “real, existing, item” “Instance” of a class

Classes Class Specifies attributes and methods for an object Encapsulated data Template Create objects from Instantiate

Quiz Define “class” in the context of OO design. Define “object” in the context of OO design.

Syntax Computers only do what they are told! You have to be priciest what and how you tell a computer what to do! Exactly!

Syntax Syntax diagram Start point Term Identify Path Termination = Expression

Syntax Variable A box to put things in Can change! nUsefullBox 25

Syntax private int nVar; protected floatfVar; StringsText; ExpressionIdentifier;

Syntax Identifiers Java Letter Java Digita.. z A.. Z $ _ OtherJava Letter 0.. 9

Syntax nText12 $Text m_oObj2 12Def #we23

Syntax Primative type Class type Identifier, ;

Syntax private int nVar; protected floatfVar; StringsText;

Syntax Variables are: Boxes you save data in You have to declare variables What type are they? What names does it have?

Syntax Class type Built into Java Data + methods Create your own User defined String Integer FileDialog

Syntax Primitive data types Built into Java int – integer (whole numbers) short long float – real numbers (approximately) double boolean – logical. True or false char – a single Unicode character byte – 8 bits of data

Syntax TypeSizeMinMax byte8 Bits short16 bits int32 bits long< -9 x > -9 x float32 bits+/- 3.4 x decimal digits double64 bits+/- 1.7 x decimal digits

Quiz Define “variable” in the context of software engineering List the inbuilt primitive data types in Java

Syntax Char Unicode character 16 bits unique characters A.. Z, Å, Ä, Ö, 1.. 9, Æ Ë Σ Ω ش הּ Ordered Numbered \u2000 = 丠

Syntax Boolean True or false Used in comparisons Not a number Not the same as C

Syntax Objects Instances of classes How to create an object? StringstrText = new String();

Syntax Constructor A method called when the object is created Sets up the object Same name as the class No return type New Key word in Java Used when creating an object Create the object in memory

Syntax StringstrText = new String(); Reference A variable that tells use where to find an object A pointer Value What’s in the box Primitive data type Hello World strText

Syntax Aliasing More than one variable can point to the same object StringstrText1 = new String(); StringstrText2 = strText1; Hello World strText1 strText2

Syntax Garbage collection When an object no longer has a reference pointing to it Hello World strText

Syntax class identifier Class associations Class body modifier { } Class member Field declaration Constructor declaration Method declaration

Syntax public class HelloWorld { }

Syntax public static void main(String[] args) { System.out.println(“Hello World”); } type identifier Method body modifier parameters void

Quiz List the parts of a class definition used in Java List the parts of a method definition in Java

Syntax public class HelloWorld { public static void main(String[] args) { System.out.println(“Hello World”); }

Syntax public class FunctionCall { private intm_nCount = 0; public void func1() { m_nCount++; System.out.println(“Count is : “ + m_nCount); } public static main(String[] args) { func1(); }

Questions?