Agenda Remarks about last homeworks Class methods(static methods)

Slides:



Advertisements
Similar presentations
Chapter 8: Arrays.
Advertisements

Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Hand Crafting your own program By Eric Davis for CS103.
CS 106 Introduction to Computer Science I 02 / 18 / 2008 Instructor: Michael Eckmann.
Arrays Horstmann, Chapter 8. arrays Fintan Array of chars For example, a String variable contains an array of characters: An array is a data structure.
1 Chapter 7 Inheritance, Polymorphism, and Scope.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
CS 106 Introduction to Computer Science I 10 / 04 / 2006 Instructor: Michael Eckmann.
1 Chapter 2 Introductory Programs. 2 Getting started To create and run a Java program –Create a text file with a.java extension for the source code. For.
What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you.
Java Unit 9: Arrays Declaring and Processing Arrays.
03/16/ What is an Array?... An array is an object that stores list of items. Each slot of an array holds an individual element. Characteristics.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Lecture # 8 Constructors Overloading. Topics We will discuss the following main topics: – Static Class Members – Overloaded Methods – Overloaded Constructors.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
1. 2 Reference... Student stu; Reference of Student stu When the reference is created it points to a null value. Before access the reference, objects.
© 2007 Lawrenceville Press Slide 1 Chapter 10 Arrays  Can store many of the same kind of data together  Allows a collection of related values to be stored.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
Computer Programming 12 Mr. Jean April 24, The plan: Video clip of the day Upcoming Quiz Sample arrays Using arrays More about arrays.
Methods in Java. Program Modules in Java  Java programs are written by combining new methods and classes with predefined methods in the Java Application.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Java Arrays and Methods MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation ©Akhilesh.
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
Arrays-. An array is a way to hold more than one value at a time. It's like a list of items.
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
Week 6 - Friday.  What did we talk about last time?  Loop examples.
Introduction to programming in java Lecture 22 Arrays – Part 2 and Assignment No. 3.
Chapter 8 Arrays and the ArrayList Class Arrays of Objects.
C++ LANGUAGE MULTIPLE CHOICE QUESTION SET-3
Array in C# Array in C# RIHS Arshad Khan
Agenda Array accessing Automatic initialization of an array
OBJECT ORIENTED PROGRAMMING I LECTURE 7 GEORGE KOUTSOGIANNAKIS
CS116 OBJECT ORIENTED PROGRAMMING II LECTURE 1 Part II
C# Programming Arrays in C# Declaring Arrays of Different Types Initializing Array Accessing Array Elements Creating User Interfaces Using Windows Standards.
C++ Arrays.
What If? Write a program that prompts for the names and locations of 1000 employees. Store the information in the program for later use.
Chapter 8: Collections: Arrays
OBJECT ORIENTED PROGRAMMING I LECTURE 7 GEORGE KOUTSOGIANNAKIS
Phil Tayco Slide version 1.0 Created Oct 16, 2017
Interface.
Pemrograman Dasar Methods PTIIK - UB.
Can store many of the same kind of data together
Arrays, Casting & User Defined Types
An Introduction to Java – Part I, language basics
Introduction to Classes and Methods
CS 302 Week 8 Jim Williams, PhD.
Arrays of Objects Fall 2012 CS2302: Programming Principles.
Arrays of Objects Fall 2012 CS2302: Programming Principles.
Introduction To Programming Information Technology , 1’st Semester
CIS 110: Introduction to Computer Programming
Can store many of the same kind of data together
Introduction to Programming
CS2011 Introduction to Programming I Arrays (I)
Take out a piece of paper and PEN.
class PrintOnetoTen { public static void main(String args[]) {
Arrays.
OBJECT ORIENTED PROGRAMMING II LECTURE 13_2 GEORGE KOUTSOGIANNAKIS
Can store many of the same kind of data together
Programming Control Structures with JavaScript Part 2
Single-Dimensional Arrays chapter6
Object Oriented Programming Review
OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS
CSC 142 Arrays [Reading: chapter 12].
By Yogesh Neopaney Assistant Professor Department of Computer Science
Submitted By : Veenu Saini Lecturer (IT)
Generic Programming.
Java: Variables, Input and Arrays
PROGRAMMING ASSIGNMENT I
Week 7 - Monday CS 121.
Week 9 - Monday CS222.
Presentation transcript:

Agenda Remarks about last homeworks Class methods(static methods) Class signature Arrays Presentations topic homework

Static methods BPJ lesson 20; Barron’s chapter 2 Static methods are sometimes called class methods. The difference between static and no-static methods: we are accessing them at the class level rather than the object level. Math class vs Random class Math.sqrt(4.0); Random.nextInput(); => wrong

testMethod2.calculateRectanglePerimeter(4, 13); public static void main(String[] args) { testMethod2.calculateRectanglePerimeter(4, 13); //testMethod2.printSmiley(); testMethod2 tM = new testMethod2(); tM.printSmiley(); }

Practice Create a class Aclass with two methods, one with static keyword, and one without. This class doesn’t need to have main(). Create another class Bclass with a main() to call the methods in Aclass. Try to see the differences about static and non-static methods calling.

Arrays Philip Costa Minna Justin An array is a structure that can store many of the same kind of data together at once. An array has a fixed length and can contain only as many data items as its length allows: Array of size 4 1 2 3 4 Friends Philip Costa Minna Justin

Arrays An Array elements: can be any data type Each element has an index value, with 0 being the index of the first item, 1 the index of the second item, and so on. Declaration: String[] friends = new String[5]; //5 friends int[] intArray = new int[20]; char[] charArray = new char[40];

Arrays Array Declaration <type>[] <name>; //declare array <name> = new <type>[<num>]; //allocate space for elements Array declaration and initialization String[] friends = {"Kermit", "Lucille", "Sammy", "Roxy"};

Practice Practice array declaration and initialization with every primitive types. Example: int[] intArray = {10, 20, 30}; Do the exercise on Lesson 18 exercise 1 - 6

Array index Philip Costa Minna Justin 1 2 3 4 Friends Array index starts from 0, assume that we want to create a Friends array like above: String[] Friends = new String[4]; Friends[0] = “Philip”; Friends[1] = “Costa”; Friends[2] = “Minna”; Friends[3] = “Justin”; Philip Costa Minna Justin

Array Accessing example doulbe[] sgt = new double[20]; for(int i = 0; i <sgt.length; i++) sgt[i] = (double) i; System.out.println("sgt element " +sgt[i]);

Class signature <access _ level> class <name> { <variables> <constructors> <methods> }

Classes A class is written in a separate file and consists of a declaration and a body. The class declaration includes the access level, the keyword class, and the class name. The class body contains variables, constructors, and methods. Constructors are used to initialize variables in a class. Variables and methods are called the members of a class

Homework Create a StudentRoster application that prompts the user for the number of students in the class and then prompts the user for each student’s name and stores the names in an array. After all the names have been entered, the application should display the title ”Student Roster” and then list the names in the array.