( &% class MyClass { }

Similar documents
Java Bytecode (binary file)

CS313D: ADVANCED PROGRAMMING LANGUAGE

Software and Programming 1

PROGRAMMING FUNDAMENTALS

Admin. CS 112 Introduction to Programming. Recap: Exceptions. Summary: for loop. Recap: CaesarFile using Loop. Summary: Flow Control Statements

CS 112 Introduction to Programming

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

AP CS Unit 3: Control Structures Notes

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

CS111: PROGRAMMING LANGUAGE II

Array. Array Declaration:

Topics. Chapter 5. Equality Operators

Following is the general form of a typical decision making structure found in most of the programming languages:

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Software and Programming 1

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it.

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

Introduction to Programming Using Java (98-388)

Lecture 05: Methods. AITI Nigeria Summer 2012 University of Lagos.

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

CS260 Intro to Java & Android 03.Java Language Basics

Introduction to Programming (Java) 4/12

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

Loops. CSE 114, Computer Science 1 Stony Brook University

Opening Problem. Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively.

Method OverLoading printf method Arrays Declaring and Using Arrays Arrays of Objects Array as Parameters

Selected Questions from by Nageshwara Rao

Pace University. Fundamental Concepts of CS121 1

Introduction to Computer Science Unit 2. Notes

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Simple Java Reference

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

Review Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous

Opening Problem. Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively.

Programming with Java

Lecture 5: Methods CS2301

CHAPTER 4 FUNCTIONS. 4.1 Introduction

Java Primer 1: Types, Classes and Operators

CONDITIONAL EXECUTION

Oct Decision Structures cont d

Introduction to Java

COMP 111. Introduction to Computer Science and Object-Oriented Programming. Week 2

Building Java Programs

C and C++ I. Spring 2014 Carola Wenk

Key Differences Between Python and Java

Center for Computation & Louisiana State University -

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

Building Java Programs

Java+- Language Reference Manual

Arrays. Outline 1/7/2011. Arrays. Arrays are objects that help us organize large amounts of information. Chapter 7 focuses on:

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

An overview of Java, Data types and variables

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

Java Basic Programming Constructs

Chapters 1-4 Summary. Syntax - Java or C? Syntax - Java or C?

CS111: PROGRAMMING LANGUAGE II

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Methods and Data (Savitch, Chapter 5)

Section 2.2 Your First Program in Java: Printing a Line of Text

Methods and Functions

Java Tutorial. Saarland University. Ashkan Taslimi. Tutorial 3 September 6, 2011

CS 112 Introduction to Programming

Admin. CS 112 Introduction to Programming. Recap: Java Static Methods. Recap: Decomposition Example. Recap: Static Method Example

Class, Variable, Constructor, Object, Method Questions

COMPUTER APPLICATIONS

In Java, data type boolean is used to represent Boolean data. Each boolean constant or variable can contain one of two values: true or false.

CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II

Administration. Conditional Statements. Agenda. Syntax. Flow of control. Lab 2 due now on floppy Lab 3 due tomorrow via FTP

Array. Prepared By - Rifat Shahriyar

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

Getting started with Java

1 class Lecture5 { 2 3 "Methods" / References 8 [1] Ch. 5 in YDL 9 [1] Ch. 20 in YDL 0 / Zheng-Liang Lu Java Programming 176 / 199

4 Programming Fundamentals. Introduction to Programming 1 1

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

1 Introduction Java, the beginning Java Virtual Machine A First Program BlueJ Raspberry Pi...

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

Computational Expression

CS 177 Spring 2010 Exam I

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

Flow Control. CSC215 Lecture

Important Java terminology

Java Classes: Math, Integer A C S L E C T U R E 8

Chapter 4 Defining Classes I

Section 2.2 Your First Program in Java: Printing a Line of Text

2/3/2018 CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II. Lecture Contents. C# basics. Methods Arrays. Dr. Amal Khalifa, Spr17

Fall 2017 CISC124 9/16/2017

Accelerating Information Technology Innovation

Mr. Monroe s Guide to Mastering Java Syntax

Supplementary Test 1

Transcription:

Recall! $! "" #

' ' )' %&! ( &% class MyClass {

$

Individual things that differentiate one object from another Determine the appearance, state or qualities of objects Represents any variables needed for class to function

' * &

' &

)'! class Car { $ String color; String model; boolean enginestate;

,' * + - %& class Car {. String color; String model; static boolean enginestate = true;

/ 0

Objects communicate to each other through method Determine what instance of the class do to change their internal state. Provide functionality provided with an entire class

$

' * &

' * & ( 12 ( 12 3 12 12

)' (4 ' void startengine() { if (enginestate == true) System.out.println("The engine is already on."); else { enginestate = true; System.out.println("The engine is now on.");

,' (4 ' 5 class Car { String Color, Model; static boolean enginestate=true; void startengine() { if (enginestate == true) 6 12 7 System.out.println("The engine is already on."); else { enginestate = true; System.out.println("The engine is now on.");

! / / / / &

/ Method s declaration provides information to compiler, runtime system, to other class and object. Carries information such as return value of a method, number and types of arguments and what other class and object can call from method. & 4' 89 :& : 1 :28 :9 ;8 :9<

/ Method is also known as function when used in other programming languages such as C, C++,C#, ASP, PHP, and so on. They are also implemented the same concept and syntax except for the modifier and throws clause. main() is also a method, but it plays the most important part in a program where it acts as the controller of a program. Creating or constructing other method(s) means that the tasks in main() method is being reduced.

/ & 4 The return type is either a valid Java type (primitive or class) or void if no value is returned. If the method declares a return type, every exit path out of the method must have a return statement. The method name must be a valid Java identifier Each parameter is separated by a comma. Also, there can be zero parameters. The method body is contained in a set of curly braces or contains a sequence of semicolon delimited Java statements that are executed sequentially or the method body can be empty.

/ '/ "!!!"$! % %" "#!"#!!!!"!

= Code conventions restrict the method names. By convention, method names should be begin with a verb in lower case, followed by capitalized verb if any. Method have unique name within its class. But, method might have same name as other class due to method overloading concept. (4 '

= & Code conventions restrict the method names. By convention, method names should be begin with a verb in lower case, followed by capitalized verb if any. Method have unique name within its class. But, method might have same name as other class due to method overloading concept. 12 (4 '

! / / / / &

(4 ' / & 12 / & %. 1 42 ;< 3 1 2 ; %<

/ &'C " (4 ' ; 1 892 ;&.. 1>=??@ A 2B &.. 1>/ =.??@ A2B &.. 1>-??> A&2B &.. 1>$??> A2B < < '(4

(4 ' / &'C " '! ; * 12 ;< 1 892 ;< <

(4 ' / &'C " )'5 4 ; * 12 / < ;&.. 1>=??@ A 2B &.. 1>/ =.??@ A2B &.. 1>-??> A&2B &.. 1>$??> A2B < 1 892 ;< 12

(4 / &'C " &6 & & ; &5 C 5 &B %CB 1 892 ; &5CDE.B %CDFB & D&5CG %CB < <

/ &'C " & ;&5 C 5 &B %CB 5 &12 ;&5CDE.B %CDFB & D&5CG %CB < 1 892 ;< (4 5 &12

(4 / &'C " ; D B DEB B 1 892 ; D G B &.. 1 2B <

/ &'C " ; D B DEB B 12 ; D G B &.. 1 2B < 1 892 ; < (4 12

(4 / &'C " ; D B DEB B 1 892 ; D G B &.. 1 2B < %.

/ &'C " ; D B DEB B (4 12 1 4 &2 ; D4G&B B < 1 892 ; &.. 1 1 22B <<

#&/ / / / /.

./ (4 No return value &* 12 No parameters Places to determine whether this method will return a value or not 5 & &

./ C " ' ' )'! & H void! 12!

./ (4 Write a method to display a student s name and matric number void displaystudentinfo() { System.out.println( Name + name); System.out.println( Matric no. + no);

./ (4 Where to put the defined method? class Student { void displaystudentinfo() { System.out.println( Name + name); System.out.println( Matric no. + no); public static void main(string[] args) {//Call method here C 77

./ (4 Write a method to calculate the product of variable A variable B. void calculate() { product = A * B;

./ (4 Where to put the defined method? class Count { int product,a = 6, B = 4; void calculate() { product = A * B; C 77 public static void main(string[] args) {//Call method here I J.

./ (4 Write a method to display a grade based on an accepted mark. void findgrade() { if ( mark >= 85 && mark <= 100) grade = A ;

./ (4 class StudentMark { int mark; String grade; Where to put the defined method? void findgrade() { if (mark >= 85 && mark <=100) grade = A ; C 77 public static void main(string[] args) {//Call method here I %.

./ (4 int return value 1 2 This method will return an integer value Can be either int, float, double and char (other than void). Pass by value/ Has parameter &

./ This method is also known as method with parameters and a return value. Pass by value happen when we invoke a method with parameters A copy of the value of the actual parameter is passed to the method. The actual variable outside the method are not affected. Contains return keyword at the end of method.

./ (4 class Count { int add(int a, int b) { int addproduct; addproduct = a * b; return addproduct; K & public static void main(string[] args) { int num1 =4, num2 = 7; I main().

./ (4 class Count { int num1 =4, num2 = 7; int add(int a, int b) { int addproduct; addproduct = a * b; return addproduct; I. K & public static void main(string[] args) {

./ (4 class StudentMark { int mark; char grade; I %. int findgrade(int m) { if (mark >= 85 && mark <=100) grade = A ; K return grade; & public static void main(string[] args) {//Call method here

)./ (4 int return value 12 This method will return an integer value Can be either int, float, double and char (other than void). No parameter = &

)./ (4 class StudentMark { int mark = 90; char grade; I %. = int findgrade() { if (mark >= 85 && mark <=100) grade = A ; K return grade; & public static void main(string[] args) {//Call method here

)./ (4 I. class Calculate { double no1 = 8,no2 =9; = double addvalue() {return no1 + no2; K & public static void main(string[] args) {//Call method here

)./ (4 class Count { int number[],odd = 0; int oddnumber() { for (int i=0;i<5;i++) { if (number[i]% 2 ==1) odd++; return odd; I. = K & public static void main(string[] args) {//Call method here

,./ (4 Two integer parameters No return value 1 4 &2 This method will not return any value # &

,./ (4 I. class Calculate { double no1 = 8,no2 =9, total; # void addvalue( double x, double y) {total= x + y; public static void main(string[] args) {//Call method here

,./ (4 class Count { int number[],odd = 0; void oddnumber(int n[]) { for (int i=0;i<5;i++) { if (n[i]% 2 ==0) odd++; I. L = public static void main(string[] args) {//Call method here

%& & 12. %& & %.! &.! &.