David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.

Slides:



Advertisements
Similar presentations
Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.
Advertisements

Animation Mrs. C. Furman. Animation  We can animate our crab by switching the image between two pictures.  crab.png and crab2.png.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington UI methods, Graphical Output.
1 Java Basics. 2 Compiling A “compiler” is a program that translates from one language to another Typically from easy-to-read to fast-to-run e.g. from.
Structure of a C program
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Objects Interaction and Source Code Week 2. OBJECT ORIENTATION BASICS REVIEW.
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Objects Real and Java COMP.
Programming in Java; Instructor:Moorthy Introduction, Objects, Classes, Libraries1 Programming in Java Introduction.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Program Elements and Syntax.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
© Xiaoying Gao, Peter Andreae Class, method, statements COMP 102 #3 2014T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
©Xiaoying Gao, Peter Andreae First Java Program COMP 102 #2 2014T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
1 CSC 201: Computer Programming I B. S. Afolabi. Introduction  3 unit course  2 hours of lecture/week Thursdays 4.00pm – 6.00pm Mondays 4.00pm – 6.00pm.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
First Java Program COMP 102 #2 2015T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Arrays and ArrayLists.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Classes CS 21a: Introduction to Computing I First Semester,
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
David Streader & Peter Andreae Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Objects.
Applications Development
Mixing integer and floating point numbers in an arithmetic operation.
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.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Types and Interfaces COMP.
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.
Object Oriented Software Development 4. C# data types, objects and references.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Types and Interfaces COMP.
Xiaoying Gao Computer Science Victoria University of Wellington Copyright: Xiaoying Gao, Peter Andreae, Victoria University of Wellington UI methods, Graphical.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
© Xiaoying Gao, Peter Andreae Variables, Constants, UI methods COMP 102 #4 2014T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington UI methods, Graphical Output.
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
CSH Intro. to Java. The Big Ideas in Computer Science Beyond programming Solving tough problems Creating extensible solutions Teams of “Computational.
© Peter Andreae Java Programs COMP 102 # T1 Peter Andreae Computer Science Victoria University of Wellington.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Program Elements and Syntax.
Objects Real and Java COMP T1 3
Yanal Alahmad Java Workshop Yanal Alahmad
Java Primer 1: Types, Classes and Operators
Objectives Identify the built-in data types in C++
Trainings 11/4 Intro to Java.
Building Java Programs Chapter 2
Functions I Creating a programming with small logical units of code.
Sridhar Narayan Java Basics Sridhar Narayan
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Recap Week 2 and 3.
Object Oriented Programming in java
Classes CS 21a: Introduction to Computing I
C++ Programming Basics
Functions I Creating a programming with small logical units of code.
Presentation transcript:

David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP T1 #2

COMP 112 2: 2 BlueJ - an IDE for Java Java is Object Oriented and has extensive Libraries. BlueJ is an Integrated Development Environment BlueJ allows Objects to be built form a Class file Methods of an object to be executed Libraries to be easily integrated

COMP 112 2: 3 Objects Objects are a collection of: Private data (fields) Public methods Decomposing a problem into useful classes and objects is sometimes straightforward. Example a student record system might have: 1.A Student class and a Student object for each student. 2.A Course class and a Course object for each course 3.A course method could be Enroll that takes a student and enrolls them on the course.

COMP 112 2: 4 BlueJ an IDE Classes Right click (on class) New AddCounter (to make an object)

COMP 112 2: 5 BlueJ an IDE

COMP 112 2: 6 BlueJ an IDE Object Right click (to call methods)

COMP 112 2: 7 Values are Typed in Java There are lots of different kinds of values: Numbers Integers( int or long) real numbers ( double or float ) e-34 … Characters ( char )'X' '4' Text ( String ) " F -> " Colours ( Color )Color.red Color.green Integer (same as int but an object) …

COMP 112 2: 8 Java is Object Oriented Typed 1.Primitive a.int b.Boolean, … 2.Reference a.String b.ArrayList, … Compiled and runs on a Virtual machine Has garbage collection

COMP 112 2: 9 Primitives and Objects Car21 Car z = new Car(2); Ov 2 z Car21 int x = 1; x 1 x names a piec e of memory in which the value 1 is stored The value in z is the reference to the Object.

COMP 112 2: 10 Objects in Java Class defines Objects Used to structure code Objects contain: Fields (hold data) Methods (can be executed) Constructor methods Have same name as Class Have no return type Used to construct Object of the Class Best understood by an example.

COMP 112 2: 11 Simple Java Class Private FieldClass Name Class Declaration Public Method

COMP 112 2: 12 Java Method Variable Declaration Variable assignment Parameter TypeMethod nameReturn Type

COMP 112 2: 13 Java Program Library Constructor Main method

COMP 112 2: 14 Main - called from terminal

COMP 112 2: 15 Structure of the program Import statements Comment Class definition (defining the objects) Class header Method definitions (defining Actions the objects can do) Method header Instructions for performing the action

COMP 112 2: 16 Syntax rules: Program structure First version 〈import statements 〉 public class 〈 method descriptions 〉 { } 〈 classname 〉 Comments can be added anywhere Import ecs100; import java.awt.Color;

COMP 112 2: 17 Comments Three kinds of comments: Documentation comments eg /** Program for converting between temperature scales */ end-of-line comments eg double fahren = celsius * 9 / ; // compute answer anywhere comments eg /* double fahren = celsius * 9 / ; UI.println(celcius + “C is " + fahren + " F"); */ /** 〈 text of comment 〉 */ // 〈 text of comment 〉 Top of class, Before each method at end of any line /* 〈 text of comment 〉 */ multi-line, or middle of line, or …

COMP 112 2: 18 Method Definitions /** Print out the conversion formulas */ public void printFormula ( ) { UI.println("Celsius = (Fahrenheit - 32) *5/9"); } 〈 Doc Comment 〉〈 Header 〉〈 Body 〉 {} public void () 〈 name 〉 〈 parameters 〉 instructions to perform this action Specifying the information the action needs. May be empty

COMP 112 2: 19 Java Java is very portable Java byte code runs on a Java virtual machine 1.Name.java is source code 2.To compile into byte code > javac -classpath./ecs100.jar Name.java 3.Name.class is the byte code 4.To execute you run the JVM with the byte code >java -classpath ".:ecs100.jar" Name 5.To build executable build a.jar file