Introduction and Programming Basics
IAT-265, Spring 2022
School of Interactive Arts and Technology
Slides based on materials from IAT265 offerings by and
Copyright By PowCoder代写 加微信 powcoder
______________________________________________________________________________________
SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] | WWW.SIAT.SFU.CA
Teaching team
Instructor:
– Office hours:
• Mon 11:30am-12:20pm
• Online via ZOOM (To attend, please email to book appointments)
– Son Nguyen-Quang
• Fri 3:00pm~5:00pm
• Mon 1:00pm~3:00pm
– Location: TBA
January 9, 2022 IAT 265 2
About the course
Java: an OOP language
Two types of Java program: Application and Applet
File structures of Java program
Method, parameter, argument
Data types and Variables
January 9, 2022 IAT 265 3
About the course
Review and consolidate concepts such as variables, data types, conditionals, ArrayLists, loops, OOP , event-driven programming etc, with the most popular primary programming language – Java
Introduce new concepts: e.g. data hiding, inner class, abstract class, interface, event listener, timer, data structures, search, sorting, etc.
Learn to design multimedia programs using concept /software design, pseudo-coding-process(PPP), code refactoring, and Design Patterns
Learn to implement per the design using both native and external libraries
January 9, 2022 IAT 265 4
State of Language Ecosystem 2020
https://www.jetbrains.com/lp/devecosystem-2019/
January 9, 2022 IAT 265 5
Connection
between 167 and 265
The setting of the two courses are followed with the Spiral Model – iterative and incremental
Break complex concepts (like OOP) into components at different levels to conquer with iterations
Cover the basics of OOP and Event Driven Programming in the 1st iteration (done in 167)
Revisit those fundamental concepts in the next iteration to consolidate (done in 265)
Add new increments at higher level to strengthen (done in 265)
January 9, 2022 IAT 265 6
Design, Implement, test
Evaluation
Evaluation
Evaluation
ments ments
January 9, 2022
Building on IAT167
You need to know what you have learned in the prereq course
Mandatory Programming Proficiency quiz and
Self-efficacy survey in Canvas:
– Quiz: simple programming task, 60 minutes
• Due date: Sun Jan 16, midnight
– Survey: 10 questions, no time limit
• Due date: Mon Jan 17, midnight
January 9, 2022 IAT 265 8
Syllabus – anatomy along concepts
Computing concepts
– Advanced OOP concepts • Datahiding
• Dataaccessing/mutating • Abstractclass
• Javainterface
– Event driven programming – Recursion
Working with libraries
– Javanativelibrary
– Externallibraries(e.g. Processing, Minim)
Multimedia creation – Shapes
– Transformations – Graphics/Images – Text
– Interactions
Otheradvancedconcepts
– Code-Refactoring,andDesign
– Basicdatastructuresand algorithms
January 9, 2022
Syllabus – anatomy along techniques
Concept design
– Problem to be solved
– Data involved
– Functionalities to have – Constraints presented
Interactions
– Mouse interactions
– Keyboard interactions
– GUI interactions
– Image based interactions
– Object interactions: collision detection and avoidance
FSM for creation of AI behaviors and advanced interactions
– Use number to represent different states
– Use conditionals to manage flow control
Generating special shapes
– Perlin noise for procedural textures – Recursion for fractals
Sound effects with native and external libraries
– Java native sound library (limited functionality)
– Minim library (more powerful) 10
Software design
– How to represent data (classes,
their relations, variables, constants
– How to achieve functionalities (methods and execution flow)
– How to handle constraints
Software implementation
– Coding as per software design using certain programming languages
Motion and animation
– Timer based motions
– Micro-animations for characters and environment
January 9, 2022 IAT 265
Goals for the course
Gain programming knowledge and skills
– Analyzerequirements
– Solveproblemalgorithmically
– Implement(writecodetofulfilltherequirements)
Instructor, lectures, and quizzes/exams are primarily to help you gain the knowledge and how the knowledge can be applied in context
TAs, Tutorials and assignments are focused more on building up the skills based on the knowledge and context
Apparently they count on both to work interactively to allow you to gain the capability to solve any problem using software approach
January 9, 2022 IAT 265 11
Lecture participation: 5% (examining concept/technique understanding weekly)
Lab participation & challenges: 10% (skill building weekly)
Four Assignments: 40%
– Assignment Phase 1 (Concept design + PPP or Design + Coding) – Assignment Phase 2 (Implementation – coding)
– Assignment Assessment (examining concept understanding)
Three Quizzes: 15% (examining concept understanding periodically)
Final Exam: 30% (examining concept understanding holistically)
January 9, 2022 IAT 265 12
IAT Grading Scale
January 9, 2022 IAT 265 13
About Lecture Participation
Mainly done with mini-quizzes using Canvas
– Each of the mini-quizzes will examine the important concepts covered in the lecture/lab of previous week
– So make sure to review the previous lecture’s concepts before you come to the lecture!!
– Even if we may not have the mini-quizzes for each of the weeks, you should still do the review, as the major purpose for such quizzes is really to promote timely review
9 January 2022 IAT 265 14
Some Other Admin Issues
All class announcements will be done via our class email list: –
– Itisyourresponsibilitytochecktheemaildailyforanyannouncement
Lab switching:
– Possibleonlyifyoucanfindapartnertoswapwithyou.Youmust formally complete the lab switch in SIMS via SIAT advising
Grading Disputes
– For any assignment grading issue, please contact your TA (the grader) in writing for review within one week after the grades are released
– Appealtoinstructorinwritingonlywhentheissueisunableto resolve between you and your TA and provide appropriate reasons within two weeks after the grades are released
January 9, 2022 IAT 265 15
Requirements and Expectations
Attend all lectures and labs
– Slides and coding demos are put in Canvas before each class
– There are materials I talk about that are not in the slides. You are expected to know it for the quizzes/exams as well – take notes as part of your review references
Do all the ASSIGNMENTS!!
Do reviews on a WEEKLY basis
– Read slides and readings (provided via Canvas), and try to understand the basic concepts
– Attend instructor/TAs’ office hours for clarification Practice, Practice, Practice!
– Programming courses are always challenging and need practice
January 9, 2022 IAT 265 16
…on how to get a good grade
Do the readings and review slides after the lecture AND before the labs (desirably)
Run the demos yourself as you are reading through the slides. Try to do some modifications on your own
Be fully engaged in the lab
Do each of the lab challenges
If you are unclear on concepts at that point, re-read the sections, and if still missing the point attend the office hours
Read lectures slides/your notes/readings before the mini- quizzes/quizzes. Review tutorials and your own assignments for major concepts and techniques
January 9, 2022 IAT 265 17
NO Plagiarism
Absolutely NO plagiarism and cheating will be tolerated
– Don’tcopyfrominternetorpreviousworkofthecourse,asyou’llget
caught easily
– Don’tcopyothersanddon’tletotherscopyyou
– Theminimumpenaltyforallpartiesinvolvedwillbenegativeofthe assignment’s total marks (e.g. if the assignment is worth 20 pts, then -20pts would apply)!!
We keep the right to report to the School director and the Registrar for record keeping per SFU Policy S10.1, Appendix 3
January 9, 2022 IAT 265 18
Note: avoid potential plagiarism behavior in doing assignments
One type of Plagiarism behavior defined by SFU Code of Academic Integrity (linked in the Syllabus):
– “ii. copying all or part of an essay or other assignment from an author or other person, including a tutor or student mentor, and presenting the material as the student’s original work”
Based on this, our criteria for determining non-plagiarism when referencing lab tutorials/lecture demos is as follows:
– The framework of your assignments must be yours: including names of classes, fields, and method names, visuals etc.
– Youcandrawreferencesfromlabtutorialsandlecturedemosfor solving problems within your own framework
Cases that will be deemed as plagiarism for the followings:
– Usealabtutorial,lecturedemo,oranyother’swork(peer’s,previous student’s etc.) as a whole to be yours, and do minor modifications on top
– Thecodedirectlytakenfromanothersourceismorethan50%
Oct 19, 2017 19
Any questions?
January 9, 2022 IAT 265 20
What is Multimedia?
Applications that use multiple modalities … of text, images, drawings (graphics), animation, video, sound, and interactivity
– Z. Li & M. of Multimedia
Multimedia (Lat. Multum + Medium) is media that uses multiple forms of information content and information processing (e.g. text, audio, graphics, animation, video, interactivity) to inform or entertain the (user) audience
– From Wikipedia, the online encyclopedia
January 9, 2022 IAT 265 21
Typical Multimedia Applications
World Wide Web
Video Games
Virtual Reality (aka Immersive Multimedia) CGIs (in film making)
Video teleconferencing
Multimedia courseware
Scientific visualization
Simulations (of systems, processes etc.) …
January 9, 2022 IAT 265 22
Some Multimedia Apps
Created by students of the class … – Watch the demos
January 9, 2022 IAT 265 23
Introduction to Java
A fully object-oriented language Types of Java program
Java language and Eclipse IDE Basics of Java Syntax
File structure of Java apps
Java system library and APIs
January 9, 2022 IAT 265 24
Java is Fully Object-Oriented
We live in a world full of objects
– Images, cars, remote controls, televisions, employees,
students, …
The older languages are procedural
OOP languages have the added capability to encapsulate objects’ properties and functions into one container – object
– A template for creating objects is called Class
January 9, 2022 IAT 265 25
Object Oriented vs. Procedural Languages
Procedural (e.g. C)
– We create some data representing an image
– We write a procedure (i.e. function) that can accept the data and draw the image
Object Oriented (e.g. Java)
– We create an object that contains image data AND a function to draw it
– The data and the function (ability to draw) are in ONE “container” – the object
January 9, 2022
IAT 265 26
To generalize …
For procedural, functions have no intrinsic relationship with the data they operate on
Data accessed in this way is considered “global” or “shared” data
In OOP, the data and related functions are bundled together into an “object“
Ideally, the data inside an object can only be manipulated by calling the object’s functions
January 9, 2022
IAT 265 27
Two types of Java Programs
Java Application:
– Standalone program, runs on its own
Java Applet:
– small program, embedded inside web
applications (becoming obsolete)
January 9, 2022 IAT 265 28
Our First Java Application
HelloWorld.java
* Hello World
* The classic first program */
public class HelloWorld {
public static void main(String args[]) {
//print a message to the console System.out.println(“Hello, world!”);
Please note: for Java, the source file name must match the class name (case sensitive) for it to compile
January 9, 2022 IAT 265 29
We use Eclipse 2021-12 R
Where compile is done automatically whenever you save your file
You run your program by selecting ”Run as” on the menu or the button for running
Please note: you must have Java SDK installed before you can run Eclipse
– WeareusingJavaSDK8-make sure you DON’T install Java 9 or higher – your code might run into some compatible issue if run on machines with lower version!!
January 9, 2022 IAT 265 30 https://www.jetbrains.com/lp/devecosystem-2019/
Basics of Java Syntax
public class HelloWorld {
You must define a class in every Java program
public – keyword for access control that allows all other classes in your program to access
– private – can only be accessed within the class where the member (field or method) is defined
As a convention, class name starts with a Capital letter (vs. variable and method names – both start with a lowercase letter), and then goes CamelCase for each additional word
January 9, 2022 IAT 265 31
main method as the driver for Java Application
public static void main(String args[]) {
main method drives Java applications, which is the first place the JRE visits when running your application
static – keyword that specifies that the member belongs to the class instead of a specific instance
January 9, 2022 IAT 265 32
Including Comments
Two basic types of comments in Java – in-line and block comments
in-line comments: make a note about a particular line of code, e.g.
//printing a message to the console System.out.println(“Hello, World!”);
block comments: normally used to explain a class or /* method on top
* Hello World
* The classic first program
January 9, 2022 IAT 265 33
Call Java API Methods
System.out.println(“Hello, world!”);
System class has a static field: out – an object of PrintStream, which has overloaded methods for printing
A call to a method that handles your system’s standard output (aka console)
– Refer to Java API documentation for more detail: https://docs.oracle.com/javase/8/docs/api/
January 9, 2022 IAT 265 34
Define your own Method
Methods are reusable commands
– Like a tool or device that does work for you
– Let you reuse code without typing it over and over
You can define your own methods by providing:
– method signature + { method body }
January 9, 2022 IAT 265 35
Review: Method Signature
– Just method name is not enough to do this, as method overloading is allowed in Java
Method signature: return_type + method name + parameters :
– void main(String args[])
– void println(String x)
– int max(int a, int b)
– double random()
Strictly speaking, method signature doesn’t include the return type. In this course though, we’d like to include the return type, so that we can learn what type of value we can expect by simply
looking at its signature
In computer programming, a method is identified by its
method signature
January 9, 2022 IAT 265 36
Define methods with parameters
public class HelloSomeone {
public static void main(String[] args) {
//accept someone’s first & last name as arguments
sayHello(“Eric”, “Yang”);
sayHello(“Jimmy”, “Shan”);
sayHello(“Jonus”, “Kraasch”);
public static void sayHello (String firstNm, String lastNm){
System.out.println(“Hello ” + firstNm + ” ” + lastNm + “!”);
January 9, 2022
IAT 265 37
Parameters vs Arguments
In Java, if a method is defined with parameters, you must pass an argument for each of the parameters when you call it
Parameters: place holders for values
sayHello (String firstNm, String lastNm) sayHello (“Eric”, “Yang”)
Arguments: actual values passed in January 9, 2022 IAT 265 38
File Structure
of Java Applications
All Java files are sitting in a package
– You can create named packages explicitly. Eg:
• package com.game.enemy;
– Otherwise a default package will be generated by Eclipse for
you to use (NOT a good practice, but we’ll start with it)
Each file can hold only one public class
In Java, the source file’s name must match exactly (case sensitive) the name of the public class it holds to compile properly
January 9, 2022 IAT 265 39
File Structure
of Java Applications (1)
If one class in a package wants to access another class in a different package, it must import that class first. Eg:
– import com.game.gameTokens.EnemyAmmo; – import java.awt.event.KeyEvent;
– import java.awt.Graphics2D;
– import java.swing.*;
The only exception to this rule is the java.lang package, you can access its classes anywhere in your program without importing
– Java makes it this way as it contains some very commonly used classes, such as: System, Math, String, Integer, Float, Exception, ….
January 9, 2022 IAT 265 40
Work with Java System Library
Library: Collection of classes that can be used as basic building blocks of programs
In Java, libraries are normally packed into .jar files and need to be included in the project build path for it to be used
Java System Library is mainly the collection of classes included in rt.jar file
– In Eclipse, Java System Library is added to the build path automatically when a project is created
January 9, 2022 IAT 265 41
Using Java API
Application Programming Interface (API) is a set of publicly accessible methods, variables, and constants of classes typically stored in a library
Java API documentation is the primary reference for working with Java
– https://docs.oracle.com/javase/8/docs/api/
Some commonly used packages in our context – java.lang – the only one NO need to import
– java.awt
– javax.swing
January 9, 2022 IAT 265 42
Intro to Java Graphics
Java provides several graphics facilities that reflect the evolution of the language
January 9, 2022 IAT 265 43
Methods of Graphics class
Two basic groups of Graphics’ methods:
– Draw and fill methods, enabling you to render
basic shapes, text, and images
– Attributes setting methods, which affect how the drawing and filling appears
• setColor(Color color), setFont(Font font) January 9, 2022 IAT 265 44
Drawing Space
• The top-left corner of a window (drawing space) is the default (0,0)
• The upper-left corner of a shape is its registration point – the
starting point to draw a shape (including ellipse)
January 9, 2022 IAT 265 45
What is the Registration Point when drawing an Oval or Arc?
It is the upper-left corner of the enclosing box, NOT that of the oval or arc
January 9, 2022 IAT 265 46
Drawing Primitive Shapes with Graphics’ methods
drawLine(int x1, int y1, int x2, int y2);
drawRect(int x, int y, int w, int h)
fillRect(int x, int y, int w, int h)
g.drawLine(40,40,320,260)
g.drawRect(40,40,320,260) g.fillRect(40,40,320,260)
drawOval(int x, int y, int w, int h)
fillOval(int x, int y, int w, int h)
January 9, 2022 IAT 265 47
g.drawOval(40,40,320,260) g.fillOvalt(40,40,320,260)
Drawing Primitive Shapes
drawPolygon(int xArray[], int yArray[], int numPoints)
fillPolygon(int xArray[], int yArray[], int numPoints)
E.g. to draw & fill a triangle:
int[] xArray = {100, 200, 300}; int[] yArray = {300, 100, 300 };
g.drawPolygon(xArray, yArray, 3); g.fillPolygon(xArray, yArray, 3);
E.g. to draw & fill a quad:
int[] xArray = {100, 120, 340, 300}; int[] yArray = {300, 100, 80, 320};
g.drawPolygon(xArray, yArray, 4); g.fillPolygon(xArray, yArray, 4);
g.drawPolygon(xArray,yArray,3) g.fillPolygon(xArray,yArray,3)
g.drawPolygon(xArray,yArray,4) g.fillPolygon(xArray,yArray,4)
January 9, 2022 IAT 265 48
Drawing arcs
drawArc(int x, int y, int w, int h, int startAngle, int arcAngle)
fillArc(int x, int y, int w, int h , int startAngle, int arcAngle) x, y – the top-left corner of the arc’s ellipse
w, h – width, height of arc’s ellipse
startAngle – angles to start the arc (in degree, positive for
counter-clockwise)
arcAngle – the angular extent of the arc, relative to the start angle
Example:
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com