Presentation is loading. Please wait.

Presentation is loading. Please wait.

JAVA Practical 02 1. Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.

Similar presentations


Presentation on theme: "JAVA Practical 02 1. Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters."— Presentation transcript:

1 JAVA Practical 02 1. Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters 6. Case sensitivity 7. Syntax Errors

2 First Steps It is a good idea for to create a folder where we will save our programs So you simply create a folder in my documents and name it ‘My Java’ J Creator is then used to create our programs

3 JCreator In order to start programming we need to create a new file in Jcreator 1. Start up JCreator 2. Click on File > New > File 3. Click on Empty Java File 4. Name the file as ‘Practical02’ 5. Choose to save it in the folder you just created in My Documents

4 First Program Type in the following program What should this program output?

5 Compiling our Program When we compile our program we will be building our file To compile our program we need to press on the ‘Build File’ icon. If we have no errors it will show Process Complete

6 Executing our Program Executing means running our programs Once we compile it we can run our program by pressing the run icon

7 Program Output Once you press run a new window will open showing your programs output

8 Source-Code File The source-code file is the text file create when we save a program This file uses actual text which use humans can read

9 Class File A class file is the file created each time we compile a program The class file contains the code that the JVM (Java Virtual Machine) uses to run our programs.

10 Program Components The different parts of our programs

11 Comments Comments are used to remind the programmer what the code does. There are two type of comments; single line and multi-line. 1. Single line comments: only a single line. In order to create a single-line comment, // must be used before writing the comment. 2. Multi-line comments can be spread over a number of lines, these comments must start with /* and then end with */. //Program 1 : My First Program

12 Class The keyword class shows that a new class is being created Just after the keyword, there must be the name of the class, which is TestProgram in our program Then the curly brackets show where the code of the class begins and ends. class TestProgram

13 Main Method Every program must have one main method It is made up of : 1. public – this means that this method is available from outside the class 2. static – this method can be used without creating an instance of the class 3. void – this method does not return a value 4. main – the name of the method 5. String args[] – an array of type String which can accept a number of arguments in array args public static void main (String args[]){

14 Statement This statement tells the program to print Hello World! as the output println() : tells the program to move the cursor to the next line print(): tells the program to leave the cursor on the same line System.out.println("Hello World!");

15 Semi - colon All statements must end with a semi – colon The semi – colon lets the program know that the statement is over and can be run ;

16 Escape Characters These are used to edit the way the text is printed when using println() Escape CharacterWhat it is used for \’Display in a single quote \”Display in double quotes \\Display a backslash \nMove to a new line \tInsert a tab

17 Case sensitivity When programming in Java we have to be careful to make sure that everything is written correctly It is important to look out when writing words with capital letters and small letters If we write we will get an error… why? system.out.println("Hello World!");

18 Syntax Error An error in the code is called a Syntax error The code will not compile before all the errors are seen too Errors could be; 1. Not obeying the case sensitivity rule 2. Forgetting a semi – colon 3. Forgetting brackets… ect


Download ppt "JAVA Practical 02 1. Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters."

Similar presentations


Ads by Google