Java Programming with BlueJ

Slides:



Advertisements
Similar presentations
Looking inside classes Fields, Constructors & Methods Week 3.
Advertisements

CSCI 160 Midterm Review Rasanjalee DM.
Chapter 2: Using Objects Part 1. To learn about variables To understand the concepts of classes and objects To be able to call methods To learn about.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
1 Classes, Encapsulation, Methods and Constructors (Continued) Class definitions Instance data Encapsulation and Java modifiers Method declaration and.
IT151: Introduction to Programming
Java Basics M Taimoor Khan
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
Fall 2007ACS-1903 BlueJ Ron McFadyen Lab 1: Using BlueJ at UofW The purpose of this lab is to give you some experience with BlueJ. Over the course of the.
COMP 110 Introduction to Programming Mr. Joshua Stough October 8, 2007.
Understanding class definitions Looking inside classes 3.0.
Objects Interaction and Source Code Week 2. OBJECT ORIENTATION BASICS REVIEW.
1 Fall 2007ACS-1903 Chapter 6: Classes Classes and Objects Instance Fields and Methods Constructors Overloading of Methods and Constructors Scope of Instance.
Understanding class definitions – Part II –. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main.
Understanding class definitions Looking inside classes.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Chapter 2 How to Compile and Execute a Simple Program.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Introduction to Java. 2 Textbook David J. Barnes & Michael Kölling Objects First with Java A Practical Introduction using BlueJ Fourth edition, Pearson.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Classes CS 21a: Introduction to Computing I First Semester,
Chapter 3: Developing Class Methods Object-Oriented Program Development Using Java: A Class-Centered Approach.
Week 2 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Chapter 2 Using Objects. Types A type defines a set of values and the operations that can be carried out on the values Examples: 13 has type int "Hello,
1 Principles of Computer Science I Prof. Nadeem Abdul Hamid CSC 120 – Fall 2005 Lecture Unit 2 - Using Objects.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Understanding class definitions
Chapter 4 Introduction to Classes, Objects, Methods and strings
By Mr. Muhammad Pervez Akhtar
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 4th Edition.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Creating Your Own Classes
Objects as a programming concept
3 Introduction to Classes and Objects.
Introduction to Python
Object Oriented Programming
Yanal Alahmad Java Workshop Yanal Alahmad
Java Primer 1: Types, Classes and Operators
Variables A piece of memory set aside to store data
Chapter 3: Using Methods, Classes, and Objects
Data types and variables
The Selection Structure
Variables, Expressions, and IO
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
Understanding class definitions
Chapter 3 Introduction to Classes, Objects Methods and Strings
Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects Outline Test-Driving the Microwave Oven Application Designing.
An Introduction to Java – Part II
Classes, Encapsulation, Methods and Constructors (Continued)
MSIS 655 Advanced Business Applications Programming
Lab 1 Introduction to C++.
CS139 October 11, 2004.
Introduction to Java Programming
Understanding class definitions
Object Oriented Programming in java
Java Programming with BlueJ Objectives
Classes CS 21a: Introduction to Computing I
Unit 3: Variables in Java
Running a Java Program using Blue Jay.
Just Enough Java 17-May-19.
CS 1054: Lecture 2, Chapter 1 Objects and Classes.
References Revisted (Ch 5)
Day 11 The Last Week!.
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Java Programming with BlueJ (Gift from Krysten Hall) Editted by Mr. S. Lupoli

Java Programming with BlueJ Objectives By the end of this presentation you should be able to: Open a BlueJ project Create an instance of a class Invoke methods of a class Toggle between the project window and the output window Identify parameters to a method

Java Programming with BlueJ Objectives View the source code Give examples of different data types Identify the 4 parts of a method signature Identify comments Identify accessor and mutator methods Use the printing methods Use selection statements Identify local variables

Opening a preexisting BlueJ Project Will need to do this: For THIS presentation And whenever you SAVE and return to a project Directions Open BlueJ Project -> Open Project -> C:\BlueJ\examples\shapes

Java Programming with BlueJ We will examine the features of BlueJ by working with the shapes project. The shapes project initially looks like this: The shapes project

Opening setup You may need to COMPILE the given files If each class has /’s under them RIGHT click on each class Select Compile

Java Programming with BlueJ Creating Instances of Classes To create an instance of the Circle class in the shapes project Right click the Circle class Click new Circle( ) Name the instance and click OK Note the naming conventions of lowercase for objects and uppercase for classes Class Object on the Object Bench

Java Programming with BlueJ Invoking Methods To invoke the methods of each class Right-click the object on the object bench Click the method to invoke from the menu, try makeVisible( )

Java Programming with BlueJ You should see a blue ball appear in a separate window. makeVisible( ) from the menu creates the blue ball in another window

Java Programming with BlueJ Parameters Some methods require a parameter be passed to it. For example the moveVertical method requires a distance and changeColor requires a color Parameters to methods

Java Programming with BlueJ Method Signatures When a method requires a parameter you will get a second window to enter that parameter. Note that the method signature indicates the type of data to be entered. Method signature

Java Programming with BlueJ Viewing the Source Code The source code for a class can be viewed by opening the editor. Right-click the class, click Open Editor.

Java Programming with BlueJ Viewing the Source Code The source code for the methods is shown here in the class definition. All methods included in the class are here.

Java Programming with BlueJ Data Types Some methods require parameters, these parameters have a type int – numeric values without decimals -5, 100, 303 -45 float – numeric values with decimals -0.456, 9.65, 100.1 String – a combination of alphanumeric symbols grouped with quotation marks “ “ “red”, “101 College Parkway”, “123”

Java Programming with BlueJ Method Signatures The method signature has 4 parts. public void moveVertical(int distance) 1) Access modifier 2) Return type 3) Name 4) Parameter list NOTE: If the parameter list is empty the parentheses MUST remain. All other parts are required.

Java Programming with BlueJ Comments Comments are included in a program to provide information to the reader about how the source code performs or was created. A single line comment begins with // (no spaces) Multi-line comments for more detailed explanations start with /* and end with */ A multi-line comment

Programming in Java with BlueJ Class definition A class definition contains: Instance variables – the data items for the class. The computer instructions in the methods act on these data items. Also called fields. Methods – the actions taken on the data items. Methods are just sequences of computer instructions. Instance variables Method acting on the instance variable

Java Programming with BlueJ Constructors Note class name is the same as the constructor A constructor is a method that has the same name as the class and provides the initial values for an object. A constructor is executed EACH time a class is instantiated.

Java Programming with BlueJ Assignment Statements The general format of an assignment statement is: variable = expression The expression is evaluated first and the value of the expression is stored in the variable. An assignment statement always terminates with a semi-colon (;) in Java. An assignment statement

Java Programming with BlueJ Accessor methods An accessor method is one that returns information to the caller about the state of an object. Remember that the state of an object is defined by the instance variables. Often an accessor method will contain a return statement in order to pass data back to the caller. Some display functions are considered accessor methods, too. An accessor method

Java Programming with BlueJ Mutator Methods (Mutators) A mutator method is one that changes the state of an object. Mutator methods

Java Programming with BlueJ Printing To display data and text to the screen the println method is used from the System.out object. Various forms of the print statement: System.out.println( ); Sends a linefeed to the output window. System.out.println(“text here”); Displays the text within the “ “ to the output window. System.out.println(“text “ + variable); Creates one string parameter consisting of the text in “ “ and the value of the variable.

Java Programming with BlueJ Printing Display statements

Java Programming with BlueJ Making Choices – Selection Statements The general form of a selection statement: if (condition that evaluates to true or false) { perform these steps if the condition evaluates to true } else{ perform these steps if the condition evaluates to false Some examples: if (length < 0){ System.out.println(“length can’t be negative”); } if (width < 0){ System.out.println(“width can’t be negative”); else { System.out.println(“width accepted”);

Java Programming with BlueJ Making decisions Selection statement

Java Programming with BlueJ Local variables A local variable A local variable is declared inside of a method or constructor and is only used during the execution of the method or constructor. Local variables are temporary. Local variables must be initialized before they are used. A local variable never has private or public associated with it.

Java Programming with BlueJ Conclusion and Assignments Work on assignments given by your instructor.