Download presentation
Presentation is loading. Please wait.
Published byClaud Higgins Modified over 8 years ago
1
Objects, Classes and Syntax Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se
2
Overview Objects Classes Syntax
3
Objects
4
A “real, existing, item” “Instance” of a class
5
Classes Class Specifies attributes and methods for an object Encapsulated data Template Create objects from Instantiate
6
Quiz Define “class” in the context of OO design. Define “object” in the context of OO design.
7
Syntax Computers only do what they are told! You have to be priciest what and how you tell a computer what to do! Exactly!
8
Syntax Syntax diagram Start point Term Identify Path Termination = Expression
9
Syntax Variable A box to put things in Can change! nUsefullBox 25
10
Syntax private int nVar; protected floatfVar; StringsText; ExpressionIdentifier;
11
Syntax Identifiers Java Letter Java Digita.. z A.. Z $ _ OtherJava Letter 0.. 9
12
Syntax nText12 $Text m_oObj2 12Def #we23
13
Syntax Primative type Class type Identifier, ;
14
Syntax private int nVar; protected floatfVar; StringsText;
15
Syntax Variables are: Boxes you save data in You have to declare variables What type are they? What names does it have?
16
Syntax Class type Built into Java Data + methods Create your own User defined String Integer FileDialog
17
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
18
Syntax TypeSizeMinMax byte8 Bits-128127 short16 bits-32 76832 767 int32 bits-2 147 483 6482 147 483 647 long< -9 x 10 18 > -9 x 10 18 float32 bits+/- 3.4 x 10 38 7 decimal digits double64 bits+/- 1.7 x 10 308 15 decimal digits
19
Quiz Define “variable” in the context of software engineering List the inbuilt primitive data types in Java
20
Syntax Char Unicode character 16 bits 65 536 unique characters A.. Z, Å, Ä, Ö, 1.. 9, Æ Ë Σ Ω ش הּ Ordered Numbered \u2000 = 丠 www.unicode.org
21
Syntax Boolean True or false Used in comparisons Not a number Not the same as C
22
Syntax Objects Instances of classes How to create an object? StringstrText = new String();
23
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
24
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
25
Syntax Aliasing More than one variable can point to the same object StringstrText1 = new String(); StringstrText2 = strText1; Hello World strText1 strText2
26
Syntax Garbage collection When an object no longer has a reference pointing to it Hello World strText
27
Syntax class identifier Class associations Class body modifier { } Class member Field declaration Constructor declaration Method declaration
28
Syntax public class HelloWorld { }
29
Syntax public static void main(String[] args) { System.out.println(“Hello World”); } type identifier Method body modifier parameters void
30
Quiz List the parts of a class definition used in Java List the parts of a method definition in Java
31
Syntax public class HelloWorld { public static void main(String[] args) { System.out.println(“Hello World”); }
32
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(); }
33
Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.