Packages. 1. Every Java object resides in a package. 2. An object s package is explicitly declared on the first line of code in a.
|
|
- Pamela Norris
- 5 years ago
- Views:
Transcription
1 Packages
2 Packages 1. Every Java object resides in a package. 2. An object s package is explicitly declared on the first line of code in a.java file: package edu.pcwe.uw.javaintro.misc; public class HelloWorld public static void main( String[] args ) System.out.println( "Hello world!" );
3 Packages 3. The fully qualified nameof a class includes its package name; the fully qualified name of the class in the preceding slide is: edu.pcwe.uw.javaintro.misc.helloworld
4 Packages 3. Packages allow different programming organizations to choose the same class name without fear of confusion: java.awt.list java.util.list
5 Packages 4. A.java file without a package statement is said to reside in the default package. Note: We will not be using explicit packages for the code we write in this class. However you have to know a little bit about packages in order to use pre assembled code.
6 Libraries 1. A library is a collection of packages. 2. A library may reside in a dedicated directory 3. but is more commonly stored in a java archive (.jar) file.
7 Libraries 4. To use an object from a library, you must: a) Import the object from its package into your code: import edu.uweo.javaintro.tools.turtle; b) Tell java where the library lives that contains the package:
8 Objects
9 Definition 1. An object stores information and performs actions. 2. An object has a nameand a type. 3. The name of an object must be unique, and allows you to have many objects of the same type. 4. The type of an object determines what it can store and what it can do. A java Integerobject stores whole numbers; it can perform basic arithmetic, such as adding and subtracting. A Cartographobject might store the coordinates of cities, and be able to compute the distance between them.
10 Declaration 1. A declaration determines the name and type of an object: Person cartman; ^ ^ ^ type name end-declaration 2. Objects need to be created before you can use them: cartman = new Person(); 3. An object can be declared and created in one step: Person cartman = new Person();
11 Methods 1. A method(a.k.a. functionor procedure) is how you usually interact with an object. 2. A method has a nameand a type. 3. A method requires 0 or more argumentsenclosed in parentheses. 4. A method is invokedusing the executor(a period). Person cartmen = new Person(); cartman.takeahike( 3, 2 ); ^ ^ executor ^ arguments name
12 Turtle Objects
13 Introduction See also: Turtle Documentation on the class web site. 1. To work with the Turtle class you must import it from edu.uweo.javaintro.tools. 2. A Turtle is an object that can draw simple figures. 3. A Turtle starts at the center of a blank screen facing east. import edu.uweo.javaintro.tools.turtle; -orimport edu.uweo.javaintro.tools.*;
14 A Turtle s Habitat
15 The paint Method The paintmethod draws a line and changes the position of a Turtle. It takes two arguments: angle and distance. paint( angle, distance ) angle: Causes a turtle to turn a number of degrees; positive numbers turn left; negative numbers turn right. distance: Tells a turtle how many pixels to walk; positive numbers walk forward; negative numbers walk backward.
16 Painting (1)
17 Painting (2)
18 Painting (3)
19 Moving
20 The move Method The move method changes the position of a Turtle without drawing. It takes two arguments: angle and distance. move( angle, distance ) angle: Causes a turtle to turn a number of degrees; positive numbers turn left; negative numbers turn right. distance: Tells a turtle how many pixels to walk; positive numbers walk forward; negative numbers walk backward.
21 The swingaroundmethod The swingaroundmethod tells a turtle to draw a circle; it does not change the position of the turtle. It takes one argument: the radius of the circle. swingaround( radius ) radius: Specifies the radius of the circle.
22 Swinging Around
23 Comments (1) Adding comments to your code can make it more readable; the java compiler ignores comments. The double slash (//) begins a comment that continues to the end of the line: Turtle sue = new Turtle(); sue.paint( 45, 200 ); // start by drawing a diagonal line sue.move( -135, 300 ); // make sue face due south
24 Comments (2) Another kind of comment begins with slash-asterisk (/*) and ends with asterisk-slash (*/): /* This program renders a surrealistic sketch of a monkey eating a banana. Author: Jordan Alispiegal Date: 23-June-2008 */ public class Monkey...
25 Exercises Textbook, Chapter 1, page 1-5: Use an editor (notepad++) to enter the program TwoSquaresfrom listing 1.2. Use javacto compile the program, and javato run it. Textbook, Chapter 1, page 1-7: Exercises 1.3, 1.5 and 1.7 (note: the house in exercise 1.7 should have a flat roof).
26 Parts of a Java Program
27 class+ name matching braces public class HelloWorld /* body of class goes here */ must live in HelloWorld.java A classcreates a new type, something which can contain data and define actions. In java, nothing can happen outside a class. Every class has a name, such as Turtle. class HelloWorld creates a new class named HelloWorld.
28 public + class public class HelloWorld /* body of class goes here */ Declaring a class to be publicmeans that it can be used by anyone. There are other options, such as private,but we won't be talking about those for a while.
29 Braces public class HelloWorld public static void main( String[] args ) System.out.println( "Hello World!" ); In java, braces are used to group things together. In the context of a class the left brace () signals the start of the class, and the right brace () signals the end of the class. Braces are always used in pairs.
30 main public class HelloWorld public static void main( String[] args ) System.out.println( "Hello World!" ); When you start a java program with the javatool, you must designate the class to start executing. This class must have a block of code (called a method) named main, which must be written exactly as shown: public static void main( String[] args )
31 void public class HelloWorld // main does not calculate a value. public static void main( String[] args ) System.out.println( "Hello World!" ); In Java, some methods can be used to calculate values, for example, Math.abs is used to calculate the absolute value of a number: System.out.println( Math.abs( -3 ) ); When a method does notcalculate a value, it must be declared void.
32 public method-name public class HelloWorld public static void main( String[] args ) System.out.println( "Hello World!" ); In Java, some methods can be used by anyone, while access to other methods is restricted. A method declared publiccan be used by anyone. There are other options, such as privatewhich we ll talk about later.
33 static method-name public class HelloWorld public static void main( String[] args ) System.out.println( "Hello World!" ); In Java, some methods can be used anytime, but others can only be used after you create an object (you can t tell a Turtle to draw anything until you create one). staticmethods, on the other hand, can be used whether you have an object or not.
34 String[] args public class HelloWorld public static void main( String[] args ) System.out.println( "Hello World!" ); String[] argsis used to process command line arguments. Don t worry about that right now; just remember that your main method must be declared this way.
35 Spacing public class HelloWorldpublic static void main(string[]args) Hello World ); Spaces and line breaks are (usually) optional in Java code. We use them to make our code more readable.
36 Indentation public class HelloWorld public static void main( String[] args ) System.out.println( "Hello World!" ); Indentation is optional in Java code, but it makes your programs much easier to read. Put the braces that delimit a block of code on lines by themselves, and line them up with the start of the block. Inside the block indent four spaces.
37 Exercises (1 of 2) 1. Go into your HelloWorldprogram and change mainto sam.compile it with the javaccommand. What happens when you try to run it with the java command? (Before you forget, change samback to main.) 2. Add the getgreetingmethod to your HelloWorldprogram, and change the "HelloWorld"line as follows: public class HelloWorld public static void main( String[] args ) System.out.println( getgreeting() ); public static String getgreeting() return "Hi there, world"; (continued on next slide)
38 Exercises (2 of 2) (continued) Compile and run the program. Explain: What happened when you substituted getgreeting() for "HelloWorld"? What is the purpose of Stringin the line public static String getgreeting()? 3. Download and complete TweedleActivity from the class web site.
39 Introduction to Inheritance (1) You can create a new class that inheritsdata and behavior from an existing class by using the extends expression: import edu.uweo.javaintro.tools.turtle; public class Bob extends Turtle public void whoareyou() System.out.println( "I am Bob, the Turtle." ); System.out.println( "Don't mess with me." );
40 Introduction to Inheritance (2) In the above example, an object of type Bobcan do anything a Turtle can. In fact, it is a Turtle, plus a little more: public class Test public static void main( String[] args ) Bob fred = new Bob(); fred.paint( 0, 128 ); fred.whoareyou();
41 The SmartTurtleClass The SmartTurtle class extends Turtle by adding two new methods. public class SmartTurtle extends Turtle public void makesmallsquare() paint( 90, 10 ); paint( 90, 10 ); paint( 90, 10 ); paint( 90, 10 ); public void makebigsquare() paint( 90, 40 ); paint( 90, 40 ); paint( 90, 40 ); paint( 90, 40 ); Questions: 1. Why are the new methods public? 2. Why are they not static? 3. Why do we use the command paintand not something.paint?
42 Instance Methods (1) 1. An instance method can only be executed on a specific object. 2. An instance method is declared without the word static. 3. Inside the method, a command like paintrefers to the object the method was executed on this is called the default executor.
43 Instance Methods (2) When we write smarty.makebigsquare()the paint command in makebigsquareis executed by smarty; when we write iggy.makesmallsquare() the paint command is executed by iggy. public class Test public static void main(string[] args) SmartTurtle smarty = new SmartTurtle(); SmartTurtle iggy = new SmartTurtle(); smarty.move( 0, -100 ); smarty.makebigsquare(); iggy.move( 0, 100 ); iggy.makesmallsquare();
44 The Default Executor In an instance method, the default executor can be explicitly invoked using this. public void makesmallsquare() paint( 90, 10 ); paint( 90, 10 ); paint( 90, 10 ); paint( 90, 10 ); // is equivalent to public void makesmallsquare() this.paint( 90, 10 ); this.paint( 90, 10 ); this.paint( 90, 10 ); this.paint( 90, 10 );
45 Definitions Instance An object that belongs to some class is an instanceof that class. An object can be an instance of more than one class; a SmartTurtleobject is an instance of both the Turtle and SmartTurtleclasses. Subclass When class A inherits from class B, class A is said to be a subclassof class B. Superclass When class A inherits from class B, class B is said to be a superclassof class A. public class A extends B
46 Exercises Textbook, Chapter 1, page 1-8: Create the file SmartTurtle.java, and enter the code from Listing 1.3. Compile the code. Textbook, Chapter 1, page 1-11: Exercises 1.8, 1.10, 1.11, 1.14
47 Turtles: the switchtomethod The switchtomethod takes one argument, a color defined in the Turtle class. switchto( color ) color: a color from the Turtle class. Example: Turtle fred = new Turtle(); fred.switchto( Turtle.RED );
48 Turtles: Constants Data stored in a class can include constant values (they're called constants because they can't be changed). The Turtle class has several constants used to represent colors: Turtle.BLACK Turtle.GRAY Turtle.BLUE Turtle.GREEN Turtle.RED Turtle.YELLOW Turtle.ORANGE Turtle.PINK Turtle.MAGENTA Turtle.WHITE
49 Turtles: the fillcirclemethod The fillcirclemethod takes one argument, a number that designates the radius of a solid circle to draw. fillcircle( radius ) radius: the radius of a circle. Example: Turtle fred = new Turtle(); fred.switchto( Turtle.RED ); fred.fillcircle( 64 );
50 Turtles: the fillboxmethod The fillboxmethod takes two arguments, numbers that designates the width and height of a solid rectangle to draw. fillbox( width, height ) width: the width of a rectangle height: the height of a rectangle Example: Turtle fred = new Turtle(); fred.switchto( Turtle.RED ); fred.fillbox( 128, 32 );
51 Turtles: the say Method The say method takes one argument, a string to draw at the Turtle s current position. say( string ) string: string to draw Example: Turtle fred = new Turtle(); fred.paint( 0, 200 ); fred.say( "making a right turn" ); fred.paint( -90, 200 );
52 Methods Without Objects 1. Methods that can be executed without an object are declared static: public static void sleep( int milliseconds ) 2. To execute a method that doesn t need an object, use the class name: Turtle.sleep( 500 )
53 Turtles: the Sleep Method The sleepmethod takes one argument, the number of millisecondsfor a Turtle to pause between commands. static void sleep( millis ) str: the number of milliseconds to sleep. Example: Turtle fred = new Turtle(); fred.paint( 90, 128 ); Turtle.sleep( 2000 ); //pause for two seconds fred.paint( 90, 64 );
54 Keywords A keywordis a part of the java programming language. Some examples of keywords that you have already seen are: public class static void extends new There are many others, including if, else, for, while and interface.
55 Identifers An identifieris a name that you give to a programming component that you create, including class names (Turtle) method names (makesmallsquare) and objects (Turtle fred = new Turtle()). Rules for creating identifiers are: You may notuse a keyword. The identifier must begin with a letter or underscore. After the first character, you may use letters, numbers and underscores. Capitalization counts; Fred is different from fred. Java conventions that you should follow: Class names should begin with an upper case letter. Non-constant object and method names should begin with a lower case letter. Constant names should not include lower case letters. Identifiers should not begin with an underscore.
56 Exercises Which of the following are keywords that you have encountered in class? public class fred wilma Turtle void paint static Which of the following are valid identifiers? fred _wilma ted_90 9_ted static void 9_5 a 9% Writea program thattells a Turtleto draw a line 100 pixels long, then say 100 ; extend the line by another 100 pixels and say 200. Textbook, Chapter 1, page 1-16: Exercises 1.18, 1.21 OPTIONAL: Textbook, Chapter 1, page 1-30: Write, compile and run the program in Listing 1.11.
Java Foundations: Unit 3. Parts of a Java Program
Java Foundations: Unit 3 Parts of a Java Program class + name public class HelloWorld public static void main( String[] args ) System.out.println( Hello world! ); A class creates a new type, something
More informationGet JAVA. I will just tell you what I did (on January 10, 2017). I went to:
Get JAVA To compile programs you need the JDK (Java Development Kit). To RUN programs you need the JRE (Java Runtime Environment). This download will get BOTH of them, so that you will be able to both
More informationSoftware and Programming 1
Software and Programming 1 Lab 1: Introduction, HelloWorld Program and use of the Debugger 17 January 2019 SP1-Lab1-2018-19.pptx Tobi Brodie (tobi@dcs.bbk.ac.uk) 1 Module Information Lectures: Afternoon
More informationJava Programming Fundamentals - Day Instructor: Jason Yoon Website:
Java Programming Fundamentals - Day 1 07.09.2016 Instructor: Jason Yoon Website: http://mryoon.weebly.com Quick Advice Before We Get Started Java is not the same as javascript! Don t get them confused
More informationCMSC 150 LECTURE 1 INTRODUCTION TO COURSE COMPUTER SCIENCE HELLO WORLD
CMSC 150 INTRODUCTION TO COMPUTING ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH INTRODUCTION TO JAVA PROGRAMMING, LIANG (PEARSON 2014) LECTURE 1 INTRODUCTION TO COURSE COMPUTER SCIENCE
More informationA PROGRAM IS A SEQUENCE of instructions that a computer can execute to
A PROGRAM IS A SEQUENCE of instructions that a computer can execute to perform some task. A simple enough idea, but for the computer to make any use of the instructions, they must be written in a form
More informationThe Vic Class. a1 b e g end. a d2 end. a3 b e g3 h3 end. a d4 e4 end. GarthB LyleL stack
Conditionals The Vic Class a1 b1 ---- ---- e1 ---- g1 ---- end a2 ---- ---- d2 end a3 b3 ---- ---- e3 ---- g3 h3 end GarthB LyleL stack a4 ---- ---- d4 e4 end The Vic Class 1. The Vic class simulates a
More informationCONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction
CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics COMP-202 Unit 1: Introduction Announcements Did you miss the first lecture? Come talk to me after class. If you want
More informationCS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG
CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG 1 Notice Reading Assignment Chapter 1: Introduction to Java Programming Homework 1 It is due this coming Sunday
More informationCS 177 Recitation. Week 1 Intro to Java
CS 177 Recitation Week 1 Intro to Java Questions? Computers Computers can do really complex stuff. How? By manipulating data according to lists of instructions. Fundamentally, this is all that a computer
More informationComputer Components. Software{ User Programs. Operating System. Hardware
Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point
More informationIntroduction to Java Unit 1. Using BlueJ to Write Programs
Introduction to Java Unit 1. Using BlueJ to Write Programs 1. Open up BlueJ. Click on the Project menu and select New Project. You should see the window on the right. Navigate to wherever you plan to save
More information5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.
Today! Build HelloWorld yourself in BlueJ and Eclipse. Look at all the Java keywords. Primitive Types. HelloWorld in BlueJ 1. Find BlueJ in the start menu, but start the Select VM program instead (you
More informationSoftware and Programming 1
Software and Programming 1 Lab 1: Introduction, HelloWorld Program and use of the Debugger 11 January 2018 SP1-Lab1-2017-18.pptx Tobi Brodie (tobi@dcs.bbk.ac.uk) 1 Module Information Lectures: Afternoon
More informationCS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style
CS125 : Introduction to Computer Science Lecture Notes #4 Type Checking, Input/Output, and Programming Style c 2005, 2004, 2002, 2001, 2000 Jason Zych 1 Lecture 4 : Type Checking, Input/Output, and Programming
More informationBIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic
BIT 3383 Java Programming Sem 1 Session 2011/12 Chapter 2 JAVA basic Objective: After this lesson, you should be able to: declare, initialize and use variables according to Java programming language guidelines
More informationIntroduction to Java Applications
2 Introduction to Java Applications OBJECTIVES In this chapter you will learn: To write simple Java applications. To use input and output statements. Java s primitive types. Basic memory concepts. To use
More informationAP Computer Science Unit 1. Writing Programs Using BlueJ
AP Computer Science Unit 1. Writing Programs Using BlueJ 1. Open up BlueJ. Click on the Project menu and select New Project. You should see the window on the right. Navigate to wherever you plan to save
More informationCS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG
CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG 1 Notice Class Website http://www.cs.umb.edu/~jane/cs114/ Reading Assignment Chapter 1: Introduction to Java Programming
More informationBASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I
BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment
More informationCreating objects TOPIC 3 INTRODUCTION TO PROGRAMMING. Making things to program with.
1 Outline TOPIC 3 INTRODUCTION TO PROGRAMMING Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared
More informationProgram Fundamentals
Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java
More informationOutline. Turtles. Creating objects. Turtles. Turtles in Java 1/27/2011 TOPIC 3 INTRODUCTION TO PROGRAMMING. Making things to program with.
1 Outline 2 TOPIC 3 INTRODUCTION TO PROGRAMMING Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared
More informationJAVA: A Primer. By: Amrita Rajagopal
JAVA: A Primer By: Amrita Rajagopal 1 Some facts about JAVA JAVA is an Object Oriented Programming language (OOP) Everything in Java is an object application-- a Java program that executes independently
More informationJava How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.
Java How to Program, 10/e Education, Inc. All Rights Reserved. Each class you create becomes a new type that can be used to declare variables and create objects. You can declare new classes as needed;
More informationAP Computer Science Unit 1. Writing Programs Using BlueJ
AP Computer Science Unit 1. Writing Programs Using BlueJ 1. Open up BlueJ. Click on the Project menu and select New Project. You should see the window on the right. Navigate to wherever you plan to save
More informationAdvanced Computer Programming
Programming in the Small I: Names and Things (Part II) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen University
More informationIntroduction to Java. Java Programs Classes, Methods, and Statements Comments Strings Escape Sequences Identifiers Keywords
Introduction to Java Java Programs Classes, Methods, and Statements Comments Strings Escape Sequences Identifiers Keywords Program Errors Syntax Runtime Logic Procedural Decomposition Methods Flow of Control
More informationThe name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.
Mr G s Java Jive #2: Yo! Our First Program With this handout you ll write your first program, which we ll call Yo. Programs, Classes, and Objects, Oh My! People regularly refer to Java as a language that
More informationCS260 Intro to Java & Android 03.Java Language Basics
03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance
More informationExpressions and Data Types CSC 121 Spring 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types
More informationAlgorithms and Programming I. Lecture#12 Spring 2015
Algorithms and Programming I Lecture#12 Spring 2015 Think Python How to Think Like a Computer Scientist By :Allen Downey Installing Python Follow the instructions on installing Python and IDLE on your
More informationExpressions and Casting
Expressions and Casting C# Programming Rob Miles Data Manipulation We know that programs use data storage (variables) to hold values and statements to process the data The statements are obeyed in sequence
More informationCS112 Lecture: Working with Numbers
CS112 Lecture: Working with Numbers Last revised January 30, 2008 Objectives: 1. To introduce arithmetic operators and expressions 2. To expand on accessor methods 3. To expand on variables, declarations
More information3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)
GETTING STARTED: YOUR FIRST JAVA APPLICATION 15 3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS) GETTING STARTED: YOUR FIRST JAVA APPLICATION Checklist: The most recent version of Java SE Development
More informationCOMP 202 Java in one week
COMP 202 Java in one week... Continued CONTENTS: Return to material from previous lecture At-home programming exercises Please Do Ask Questions It's perfectly normal not to understand everything Most of
More informationExpressions and Data Types CSC 121 Fall 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and
More informationUnit E Step-by-Step: Programming with Python
Unit E Step-by-Step: Programming with Python Computer Concepts 2016 ENHANCED EDITION 1 Unit Contents Section A: Hello World! Python Style Section B: The Wacky Word Game Section C: Build Your Own Calculator
More informationCS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG
CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG 1 Notice Assignments Reading Assignment: Chapter 3: Introduction to Parameters and Objects The Class 10 Exercise
More informationWe will work with Turtles in a World in Java. Seymour Papert at MIT in the 60s. We have to define what we mean by a Turtle to the computer
Introduce Eclipse Create objects in Java Introduce variables as object references Aleksandar Stefanovski CSCI 053 Department of Computer Science The George Washington University Spring, 2010 Invoke methods
More informationThe first program: Little Crab
Chapter 2 The first program: Little Crab topics: concepts: writing code: movement, turning, reacting to the screen edges source code, method call, parameter, sequence, if-statement In the previous chapter,
More informationObjects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003
Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 Java Programs A Java program contains at least one class definition. public class Hello { public static void
More informationA Java program contains at least one class definition.
Java Programs Identifiers Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 A Java program contains at least one class definition. public class Hello { public
More informationFunctions. x y z. f (x, y, z) Take in input arguments (zero or more) Perform some computation - May have side-effects (such as drawing)
2.1 Functions Functions Take in input arguments (zero or more) Perform some computation - May have side-effects (such as drawing) Return one output value Input Arguments x y z f Return Value f (x, y, z)
More informationLab # 2. For today s lab:
1 ITI 1120 Lab # 2 Contributors: G. Arbez, M. Eid, D. Inkpen, A. Williams, D. Amyot 1 For today s lab: Go the course webpage Follow the links to the lab notes for Lab 2. Save all the java programs you
More informationChapter Two Bonus Lesson: JavaDoc
We ve already talked about adding simple comments to your source code. The JDK actually supports more meaningful comments as well. If you add specially-formatted comments, you can then use a tool called
More informationA Foundation for Programming
2.1 Functions A Foundation for Programming any program you might want to write objects functions and modules build bigger programs and reuse code graphics, sound, and image I/O arrays conditionals and
More informationBasics of Java Programming
Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement
More informationChapter 5 Methods. public class FirstMethod { public static void main(string[] args) { double x= -2.0, y; for (int i = 1; i <= 5; i++ ) { y = f( x );
Chapter 5 Methods Sections Pages Review Questions Programming Exercises 5.1 5.11 142 166 1 18 2 22 (evens), 30 Method Example 1. This is of a main() method using a another method, f. public class FirstMethod
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More information12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.
Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started
More informationList of Slides 1 Title 2 Chapter 2: Sequential execution and program errors 3 Chapter aims 4 Section 2: Example:Hello world 5 Aim 6 Class: programs ar
List of Slides 1 Title 2 Chapter 2: Sequential execution and program errors 3 Chapter aims 4 Section 2: Example:Hello world 5 Aim 6 Class: programs are divided into classes 7 Class: public class 8 Class:
More informationRules and syntax for inheritance. The boring stuff
Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for
More informationChapter 2: Programming Concepts
Chapter 2: Programming Concepts Objectives Students should Know the steps required to create programs using a programming language and related terminology. Be familiar with the basic structure of a Java
More informationProject 1. Java Control Structures 1/17/2014. Project 1 and Java Intro. Project 1 (2) To familiarize with
Project 1 and Java Intro Sharma Chakravarthy Information Technology Laboratory (IT Lab) Computer Science and Engineering Department The University of Texas at Arlington, Arlington, TX 76019 Email: sharma@cse.uta.edu
More informationOutline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors
Outline Overview history and advantage how to: program, compile and execute 8 data types 3 types of errors Control statements Selection and repetition statements Classes and methods methods... 2 Oak A
More informationMore About Classes CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario
More About Classes CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario The Story So Far... Classes as collections of fields and methods. Methods can access fields, and
More informationT H E I N T E R A C T I V E S H E L L
3 T H E I N T E R A C T I V E S H E L L The Analytical Engine has no pretensions whatever to originate anything. It can do whatever we know how to order it to perform. Ada Lovelace, October 1842 Before
More informationThe C++ Language. Arizona State University 1
The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University
More informationChapter 2 Author Notes
Chapter 2 Author Notes Good Programming Practice 2.1 Every program should begin with a comment that explains the purpose of the program, the author and the date and time the program was last modified.
More informationCOMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods
COMP-202 Unit 2: Java Basics CONTENTS: Using Expressions and Variables Types Strings Methods Assignment 1 Assignment 1 posted on WebCt and course website. It is due May 18th st at 23:30 Worth 6% Part programming,
More informationProgramming for Engineers Introduction to C
Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines
More informationAn overview of Java, Data types and variables
An overview of Java, Data types and variables Lecture 2 from (UNIT IV) Prepared by Mrs. K.M. Sanghavi 1 2 Hello World // HelloWorld.java: Hello World program import java.lang.*; class HelloWorld { public
More informationAssoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Dr. Marenglen Biba Laboratory Session: Exercises on classes Analogy to help you understand classes and their contents. Suppose you want to drive a car and make it go faster by pressing down
More informationclass objects instances Fields Constructors Methods static
Class Structure Classes A class describes a set of objects The objects are called instances of the class A class describes: Fields (instance variables)that hold the data for each object Constructors that
More informationWelcome to CSE 142! Zorah Fung University of Washington, Spring Building Java Programs Chapter 1 Lecture 1: Introduction; Basic Java Programs
Welcome to CSE 142! Zorah Fung University of Washington, Spring 2015 Building Java Programs Chapter 1 Lecture 1: Introduction; Basic Java Programs reading: 1.1-1.3 1 What is computer science? computers?
More information13 th Windsor Regional Secondary School Computer Programming Competition
SCHOOL OF COMPUTER SCIENCE 13 th Windsor Regional Secondary School Computer Programming Competition Hosted by The School of Computer Science, University of Windsor WORKSHOP I [ Overview of the Java/Eclipse
More informationComputer Science is...
Computer Science is... Automated Software Verification Using mathematical logic, computer scientists try to design tools to automatically detect runtime and logical errors in huge, complex programs. Right:
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More informationA A B U n i v e r s i t y
A A B U n i v e r s i t y Faculty of Computer Sciences O b j e c t O r i e n t e d P r o g r a m m i n g Week 4: Introduction to Classes and Objects Asst. Prof. Dr. M entor Hamiti mentor.hamiti@universitetiaab.com
More informationCT 229 Arrays in Java
CT 229 Arrays in Java 27/10/2006 CT229 Next Weeks Lecture Cancelled Lectures on Friday 3 rd of Nov Cancelled Lab and Tutorials go ahead as normal Lectures will resume on Friday the 10 th of Nov 27/10/2006
More informationCourse Outline. Introduction to java
Course Outline 1. Introduction to OO programming 2. Language Basics Syntax and Semantics 3. Algorithms, stepwise refinements. 4. Quiz/Assignment ( 5. Repetitions (for loops) 6. Writing simple classes 7.
More informationExpressions and Casting. Data Manipulation. Simple Program 11/5/2013
Expressions and Casting C# Programming Rob Miles Data Manipulation We know that programs use data storage (variables) to hold values and statements to process the data The statements are obeyed in sequence
More informationAssignment Marking Criteria
Assignment Marking Criteria Analysis Your analysis documentation must meet the following criteria: All program inputs, processing, and outputs. Each input and output must be given a name and description
More information+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.
+ Inheritance + Inheritance Classes that we design in Java can be used to model some concept in our program. For example: Pokemon a = new Pokemon(); Pokemon b = new Pokemon() Sometimes we need to create
More informationSoftware Design and Analysis for Engineers
Software Design and Analysis for Engineers by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc251 Simon Fraser University Slide Set: 2 Date:
More informationPython Unit
Python Unit 1 1.1 1.3 1.1: OPERATORS, EXPRESSIONS, AND VARIABLES 1.2: STRINGS, FUNCTIONS, CASE SENSITIVITY, ETC. 1.3: OUR FIRST TEXT- BASED GAME Python Section 1 Text Book for Python Module Invent Your
More informationLecture 02, Fall 2018 Friday September 7
Anatomy of a class Oliver W. Layton CS231: Data Structures and Algorithms Lecture 02, Fall 2018 Friday September 7 Follow-up Python is also cross-platform. What s the advantage of Java? It s true: Python
More information9 Working with the Java Class Library
9 Working with the Java Class Library 1 Objectives At the end of the lesson, the student should be able to: Explain object-oriented programming and some of its concepts Differentiate between classes and
More informationImport Statements, Instance Members, and the Default Constructor
Import Statements, Instance Members, and the Default Constructor Introduction In this article from my free Java 8 course, I will be discussing import statements, instance members, and the default constructor.
More informationChapter 4 Defining Classes I
Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the
More information17 Hello world 18 Type: String: literal 19 Standard API: System: out.println() 20 Hello world 21 Statement 22 Statement: simple statements are ended w
List of Slides 1 Title 2 Chapter 2: Sequential execution and program errors 3 Chapter aims 4 Section 2: Example:Hello world 5 Aim 6 Class: programs are divided into classes 7 Class: public class 8 Class:
More informationCOMP-202: Foundations of Programming. Lecture 4: Methods Jackie Cheung, Winter 2016
COMP-202: Foundations of Programming Lecture 4: Methods Jackie Cheung, Winter 2016 Announcements Quiz 1 postponed: Due Jan 26 at 11:59pm Assignment 1 postponed: Due on Feb 1 at 11:59pm 2 Review What is
More informationProgramming in Java Prof. Debasis Samanta Department of Computer Science Engineering Indian Institute of Technology, Kharagpur
Programming in Java Prof. Debasis Samanta Department of Computer Science Engineering Indian Institute of Technology, Kharagpur Lecture 04 Demonstration 1 So, we have learned about how to run Java programs
More informationSection 2.2 Your First Program in Java: Printing a Line of Text
Chapter 2 Introduction to Java Applications Section 2.2 Your First Program in Java: Printing a Line of Text 2.2 Q1: End-of-line comments that should be ignored by the compiler are denoted using a. Two
More informationJava Bytecode (binary file)
Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.
More informationIntroduction to JAVA
Java A001 Hello World Let's study the entire program below: Introduction to JAVA // The "A001" class. import java.awt.*; public class A001 { public static void main (String[] args) { System.out.println("Hello
More informationDM550 Introduction to Programming part 2. Jan Baumbach.
DM550 Introduction to Programming part 2 Jan Baumbach jan.baumbach@imada.sdu.dk http://www.baumbachlab.net COURSE ORGANIZATION 2 Course Elements Lectures: 10 lectures Find schedule and class rooms in online
More information12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.
Java How to Program, 9/e Education, Inc. All Rights Reserved. } Covered in this chapter Classes Objects Methods Parameters double primitive type } Create a new class (GradeBook) } Use it to create an object.
More informationTOPIC 2 INTRODUCTION TO JAVA AND DR JAVA
1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared
More informationCS 231 Data Structures and Algorithms, Fall 2016
CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard
More informationCOMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016
COMP-202: Foundations of Programming Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016 Learn about cutting-edge research over lunch with cool profs January 18-22, 2015 11:30
More informationS.E. Sem. III [CMPN] Object Oriented Programming Methodology
S.E. Sem. III [CMPN] Object Oriented Programming Methodology Time : 3 Hrs.] Prelim Question Paper Solution [Marks : 80 Q.1(a) Write a program to calculate GCD of two numbers in java. [5] (A) import java.util.*;
More informationJava using LEGO Mindstorms and LeJOS. University of Idaho
Java using LEGO Mindstorms and LeJOS University of Idaho 2 Contents 1 Introduction 1 1.1 Setting up Java and Eclipse................................ 1 1.2 Setting up the Lego Brick to work with LeJOS.....................
More informationThe While Statement. If boolean expression is true execute statement; continue to execute statement so long as boolean expression is true.
Variables and Loops The While Statement while ( boolean-expression ) statement If boolean expression is true execute statement; continue to execute statement so long as boolean expression is true. While
More informationLecture 05 I/O statements Printf, Scanf Simple statements, Compound statements
Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple
More informationLast Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings
University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Writing a Simple Java Program Intro to Variables Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch
More informationICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit
ICOM 4015 Advanced Programming Laboratory Chapter 1 Introduction to Eclipse, Java and JUnit University of Puerto Rico Electrical and Computer Engineering Department by Juan E. Surís 1 Introduction This
More informationInheritance and Interfaces
Inheritance and Interfaces Object Orientated Programming in Java Benjamin Kenwright Outline Review What is Inheritance? Why we need Inheritance? Syntax, Formatting,.. What is an Interface? Today s Practical
More informationChapter 2. Designing a Program. Input, Processing, and Output Fall 2016, CSUS. Chapter 2.1
Chapter 2 Input, Processing, and Output Fall 2016, CSUS Designing a Program Chapter 2.1 1 Algorithms They are the logic on how to do something how to compute the value of Pi how to delete a file how to
More information