Introduction to Java Part 3 - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Introduction to Java Part 3

Description:

BA Mosbach / Referent Lars Vogel. Comments in Java ... Anther method may call this method and pass the real values to the method: public class Math ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 13
Provided by: D416
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Java Part 3


1
Introduction to Java Part 3
  • Informatik III

2
Comments
3
Comments in Java
  • / This kind of comment can span multiple lines
    /
  • // This kind is to the end of the line
  • / This kind of comment is a special
    javadoc style comment /
  • Source code should be documented via comments

4
Parameter of methods
5
Method parameters
  • A method can get parameters
  • Placeholder for the actual values which are
    passed to the method
  • Anther method may call this method and pass the
    real values to the method

public class Math public void
multiplyWrite(int a, int b)
System.out.println(a b)
Math variable1 new Math() variable1.multiplyWri
te(4,2)
6
Return values
7
Return values
  • A method can return the result of its calculation
  • void means that no return value is returned
  • If a return value is included then the calling
    method can use the return value.

public class Math public int multiply(int
a, int b) return a b
8
Return values - Explained
method multiply (int a, int b)
Another method calling multiply
Tell me what is 12 x 14
Ahthe result is 168
Method main calls method multiply
Method multiply returns the result
9
Code Example
10
Code Example Part 1
11
Code Example Part 2
  • This is a class which uses the other class

12
Exercises
  • Make your application more flexible
  • Perform the following exercise
  • http//www.vogella.de/articles/JavaIntroduction/ar
    ticle.htmlexercise08
  • http//www.vogella.de/articles/JavaIntroduction/ar
    ticle.htmlexercise10
  • http//www.vogella.de/articles/JavaIntroduction/ar
    ticle.htmlexercise12
  • http//www.vogella.de/articles/JavaIntroduction/ar
    ticle.htmlexercise14
Write a Comment
User Comments (0)
About PowerShow.com