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

Slides:



Advertisements
Similar presentations
Introduction to Programming G51PRG University of Nottingham Revision 1
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.
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.
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.
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.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
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.)
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
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Classes CS 21a: Introduction to Computing I First Semester,
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Xiaoying Gao Computer Science Victoria University of Wellington Copyright: Xiaoying Gao, Peter Andreae, Victoria University of Wellington Methods with.
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.
Java methods Methods break down large problems into smaller ones Your program may call the same method many times saves writing and maintaining same code.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
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.
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.
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington UI methods, Graphical Output.
1 Class and Object Lecture 7. 2 Classes Classes are constructs that define objects of the same type. A Java class uses instance variables to define data.
CSC 142 F 1 CSC 142 References and Primitives. CSC 142 F 2 Review: references and primitives  Reference: the name of an object. The type of the object.
© 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.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Introduction to java (class and object). Programming languages: –Easier to understand than CPU instructions –Needs to be translated for the CPU to understand.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Program Elements and Syntax.
Information and Computer Sciences University of Hawaii, Manoa
Objects Real and Java COMP T1 3
Yanal Alahmad Java Workshop Yanal Alahmad
Java Primer 1: Types, Classes and Operators
Java Intro.
Sridhar Narayan Java Basics Sridhar Narayan
Building Java Programs
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Recap Week 2 and 3.
Java Programming Review 1
Object Oriented Programming in java
Classes CS 21a: Introduction to Computing I
C++ Programming Basics
Presentation transcript:

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

COMP 112 3: 2 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 3: 3 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 3: 4 Simple Java Class Private FieldClass Name Class Declaration Public Method

COMP 112 3: 5 Java Method Variable Declaration Variable assignment Parameter TypeMethod nameReturn Type

COMP 112 3: 6 Java Program Library Constructor Main method

COMP 112 3: 7 Main - called from terminal Constructor Method Call on c1 New Object

COMP 112 3: 8 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 3: 9 Syntax rules: Program structure First version 〈 import statements 〉 publicclass 〈 method descriptions 〉 { } 〈 classname 〉 Comments can be added anywhere Import ecs100; import java.awt.Color;

COMP 112 3: 10 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 3: 11 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 3: 12 Variables can be Primitives or 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 3: 13 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