SlideShare a Scribd company logo
Introduction Methods
What is a  Method ? A  method  is a kind of building block that solves a small problem A piece of code that has a name and can be called from the other code Methods allow programmers to construct large programs from simple pieces Methods are also known as  functions ,  procedures , and  subroutines
Why Use Methods? More manageable programming Better organization of the program Easy to read programs Avoid repeating code Code reusability Using existing methods several times
Declaring and  Creating  Methods
Declaring and  Creating  Methods Each method has a  name It is used to call the method Describes its purpose public  static void  printLogo ()   { System.out.println("FunSoft Corp."); System.out.println ("www.funsoft.bg"); }
Declaring and  Creating  Methods (2) Methods declared  public  can be called by any other classes This will be discussed later in details Methods declared  static  can be called by any other method (static or not) This will also be discussed later The keyword  void  means that the method does not return any result public s tatic void   p rintLogo( )  { System.out.println("FunSoft Corp."); System.out.println ("www.funsoft.bg"); }
Declaring and  Creating  Methods (3) Each method has a  body It contains the programming code Surrounded by  {  and  } public  static void printLogo()   { System.out.println("FunSoft Corp."); System.out.println("www.funsoft.bg"); }
Using Parameters Defining and Using Method Parameters
Method  Parameters To pass information to a method, you can use  parameters You can pass zero or several values You can pass values of different types Use parameters to change the way the method works every time you call it
Defining and Using  Method Parameters Method’s behavior depends on its parameters Parameters can be of any type int ,  double ,  String , etc. arrays ( int[] ,  double[] , etc.) public static void printSign( int number )   { if ( number  > 0) System.out.println(&quot;Positive&quot;); else if ( number  < 0) System.out.println(&quot;Negative&quot;); else System.out.println(&quot;Zero&quot;); }
Returning Values From Methods
Returning Values From Methods A method can  return  a value to its caller Returned value: Can be assigned to a variable: Can be used in expressions: Can be passed to another method: String message = input.nextLine(); // input.nextLine() returns a string float price =  g etPrice ()  * quantity * 1.20; System.out.println( input.nextLine() ) ;
Creating a Method That Returns a Value Instead of  void , specify the type of data you want to return Methods can return any type of data ( int ,  String , array, etc.) void  methods do not return anything Use  return  keyword to return a result public static  int  multiply(int number1, int number2) { return  number1 * number2; }
return  Statement return  statement: Terminates  method’s execution Returns the given expression to the caller To terminate  void  method, simply write  return; You can use return several times in a method
Questions ? Methods – Introduction
Ad

More Related Content

What's hot (17)

this in c#
this in c#this in c#
this in c#
Sireesh K
 
Introduction To Algorithm [2]
Introduction To Algorithm [2]Introduction To Algorithm [2]
Introduction To Algorithm [2]
ecko_disasterz
 
Compiler lab final report writing
Compiler lab final report writingCompiler lab final report writing
Compiler lab final report writing
Umme habiba
 
User Defined Functions in C Language
User Defined Functions   in  C LanguageUser Defined Functions   in  C Language
User Defined Functions in C Language
Infinity Tech Solutions
 
SPL 4 | printf in C
SPL 4 | printf in CSPL 4 | printf in C
SPL 4 | printf in C
Mohammad Imam Hossain
 
Python-02| Input, Output & Import
Python-02| Input, Output & ImportPython-02| Input, Output & Import
Python-02| Input, Output & Import
Mohd Sajjad
 
Main topic 3 problem solving and office automation
Main topic 3 problem solving and office automationMain topic 3 problem solving and office automation
Main topic 3 problem solving and office automation
Infinity Tech Solutions
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
Hattori Sidek
 
Introduction to algorithms
Introduction to algorithmsIntroduction to algorithms
Introduction to algorithms
Madishetty Prathibha
 
Flag Waiving
Flag WaivingFlag Waiving
Flag Waiving
Kevlin Henney
 
Ch3 selection
Ch3 selectionCh3 selection
Ch3 selection
Hattori Sidek
 
Algorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo codeAlgorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo code
hamza javed
 
Ch03
Ch03Ch03
Ch03
Arriz San Juan
 
Ch05
Ch05Ch05
Ch05
Arriz San Juan
 
Ch1 principles of software development
Ch1 principles of software developmentCh1 principles of software development
Ch1 principles of software development
Hattori Sidek
 
Ch06
Ch06Ch06
Ch06
Arriz San Juan
 
Input processing and output in Python
Input processing and output in PythonInput processing and output in Python
Input processing and output in Python
Raajendra M
 
Introduction To Algorithm [2]
Introduction To Algorithm [2]Introduction To Algorithm [2]
Introduction To Algorithm [2]
ecko_disasterz
 
Compiler lab final report writing
Compiler lab final report writingCompiler lab final report writing
Compiler lab final report writing
Umme habiba
 
Python-02| Input, Output & Import
Python-02| Input, Output & ImportPython-02| Input, Output & Import
Python-02| Input, Output & Import
Mohd Sajjad
 
Main topic 3 problem solving and office automation
Main topic 3 problem solving and office automationMain topic 3 problem solving and office automation
Main topic 3 problem solving and office automation
Infinity Tech Solutions
 
Algorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo codeAlgorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo code
hamza javed
 
Ch1 principles of software development
Ch1 principles of software developmentCh1 principles of software development
Ch1 principles of software development
Hattori Sidek
 
Input processing and output in Python
Input processing and output in PythonInput processing and output in Python
Input processing and output in Python
Raajendra M
 

Viewers also liked (20)

Grafico diario del dax perfomance index para el 07 11-2012
Grafico diario del dax perfomance index para el 07 11-2012Grafico diario del dax perfomance index para el 07 11-2012
Grafico diario del dax perfomance index para el 07 11-2012
Experiencia Trading
 
Καινοτομια
ΚαινοτομιαΚαινοτομια
Καινοτομια
Elena Elliniadou
 
日本語テスト 空白あり
日本語テスト 空白あり日本語テスト 空白あり
日本語テスト 空白あり
jt_test
 
World Economic Forum on Africa 2006
World Economic Forum on Africa 2006World Economic Forum on Africa 2006
World Economic Forum on Africa 2006
WorldEconomicForumDavos
 
Leveraging Social Media Tools
Leveraging Social Media ToolsLeveraging Social Media Tools
Leveraging Social Media Tools
Sage Island
 
Teatro s. XVII
Teatro s. XVIITeatro s. XVII
Teatro s. XVII
Luis Gil Gil
 
Code iscool
Code iscoolCode iscool
Code iscool
Gordon Bockus
 
ChefConf2014 - Chef TDD
ChefConf2014 - Chef TDD ChefConf2014 - Chef TDD
ChefConf2014 - Chef TDD
Daniel Tracy
 
Digitalisaatio ja valtioneuvosto
Digitalisaatio ja valtioneuvostoDigitalisaatio ja valtioneuvosto
Digitalisaatio ja valtioneuvosto
Jyrki Kasvi
 
LESTER_ANTONY_FRANCIS ( Aug 2016)
LESTER_ANTONY_FRANCIS ( Aug 2016)LESTER_ANTONY_FRANCIS ( Aug 2016)
LESTER_ANTONY_FRANCIS ( Aug 2016)
Lester Antony Francis
 
Talk nerdy to me!
Talk nerdy to me!Talk nerdy to me!
Talk nerdy to me!
Christian Heilmann
 
Adobe Flash, entre el amor y el odio
Adobe Flash, entre el amor y el odioAdobe Flash, entre el amor y el odio
Adobe Flash, entre el amor y el odio
Universidad de Sevilla
 
There's No Crying In Local Search
There's No Crying In Local SearchThere's No Crying In Local Search
There's No Crying In Local Search
Greg Gifford
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
BG Java EE Course
 
On the frontier of genotype-2-phenotype data integration
On the frontier of genotype-2-phenotype data integrationOn the frontier of genotype-2-phenotype data integration
On the frontier of genotype-2-phenotype data integration
mhaendel
 
Презентация устройства "Корден"
Презентация устройства "Корден"Презентация устройства "Корден"
Презентация устройства "Корден"
kulibin
 
Espirometría
EspirometríaEspirometría
Espirometría
Rigoberto José Meléndez Cuauro
 
About the-course
About the-courseAbout the-course
About the-course
BG Java EE Course
 
Estudiante virtual exioso
Estudiante virtual exiosoEstudiante virtual exioso
Estudiante virtual exioso
Kelly Tatiana Rodriguez Uribe
 
Grafico diario del dax perfomance index para el 07 11-2012
Grafico diario del dax perfomance index para el 07 11-2012Grafico diario del dax perfomance index para el 07 11-2012
Grafico diario del dax perfomance index para el 07 11-2012
Experiencia Trading
 
日本語テスト 空白あり
日本語テスト 空白あり日本語テスト 空白あり
日本語テスト 空白あり
jt_test
 
Leveraging Social Media Tools
Leveraging Social Media ToolsLeveraging Social Media Tools
Leveraging Social Media Tools
Sage Island
 
ChefConf2014 - Chef TDD
ChefConf2014 - Chef TDD ChefConf2014 - Chef TDD
ChefConf2014 - Chef TDD
Daniel Tracy
 
Digitalisaatio ja valtioneuvosto
Digitalisaatio ja valtioneuvostoDigitalisaatio ja valtioneuvosto
Digitalisaatio ja valtioneuvosto
Jyrki Kasvi
 
There's No Crying In Local Search
There's No Crying In Local SearchThere's No Crying In Local Search
There's No Crying In Local Search
Greg Gifford
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
BG Java EE Course
 
On the frontier of genotype-2-phenotype data integration
On the frontier of genotype-2-phenotype data integrationOn the frontier of genotype-2-phenotype data integration
On the frontier of genotype-2-phenotype data integration
mhaendel
 
Презентация устройства "Корден"
Презентация устройства "Корден"Презентация устройства "Корден"
Презентация устройства "Корден"
kulibin
 
Ad

Similar to Methods intro-1.0 (20)

Java Foundations: Methods
Java Foundations: MethodsJava Foundations: Methods
Java Foundations: Methods
Svetlin Nakov
 
09. Java Methods
09. Java Methods09. Java Methods
09. Java Methods
Intro C# Book
 
09. Methods
09. Methods09. Methods
09. Methods
Intro C# Book
 
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
wilcockiris
 
Chapter 2.4
Chapter 2.4Chapter 2.4
Chapter 2.4
sotlsoc
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
Kavitha713564
 
11. java methods
11. java methods11. java methods
11. java methods
M H Buddhika Ariyaratne
 
static methods
static methodsstatic methods
static methods
Micheal Ogundero
 
Working with Methods in Java.pptx
Working with Methods in Java.pptxWorking with Methods in Java.pptx
Working with Methods in Java.pptx
maryansagsgao
 
Subprogramms
SubprogrammsSubprogramms
Subprogramms
janapriyanaidu
 
Xamarin: C# Methods
Xamarin: C# MethodsXamarin: C# Methods
Xamarin: C# Methods
Eng Teong Cheah
 
14method in c#
14method in c#14method in c#
14method in c#
Sireesh K
 
Module 4 : methods & parameters
Module 4 : methods & parametersModule 4 : methods & parameters
Module 4 : methods & parameters
Prem Kumar Badri
 
Methods In C-Sharp (C#)
Methods In C-Sharp (C#)Methods In C-Sharp (C#)
Methods In C-Sharp (C#)
Abid Kohistani
 
Class 10
Class 10Class 10
Class 10
SIVASHANKARIRAJAN
 
Intake 38 2
Intake 38 2Intake 38 2
Intake 38 2
Mahmoud Ouf
 
Java method
Java methodJava method
Java method
sunilchute1
 
Csphtp1 06
Csphtp1 06Csphtp1 06
Csphtp1 06
HUST
 
Psuedocode1, algorithm1, Flowchart1.pptx
Psuedocode1, algorithm1, Flowchart1.pptxPsuedocode1, algorithm1, Flowchart1.pptx
Psuedocode1, algorithm1, Flowchart1.pptx
MattFlordeliza1
 
Computer programming 2 Lesson 15
Computer programming 2  Lesson 15Computer programming 2  Lesson 15
Computer programming 2 Lesson 15
MLG College of Learning, Inc
 
Ad

More from BG Java EE Course (20)

Rich faces
Rich facesRich faces
Rich faces
BG Java EE Course
 
JSP Custom Tags
JSP Custom TagsJSP Custom Tags
JSP Custom Tags
BG Java EE Course
 
Java Server Faces (JSF) - advanced
Java Server Faces (JSF) - advancedJava Server Faces (JSF) - advanced
Java Server Faces (JSF) - advanced
BG Java EE Course
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - Basics
BG Java EE Course
 
JSTL
JSTLJSTL
JSTL
BG Java EE Course
 
Unified Expression Language
Unified Expression LanguageUnified Expression Language
Unified Expression Language
BG Java EE Course
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
BG Java EE Course
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and Deployment
BG Java EE Course
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
BG Java EE Course
 
CSS
CSSCSS
CSS
BG Java EE Course
 
HTML: Tables and Forms
HTML: Tables and FormsHTML: Tables and Forms
HTML: Tables and Forms
BG Java EE Course
 
HTML Fundamentals
HTML FundamentalsHTML Fundamentals
HTML Fundamentals
BG Java EE Course
 
WWW and HTTP
WWW and HTTPWWW and HTTP
WWW and HTTP
BG Java EE Course
 
JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery Fundamentals
BG Java EE Course
 
Creating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSSCreating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSS
BG Java EE Course
 
Processing XML with Java
Processing XML with JavaProcessing XML with Java
Processing XML with Java
BG Java EE Course
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
BG Java EE Course
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
BG Java EE Course
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
BG Java EE Course
 
Introduction to-RDBMS-systems
Introduction to-RDBMS-systemsIntroduction to-RDBMS-systems
Introduction to-RDBMS-systems
BG Java EE Course
 

Recently uploaded (20)

tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 

Methods intro-1.0

  • 2. What is a Method ? A method is a kind of building block that solves a small problem A piece of code that has a name and can be called from the other code Methods allow programmers to construct large programs from simple pieces Methods are also known as functions , procedures , and subroutines
  • 3. Why Use Methods? More manageable programming Better organization of the program Easy to read programs Avoid repeating code Code reusability Using existing methods several times
  • 4. Declaring and Creating Methods
  • 5. Declaring and Creating Methods Each method has a name It is used to call the method Describes its purpose public static void printLogo () { System.out.println(&quot;FunSoft Corp.&quot;); System.out.println (&quot;www.funsoft.bg&quot;); }
  • 6. Declaring and Creating Methods (2) Methods declared public can be called by any other classes This will be discussed later in details Methods declared static can be called by any other method (static or not) This will also be discussed later The keyword void means that the method does not return any result public s tatic void p rintLogo( ) { System.out.println(&quot;FunSoft Corp.&quot;); System.out.println (&quot;www.funsoft.bg&quot;); }
  • 7. Declaring and Creating Methods (3) Each method has a body It contains the programming code Surrounded by { and } public static void printLogo() { System.out.println(&quot;FunSoft Corp.&quot;); System.out.println(&quot;www.funsoft.bg&quot;); }
  • 8. Using Parameters Defining and Using Method Parameters
  • 9. Method Parameters To pass information to a method, you can use parameters You can pass zero or several values You can pass values of different types Use parameters to change the way the method works every time you call it
  • 10. Defining and Using Method Parameters Method’s behavior depends on its parameters Parameters can be of any type int , double , String , etc. arrays ( int[] , double[] , etc.) public static void printSign( int number ) { if ( number > 0) System.out.println(&quot;Positive&quot;); else if ( number < 0) System.out.println(&quot;Negative&quot;); else System.out.println(&quot;Zero&quot;); }
  • 12. Returning Values From Methods A method can return a value to its caller Returned value: Can be assigned to a variable: Can be used in expressions: Can be passed to another method: String message = input.nextLine(); // input.nextLine() returns a string float price = g etPrice () * quantity * 1.20; System.out.println( input.nextLine() ) ;
  • 13. Creating a Method That Returns a Value Instead of void , specify the type of data you want to return Methods can return any type of data ( int , String , array, etc.) void methods do not return anything Use return keyword to return a result public static int multiply(int number1, int number2) { return number1 * number2; }
  • 14. return Statement return statement: Terminates method’s execution Returns the given expression to the caller To terminate void method, simply write return; You can use return several times in a method
  • 15. Questions ? Methods – Introduction

Editor's Notes

  • #2: * 10/16/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #5: * 10/16/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #9: * 10/16/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #12: * 10/16/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##