Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tonga Institute of Higher Education

Similar presentations


Presentation on theme: "Tonga Institute of Higher Education"— Presentation transcript:

1 Tonga Institute of Higher Education
Java Basics Tonga Institute of Higher Education

2 How Object Oriented Programs Work
The building block of an object-oriented language is an object. Object - A self-contained entity that contains data and procedures to manipulate the data. An object is like a tool that we can use to do things.

3 Classes /* This program displays “Hello World!" to the standard output. */ class HelloWorld { public static void main(String[] args) { //Displays a message System.out.println(“Hello World!"); } Class - The blue print or design for creating an object. Each program must have a class Each class has a name Class names should be nouns One word The first letter is capitalized. The first letter of each internal word is capitalized. Keep your class names simple and descriptive. Example: Customer SalesOrder You need an open bracket and a close bracket after the name of the class. The contents of the class is between the brackets Everything inside a class is indented.

4 Demonstration Create a class

5 Methods /** This program displays “Hello World!" to the standard output. */ class HelloWorld { public static void main(String[] args) { //Displays a message System.out.println(“Hello World!"); } Methods - Pieces of code that perform a single function Each method has a name Method names should be verbs One word The first letter is lower case. The first letter of each internal word is capitalized. Keep your method names simple and descriptive. Example: runFast getBackground showWelcomeMessage You need an open bracket and a close bracket after the name of the method. The contents of the method is between the brackets Everything inside a method is indented.

6 main() Method Each Java program must have a method called main().
/** This program displays “Hello World!" to the standard output. */ class HelloWorld { public static void main(String[] args) { //Displays a message System.out.println(“Hello World!"); } Each Java program must have a method called main(). The work of the program is started in the main method when the class is run from the command line prompt.

7 Creating methods Creating main methods
Demonstration Creating methods Creating main methods

8 Details Java requires a lot of attention to detail!
All Java statements must end with a semi-colon. Line breaks are ignored. Indentations are ignored. Even spaces are ignored except in quoted Strings. Use indentations and spaces to improve readability Case is important. Always check capitalization! Good System.out.println(“I love Java”); Bad system.out.Println(“I love Java”);


Download ppt "Tonga Institute of Higher Education"

Similar presentations


Ads by Google