Writing Methods PowerPoint PPT Presentation

presentation player overlay
1 / 19
About This Presentation
Transcript and Presenter's Notes

Title: Writing Methods


1
Writing Methods
2
Create the method
  • Methods, like functions, do something
  • They contain the code that performs the job
  • Methods have two parts

3
Create the method
  • The first part is called the Header
  • modifier return name
  • public void message( )
  • open closing braces

4
Methods have two parts
  • The second part is called the Body
  • The body contains the lines of code that instruct
    the computer what to do
  • You can have as many lines of code in the body as
    you want

5
Methods have two parts
  • This Body has one line of code
  • It tells the computer to print to the screen the
    text that is inside the set of double quotes
  • public void message( )
  • System.out.println()
  • System.out.println(java is not kawfy)

6
Create a Class
  • To use the method we need to create a simple
    class
  • We put the method inside the class
  • The class can have as many methods as you wish
  • The class also has a Header and a Body

7
Create a Class
  • The first part is called the Header
  • modifier structure name
  • public class MyClass
  • open closing braces

8
Create a Class
  • The second part is called the Body
  • The body contains one or more methods
  • public class MyClass
  • public void message()
  • System.out.println()
  • System.out.println(java is not kawfy)

9
Create an Application
  • An Application is an executable program
  • It uses the methods of different classes to
    execute the program
  • Some methods are from the Java Class Library
  • Other methods are from the Classes that We wrote

10
Create an Application
  • We will create an object (instance) of the class
  • We will call (invoke) a method of the class
  • The Application class also has a Header and a
    Body
  • The Application has one method named main

11
Create an Application
  • Syntax
  • public class Morty
  • public static void main(String args)
  • MyClass mc new MyClass()
  • mc.message()

12
Compile and Run
  • Compile correct any syntax errors
  • Run check for correct output
  • If necessary make any corrections
  • Then recompile and rerun.

13
1-compile
2-run
3-output
14
(No Transcript)
15
  • You will need to download a text editor
  • You will need to download the latest version of
    Java
  • You will need to reset the Path variable
  • You will then be ready to roll

16
(No Transcript)
17
(No Transcript)
18
To Edit (add or delete) the PATH of the Windows
O/S 0- Start 1- Settings 2- Control
Panel 3- System 4- System Properties
(dialog box) 5- Advanced (tab) 6-
Environment Variables 7- User (System
variables) You can edit a current variable You
can add/delete Delimiter is a semi-colon
19
  • The Path should be edited by inserting the
  • following line at the very beginning
  • C\ program files\java\jdk1.5.0_06\bin
  • Make sure you put the semi-colon (delimiter)
    right
  • after the word bin
Write a Comment
User Comments (0)
About PowerShow.com