Game Programming in Java Dr. Jeyakesavan Veerasamy CS faculty, The University of Texas at Dallas Website:

Slides:



Advertisements
Similar presentations
C++ Language Fundamentals. 2 Contents 1. Introduction to C++ 2. Basic syntax rules 3. Declaring and using variables.
Advertisements

Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Exception Handling The purpose of exception handling is to permit the program to catch and handle errors rather than letting the error occur and suffer.
Advanced Java Concepts Dr. Jeyakesavan Veerasamy
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
Rossella Lau Lecture 8, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 8: Polymorphism & C++ pointer  Inheritance.
Session 1 CS-240 Data Structures Binghamton University Dick Steflik.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Java Review 2 – Errors, Exceptions, Debugging Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles C/C++ Emery Berger and Mark Corner University of Massachusetts.
C++ vs. Java: Similiarities & Differences Dr. Jeyakesavan Veerasamy Director of CS UTDesign program & CS Teaching Faculty University.
Guide To UNIX Using Linux Third Edition
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
Gentle Introduction to Programming in Java Dr. Jey Veerasamy 1.
C++ fundamentals.
Peter Juszczyk CS 492/493 - ISGS. // Is this C# or Java? class TestApp { static void Main() { int counter = 0; counter++; } } The answer is C# - In C#
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
Programming in Java; Instructor:Moorthy Introduction, Objects, Classes, Libraries1 Programming in Java Introduction.
OOP Languages: Java vs C++
Programming Languages and Paradigms Object-Oriented Programming.
Classes Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd Spetember 2006.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Java and C++, The Difference An introduction Unit - 00.
Recap, Test 1 prep, Composition and Inheritance. Dates Test 1 – 12 th of March Assignment 1 – 20 th of March.
Intro to C++ And Some Tools Opening Discussion zHave any questions come up since last class? Have you had a chance to look over the project.
 200 Total Points ◦ 74 Points Writing Programs ◦ 60 Points Tracing Algorithms and determining results ◦ 36 Points Short Answer ◦ 30 Points Multiple Choice.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
CS212: Object Oriented Analysis and Design Lecture 7: Arrays, Pointers and Dynamic Memory Allocation.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Week 14 - Monday.  What did we talk about last time?  Introduction to C++  Input and output  Functions  Overloadable  Default parameters  Pass.
Pointers OVERVIEW.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Constructors CMSC 202. Object Creation Objects are created by using the operator new in statements such as… The following expression invokes a special.
CPSC 252 Dynamic Memory Allocation Page 1 Dynamic memory allocation Our first IntVector class has some serious limitations the capacity is fixed at MAX_SIZE.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
CPSC 252 The Big Three Page 1 The “Big Three” Every class that has data members pointing to dynamically allocated memory must implement these three methods:
C/C++ Basics. Basic Concepts Basic functions of each language: Input, output, math, decision, repetition Types of errors: Syntax errors, logic errors,
Introduction to C Programming Lecture 6. Functions – Call by value – Call by reference Arrays Today's Lecture Includes.
OOP in C++ CS 124. Program Structure C++ Program: collection of files Source (.cpp) files be compiled separately to be linked into an executable Files.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
Computer Graphics 3 Lecture 1: Introduction to C/C++ Programming Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
CMSC 202 Advanced Section Classes and Objects: Object Creation and Constructors.
Classes, Arrays & Pointers. Compiler & Linker expectations file1.cppfile2.cppfilen.cpp …. file1.ofile2.ofilen.o …. Linker application (executable) Compiler.
Chapter 1 C++ Basics Review (Section 1.4). Classes Defines the organization of a data user-defined type. Members can be  Data  Functions/Methods Information.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Software Engineering Algorithms, Compilers, & Lifecycle.
Memory Management in Java Mr. Gerb Computer Science 4.
CSC Pointers Powerful feature of the C++ language One of the most difficult to master Essential for construction of interesting data structures.
Programming Competitions. USA Computing Olympiad ace.delos.com/usacogate You need to create an account (use KITE address) to gain access. Solution.
Lecture 3 Translation.
Object Lifetime and Pointers
Pointer to an Object Can define a pointer to an object:
BRIEF Overview ON THE MAJOR Similarities & Differences
Default Constructors A default constructor is a constructor that takes no arguments. If you write a class with no constructor at all, C++ will write a.
“Alice  Java” workshop
Java Review: Reference Types
CS 2308 Final Exam Review.
Introduction to Classes
C/C++ Basics.
BRIEF Overview ON THE MAJOR Similarities & Differences
From C++ to Java Java history: Oak, toaster-ovens, internet language, panacea What it is O-O language, not a hybrid (cf. C++) compiled to byte-code, executed.
CMSC 202 Constructors Version 9/10.
Introduction to Classes and Objects
Presentation transcript:

Game Programming in Java Dr. Jeyakesavan Veerasamy CS faculty, The University of Texas at Dallas Website:

Goals Understand C++ vs. Java concepts Strengthen recursive coding skills See algorithm efficiency in action Strengthen logical thinking skills Strengthen coding skills in Java Event driven programming This is NOT a “serious” game programming workshop!

C++ vs. Java: Similarities Both support OOP. Most OOP library contents are similar, however Java continues to grow faster. Syntax is very close – Java has strong influence of C/C++. Easy to learn the other language when you know one of these.

C++ Compiler & Linker expectations file1.cppfile2.cppfilen.cpp …. file1.ofile2.ofilen.o …. Linker application (executable) Compiler C++ compiler does not care about filenames.

Java? … file1.java file2.java file3.javafilen.java

C++ Concepts: Operator overloading Operator overloading: ComplexNumber x, y, z; z = x + y; In Java?

C++ Concepts: Method overloading Method overloading – similar to Java – use different argument types to differentiate

C++ Concept: Friend friend designation - breaks OOP philosophy! – specific functions/methods outside the class can access private data  Why?

Concepts: Objects Objects can be created as local variables just like any basic data types. ComplexNumber num1;

Arrays Basic data types and classes are treated the same way in C++, unlike Java. ComplexNumber numbers[5];

C++ Array version #2 ComplexNumber *numbers; numbers = new ComplexNumber[5];

C++ Array version #3 ComplexNumber **numbers; numbers = new ComplexNumber*[5]; for( index i = 0 ; i < 5 ; i++) numbers[i] = new ComplexNumber(…);

Java ComplexNumber numbers[]; numbers = new ComplexNumber[5]; for( index i = 0 ; i < 5 ; i++) numbers[i] = new ComplexNumber(…);

C++ Pointers vs Java References Explicit in C++: ComplexType *cnump; Pointer arithmetic Dynamic memory allocation requires pointers (just like references in Java)

Dynamic memory allocation No automatic garbage collection in C++ # of new invocations should match # of delete invocations. If a class constructor allocates memory (i.e. uses “new …”), it needs a destructor method too – it should use “delete …” to release allocated memory.

C++ vs. Java: differences C++Java Write once, compile everywhere  unique executable for each target Write once, run anywhere  same class files will run above all target-specific JREs. No strict relationship between class names and filenames. Typically, a header file and implementation file are used for each class. Strict relationship is enforced, e.g. source code for class PayRoll has to be in PayRoll.java I/O statements use cin and cout, e.g. cin >> x; cout << y; I/O input mechanism is bit more complex, since default mechanism reads one byte at a time (System.in). Output is easy, e.g. System.out.println(x); Pointers, References, and pass by value are supported. No array bound checking. Primitive data types always passed by value. Objects are passed by reference. Array bounds are always checked. Explicit memory management. Supports destructors. Automatic Garbage Collection. Supports operator overloading.Specifically operator overloading was left out.

Example: Guessing game Think of a number between 1 and 100 in your mind. Then, the computer (program) will ask you a series of questions and determine that number based on your answers. Series of interactions: Program: Is it NN? Your response:

Sample run #1 Guess a number between 1 and 100 (both inclusive) and get ready to answer a few questions. How about 50 ( )? < How about 25 ( )? < How about 12 ( )? > How about 18 ( )? > How about 21 ( )? < How about 19 ( )? > Your guess is 20.

Sample run #2 Guess a number between 1 and 100 (both inclusive) and get ready to answer a few questions. How about 50 ( )? > How about 75 ( )? < How about 62 ( )? > How about 68 ( )? > How about 71 ( )? = Your guess is 71.

Example: Lotto game Generate 6 unique numbers from 1 to 50. Output should NOT have repeating numbers. Random ran = new Random(); int x = ran.nextInt(50); //returns 0 to 49

Example: Hangman game

Programming Competitions: usaco.org Create a new account in usaco.org Use graduation year 9999, country code IND Then go to your to find the password. Login first, then go to look into Bronze level problems

USA Computing Olympiad training site ace.delos.com/usacogate You need to create an account (use KITE address) to gain access. 100s or 1000s of programming problems! A few solution files

Example: Knapsack problem int weights[] = { 5, 9, 23, 12, 45, 10, 4, 19, 53 }; int target = 100; Goal is to find 2 distinct weights, when added, come to close to target, but do NOT exceed it. For this problem, answer is 45 and 53. Now, let us write generic algorithm so that we can find it for any user-specified target value.

Memory game GUI setup code Image files