Saturday, August 29, 2015

If you become part of a development team in industry, you might work on applications that contain hundreds, or even thousands, of classes.


You can use Eclipse IDE which I recommend or any other IDE.


Obviously we won't be starting from scratch. There's always a introduction about computer languages and how the system works and how the java program works. You obviously can find these stuff in any java book. i would recommend you to download that book " java how to program".

Now, let's start!

You obviously going need a class to start a program. while you are writing a program, u gotta be careful that "java" is a case sensitive letters.

let's provide a small program and start illustrating it.

1

2 // Class declaration with one method.

3

4 public class GradeBook

5 {

6 // display a welcome message to the GradeBook user

7 public void displayMessage()

8 {

9 System.out.println( "Welcome to the Grade Book!" );

10 } // end method displayMessage

11 } // end class GradeBook


Class GradeBook (declared in the file GradeBook.java) will be used to display a message on the screen. welcoming the instructor to the grade book application.

Each classdeclaration that begins withkey word public must be stored in afile having the same name as the class and ending with the .java file-name extension.
Class GradeBook The GradeBook class declaration contains a displayMessage method (lines 7– 10) that displays a message on the screen. We’ll need to make an object of this class and call its method to execute line 9 and display the message. The class declaration begins in line 4. The keyword public is an access modifier. For now, we’ll simply declare every class public. Every class declaration contains keyword class followed immediately by the class’s name. Every class’s body is enclosed in a pair of left and right braces, as in lines 5 and 11 of class GradeBook.

ClassGradeBook also has one method—displayMessage (lines 7–10). Recall that main is a special method that’s always called automatically by the Java Virtual Machine (JVM) when you execute an application. Most methods do not get called automatically . As you’ll soon see, you must call method displayMessage explicitly to tell it to perform its task.



The method declaration begins with keyword public to indicate that the method is "available to the public"—it can be called from methods of other classes.
Next is the method’s return type, which specifies the type of data the method returns to its caller after performing its task. The return type void indicates that this method will perform a task but will not return (i.e., give back) any information to its calling method. You’ve used methods that return information.


1

2 // Creating a GradeBook object and calling its displayMessage method.

3

4 public class GradeBookTest

5 {

6 // main method begins program execution

7 public static void main( String[] args )

8 {

9 // create a GradeBook object and assign it to myGradeBook

10 GradeBook myGradeBook = new GradeBook();

11

12 // call myGradeBook's displayMessage method

13 myGradeBook.displayMessage();

14 } // end main

15 } // end class GradeBookTest

using myGradeBook followed by a dot separator (.), the method name displayMessage and an empty set of parentheses. This call causes the displayMessage method to perform its task.

For any questions, leave it in comments. thank you.

What we gonna do next is explain how to declare a method with a parameter.

1 comment: