Methods Android Club 2015.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Using Classes to Store Data Computer Science 2 Gerb.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
BASIC JAVA. Hello World n // Hello world program public class MyFirstJavaProgram { public static void main(String args[]) { char c = 'H'; String s =
Blue Box Diagram Method contains a block of instructions We pass (give) The method information (expressions) as arguments to use Processing is done in.
 To be able to write larger programs ◦ By breaking them down into smaller parts and passing data between the parts.  To understand the concepts of Methods.
16-Aug-15 Java Puzzlers From the book Java Puzzlers by Joshua Bloch and Neal Gafter.
Static Keyword. What is static The static keyword is used when a member variable of a class has to be shared between all the instances of the class. All.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Control Structures if else do while continue break switch case return for.
JAVA—Bitwise. Compiling/Executing a Java Application Source Code Java Compiler ByteCode > Java Interpreter Machine Code >
Objects, Classes and Syntax Dr. Andrew Wallace PhD BEng(hons) EurIng
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
1 Announcements B7 tutorial today in CS103 –In CSE department –Ask at entry desk for direction to CS103.
OOP (pre) Basic Programming. Writing to Screen print will display the string to the screen, the following print statement will be appended to the previous.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Primitive variables Android Club types of variables: Primitive single value (starts with uppercase letter) Complex multiple value (starts with.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
Java Programming static keyword.
1 More data types Character and String –Non-numeric variables –Examples: char orange; String something; –orange and something are variable names –Note.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Java and C++ Transitioning. A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello.
Chapter One Lesson Three DATA TYPES ©
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
Computer Programming 2 Lab (1) I.Fatimah Alzahrani.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Java: Variables and Methods By Joshua Li Created for the allAboutJavaClasses wikispace.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
Output Programs These slides will present a variety of small programs. Each program has a compound condition which uses the Boolean Logic that was introduced.
Object Oriented Programming Lecture 2: BallWorld.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Staples are our staple Building upon our solution.
Introduction to Programming using Java Day 3 and 4 Java Language Basics Review The “For” loop Subroutines The “String” class.
Methods Matthew Harrison. Overview ● There are five main aspects of methods... ● 1) Modifiers – public, private ● 2) Method Name ● 3) Parameters ● 4)
Introduction of Java Fikri Fadlillah, S.T.
Examples of Classes & Objects
using System; namespace Demo01 { class Program
Sum of natural numbers class SumOfNaturalNumbers {
Learning about Programming Languages
Lecture 2: Data Types, Variables, Operators, and Expressions
Introduction to programming in java
Computing Adjusted Quiz Total Score
CSC 113 Tutorial QUIZ I.
Introduction to Java Programming
Classes & Objects: Examples
Building Java Programs
Building Java Programs
CSE 214 – Computer Science I More on Linked Lists
Recap Week 2 and 3.
Building Java Programs Chapter 2
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Java Programming with Multiple Classes
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Scope of variables class scopeofvars {
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Building Java Programs
Building Java Programs
Scope scope: The part of a program where a variable exists. From its declaration to the end of the { } braces A variable declared in a for loop exists.
Building Java Programs Chapter 2
Names of variables, functions, classes
Building Java Programs
Methods/Functions.
Methods (a.k.a functions)
CIS 110: Introduction to Computer Programming
Introduction to java Part I By Shenglan Zhang.
Computer Science Club 1st November 2019.
Instructor: Mainak Chaudhuri
Presentation transcript:

Methods Android Club 2015

private: example public static void main(String[] args) { ClassOne perviyKlass = new ClassOne(); perviyKlass.print(); } private void print(){ System.out.println("Hello Android!");

Private: practice Create new private method: print2() In this method print: “Hello, Tashkent” Call this method from main() method

public: example public void say(){ System.out.println("Hello Hello Hello Hello!"); } ClassTwo: public static void main(String[] args) { ClassOne perviyKlass = new ClassOne(); perviyKlass.say(); }

public: practice Create class: ClassIchi Create method inside ClassIchi: talk() Create another class: ClassNi Call talk() method from ClassNi’s main method

non-static: example public void nonStatic(){ System.out.println("Non static"); } public static void main(String[] args) { ClassOne perviyKlass = new ClassOne(); perviyKlass.nonStatic();

non-static: practice Create non static method: write() In main() method: create instance of class Call write() method

static: example public static void staticMethod(){ System.out.println("Static"); } public static void main(String[] args) { ClassOne.staticMethod();

static: practice Create static method: sayHello() Call this method from main method

return – int: example private static int getNumber() { return 5; } public static void main(String[] args) { int result = getNumber(); System.out.println(result); }

return – int: practice Create method: getTen() Return: 10 In main method print value from getTen()

return-String: example private static String getName() { return "Joe"; } public static void main(String[] args) { String result = getName(); System.out.println(result);

return – String: practice Create new method: getTitle() Return: “Main page” In main method print value from getTitle()

return – boolean: example private static boolean isOpen() { return true; } public static void main(String[] args) { boolean result = isOpen(); System.out.println(result);

return – boolean: practice Create method: isPassed Return: true Print this value in main method

return – char: example private static char getGrade() { return 'a'; } public static void main(String[] args) { char result = getGrade(); System.out.println(result);

return – char: practice Create method: getAndroidVersion Return: ‘m’ Print this value in main method

Pass int - example private static void printInt(int x) { System.out.println(x); } public static void main(String[] args) { printInt(2015);

Pass int - practice Create method: printNumber Pass int: 123 Print int

Pass String - example private static void printString(String text) { System.out.println(text); } public static void main(String[] args) { printString("Android");

Pass String - practice Create method: printName Pass String: your name

Pass boolean - example private static void printBoolean(boolean isReady) { System.out.println(isReady); } public static void main(String[] args) { printBoolean(false);

Pass boolean - practice Create method: printCakeReady Pass boolean: true Print this value

Pass char - example private static void printChar(char grade) { System.out.println(grade); } public static void main(String[] args) { printChar('c');

Pass char - practice Create method printLetter() Pass char: ‘w’ Print char

Congratulations! Now we are experts on methods!