Difference between revisions of "Java/C2/First-Java-Program/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with ''''Title of script''': Getting started with java: first program. '''Author: Prathamesh Salunke''' '''Keywords: video tutorial, Hello World, first program''' {| style="border…')
 
 
(One intermediate revision by one other user not shown)
Line 27: Line 27:
 
<nowiki>* To compile the program.</nowiki>
 
<nowiki>* To compile the program.</nowiki>
  
<nowiki>* To run the program.</nowiki>
+
<nowiki>* To run the program</nowiki> and
  
 
<nowiki>* About the naming conventions followed.</nowiki>
 
<nowiki>* About the naming conventions followed.</nowiki>
Line 48: Line 48:
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| To follow this tutorial '''JDK 1.6 '''must be installed on your system.
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| To follow this tutorial '''JDK 1.6 '''must be installed on your system.
  
If not, for relevant tutorial please visit our website as shown.
+
If not, for relevant tutorial please visit our website which is as shown.
  
 
|-
 
|-
Line 54: Line 54:
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Let us now write our first java program.
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Let us now write our first java program.
  
For that you need a '''Terminal''' and a '''Text''' '''Editor'''.
+
For that you need a '''Terminal''' and you need  a '''Text''' '''Editor'''.
  
  
Line 87: Line 87:
  
  
Open ''curly bracket''.
+
then Open ''curly bracket''.
  
Press '''Enter '''and close ''curly bracket''.
+
  '''Enter '''and close ''curly bracket''.
  
  
Line 96: Line 96:
 
|-
 
|-
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Highlight {}
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Highlight {}
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| The code inside this block will belong to the class '''HelloWorld'''
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| The code between  this two curly brackets  will belong to the class '''HelloWorld'''
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Click on the Save icon.
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Click on the Save icon.
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Now save the file by clicking on the '''Save '''icon.
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Now save the file by clicking on the '''Save '''icon at the top
  
 
It is a good practice to save the file frequently.  
 
It is a good practice to save the file frequently.  
Line 106: Line 106:
 
|-
 
|-
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Save as Dialog box
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Save as Dialog box
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| '''Save As Dialog box '''appears.
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| so'''Save As Dialog box '''appears.
  
Browse the location where you want to save the file.
+
Browse the location where you want to save your file.
  
 
|-
 
|-
Line 114: Line 114:
  
 
Create folder Demo.
 
Create folder Demo.
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Here, in the home directory we will create a folder.
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Here, in the home directory i will create a folder.
  
Let us name it as '''Demo'''
+
Let us name it   '''Demo''' and press enter
  
 
Then inside this folder we will save the file.
 
Then inside this folder we will save the file.
Line 131: Line 131:
 
In java, the name of the class and the file name should be same.
 
In java, the name of the class and the file name should be same.
  
Recall that the class we have created is HelloWorld.
+
Recall that we   created   class  HelloWorld.
  
  
So we will save this file also as HelloWorld dot java
+
So we will save the file   as HelloWorld dot java
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Highlight .java
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Highlight .java
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| '''Dot '''java extension is given to a java file.
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| '''Dot '''java is the file extension is given to a java file.
  
 
|-
 
|-
Line 168: Line 168:
 
So type:
 
So type:
  
'''''public static void main '''within'' ''parentheses '''String''' '''arg''' Square brackets''  
+
'''''public static void main '''   ''parentheses'' inside  ''parentheses'' '''String''' '''arg''' Square brackets''  
  
  
'''Main''' method marks the starting point of the program.
+
'''Main''' functions marks the starting point of the program.
  
  
We will describe the words public, static, void and String arg in a future tutorial.
+
We will describe public, static, void and String arg in a future tutorial.
  
  
Then again, open curly bracket.
+
Then once again, open curly bracket.
  
 
Press '''Enter '''and close curly bracket.
 
Press '''Enter '''and close curly bracket.
Line 186: Line 186:
 
|-
 
|-
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Highlight {}
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Highlight {}
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| The code inside these curly brackets will belong to the main method.
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| The code between these two curly brackets will belong to the main method.
  
 
|-
 
|-
Line 207: Line 207:
  
  
So type '''''System '''dot''' out '''dot''' println''''' parentheses semi-colon
+
So inside main method  type'''''System '''dot''' out '''dot''' println''''' parentheses semi-colon
  
  
This statement is used to print a line.
+
This is the statement  used to print a line.
  
  
In Java, semi-colon is used to terminate a line.
+
  semi-colon is used to terminate a line.
  
  
Line 219: Line 219:
  
  
Within '''''parentheses in double quotes type My first java program exclamation mark'''.''
+
So Within '''''parentheses in double quotes type My first java program exclamation mark'''.''
  
 
|-
 
|-
Line 227: Line 227:
 
|-
 
|-
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Switch to the '''Terminal'''
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Switch to the '''Terminal'''
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Let us go back to the '''Terminal'''.
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Let us go   to the '''Terminal'''.
  
 
|-
 
|-
Line 237: Line 237:
  
 
ls
 
ls
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Make sure that you are in the directory where your '''HelloWorld.java''' file is present.
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Make sure that you are in the directory where you save your '''HelloWorld.java'''  
  
  
Line 243: Line 243:
  
  
We can see that Demo is a subdirectory.
+
  
  
Line 249: Line 249:
  
  
We see the HelloWorld.java file present in the Demo folder.
+
We see   HelloWorld.java file present in the Demo folder.
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| javac HelloWorld.java  
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| javac HelloWorld.java  
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Now, run the command '''''javac '''Space''' HelloWorld '''dot''' java'''''.
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Lets compile this file so type  '''javac '''Space''' HelloWorld '''dot''' java''''' and hit enter
  
  
This will compile the file that we have created.  
+
This   compile the file that we have created.  
  
 
|-
 
|-
Line 262: Line 262:
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Alright now the file is compiled as we see no error.
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Alright now the file is compiled as we see no error.
  
We can see''' '''the''' HelloWorld.class''' file created.
+
We can see that  '''HelloWorld.class''' file created.
  
 
This file can run anywhere.
 
This file can run anywhere.
Line 272: Line 272:
 
Hence, java is rightly described as “write once, run anywhere.”
 
Hence, java is rightly described as “write once, run anywhere.”
  
|-
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Switch back to the '''Terminal'''
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Go back to the '''Terminal'''.
+
  
 
|-
 
|-
Line 280: Line 278:
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| After successful compilation, run the program using the command,  
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| After successful compilation, run the program using the command,  
  
'''''java '''''(no c) space '''''HelloWorld '''''(no dot java) and hit '''Enter'''.
+
'''''java '''''(no c) space '''''HelloWorld '''''(no dot java extension) and hit '''Enter'''.
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Output
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Output
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| We see the output '''My first java program!'''
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| You seewill get  the output '''My first java program!'''
  
 
So we have written our first java program.
 
So we have written our first java program.
  
|-
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Go back to text editor
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Let us go back to the '''Text Editor'''.
+
 
+
 
|-
 
|-
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Delete ;
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Delete ;
Line 306: Line 301:
 
|-
 
|-
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| '''javac''' '''HelloWorld.java'''  
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| '''javac''' '''HelloWorld.java'''  
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Run the command '''''javac '''Space''' HelloWorld '''dot''' java'''''.  
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Run the command '''''javac ''' ''' HelloWorld '''dot''' java'''''.  
  
 
|-
 
|-
Line 325: Line 320:
 
|-
 
|-
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Switch back to the '''Text Editor'''
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Switch back to the '''Text Editor'''
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Let us go back to the '''Text Editor'''.
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Let us go back to the ''' Editor'''.
  
 
In Java, all statements are terminated with semicolons.  
 
In Java, all statements are terminated with semicolons.  
Line 331: Line 326:
 
|-
 
|-
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type ;
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Type ;
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| So go to the fifth line.
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| So go to the fifth line and add a semicolon.
  
At the end of the statement add a semi-colon.
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Click on '''Save'''
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Click on '''Save'''
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Click on the '''Save '''icon.
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Click on the '''Save '''icon. It is necessary tosave the file before compiling
  
 
|-
 
|-
Line 345: Line 340:
 
|-
 
|-
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| javac HelloWorld.java  
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| javac HelloWorld.java  
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Run the command '''''javac '''Space''' HelloWorld '''dot''' java'''''.  
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| Compile the file using  '''''javac '''Space''' HelloWorld '''dot''' java'''''.  
  
 
|-
 
|-
Line 353: Line 348:
 
Now, run the program using the command  
 
Now, run the program using the command  
  
'''''java''''' space '''''HelloWorld''''' and hit '''Enter'''.
+
'''''java''''' '''''HelloWorld''''' and .
  
  
Line 379: Line 374:
 
* Example: class HelloWorld, class ChessGame.
 
* Example: class HelloWorld, class ChessGame.
  
So, H of hello, W of World are in uppercase.
+
So, H of hello and  W of World are in uppercase.
  
  
Line 391: Line 386:
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| * The method name should be in mixed case.
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| * The method name should be in mixed case.
 
* Which means that the first word should begin with a lower case.  
 
* Which means that the first word should begin with a lower case.  
* And all new words should begin with an upper case.
+
* And all new words followed should begin with an upper case.
 
* Also the method name should be a verb.
 
* Also the method name should be a verb.
  
Line 398: Line 393:
 
|-
 
|-
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Slide 6  
 
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:none;padding:0.097cm;"| Slide 6  
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| * Example: showString(), main(), goToHelp().The variable name should not begin with digits.<br/> Here '''s''' of show is in lowercase and '''S''' of string is in uppercase.
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| * Example: showString(), main(), goToHelp() Here '''s''' of show is in lowercase and '''S''' of string is in uppercase .The variable name should not begin with digits.<br/>.
 
* We cannot use keywords for our class, method or variable name.
 
* We cannot use keywords for our class, method or variable name.
* For example: We cannot use keywords like public, private, void, static and many more.  
+
* For example: cannot use keywords like public, private, void, static and many more.  
  
  
Line 416: Line 411:
  
 
Assignment
 
Assignment
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| For self assessment write a simple java program which prints '''Java file name and class name should be same'''.
+
| style="border-top:none;border-bottom:0.035cm solid #000000;border-left:0.035cm solid #000000;border-right:0.035cm solid #000000;padding:0.097cm;"| For self assessment write a simple java program to prints '''Java file name and class name should be same'''.
  
  

Latest revision as of 16:32, 22 January 2014

Title of script: Getting started with java: first program.

Author: Prathamesh Salunke

Keywords: video tutorial, Hello World, first program


Visual Cue
Narration
Slide 1

Opening slide

Welcome to the Spoken Tutorial on getting started with the First java program.
Slide 2

Learning Objectives

In this tutorial we will learn

* To create a simple java program.

* To compile the program.

* To run the program and

* About the naming conventions followed.

Slide 3

System Requirements

Here we are using
  • Ubuntu version 11.10 and
  • Java Development Environment jdk 1.6


Slide 4

Prerequisite

To follow this tutorial JDK 1.6 must be installed on your system.

If not, for relevant tutorial please visit our website which is as shown.

Switch to Terminal and then to the Text Editor Let us now write our first java program.

For that you need a Terminal and you need a Text Editor.



Point to the gedit I am using gedit as my Text Editor
type:

class HelloWorld


Highlight HelloWorld


{

}

[ENTER]


In the text editor, we will first create the class HelloWorld.

So type class HelloWorld

HelloWorld is the name of the class.


then Open curly bracket.
 Enter and close curly bracket.



Highlight {} The code between this two curly brackets will belong to the class HelloWorld
Click on the Save icon. Now save the file by clicking on the Save icon at the top

It is a good practice to save the file frequently.

Save as Dialog box soSave As Dialog box appears.

Browse the location where you want to save your file.

Select Home directory

Create folder Demo.

Here, in the home directory i will create a folder.

Let us name it Demo and press enter

Then inside this folder we will save the file.

Type:

HelloWorld.java


type HelloWorld dot java

In the Name text-box, type the name of the class.

In java, the name of the class and the file name should be same.

Recall that we created class HelloWorld.


So we will save the file as HelloWorld dot java

Highlight .java Dot java is the file extension is given to a java file.
Click on Save Then click on Save button.

So the file is now saved.

class HelloWorld

{

public static void main()

{

}

}

Highlight Main


main(String arg[])

Inside the class, we write the main method.


So type:

public static void main parentheses inside parentheses String arg Square brackets


Main functions marks the starting point of the program.


We will describe public, static, void and String arg in a future tutorial.


Then once again, open curly bracket.

Press Enter and close curly bracket.



Highlight {} The code between these two curly brackets will belong to the main method.
Type:

public static void main(String arg[])

{

System.out.println();

}


Highlight semicolon


System.out.println(“My first java program!”);

We will now write a code to display a line on the Terminal.


So inside main method typeSystem dot out dot println parentheses semi-colon


This is the statement used to print a line.


 semi-colon is used to terminate a line.


Now let us tell Java what to print.


So Within parentheses in double quotes type My first java program exclamation mark.
Click on Save icon Let us Save the file by clicking on Save icon.
Switch to the Terminal Let us go to the Terminal.
ls


cd Demo


ls

Make sure that you are in the directory where you save your HelloWorld.java


Remember that I am in my home directory.



So type cd Space Demo and hit Enter


We see HelloWorld.java file present in the Demo folder.

javac HelloWorld.java Lets compile this file so type javac Space HelloWorld dot java and hit enter


This compile the file that we have created.

ls Alright now the file is compiled as we see no error.

We can see that HelloWorld.class file created.

This file can run anywhere.

That is, on any Operating System.

We do not need java compiler as well.

Hence, java is rightly described as “write once, run anywhere.”


Java HelloWorld After successful compilation, run the program using the command,

java (no c) space HelloWorld (no dot java extension) and hit Enter.

Output You seewill get the output My first java program!

So we have written our first java program.


Delete ; Now, remove the semi-colon which is at the end of the statement.
Click on Save Click on the Save icon.
Go to Terminal Let us go back to the Terminal.
javac HelloWorld.java Run the command javac HelloWorld dot java.
HelloWorld.java:5: ';' expected

System.out.println("My first java program")

^ 

1 error

The compiler gives an error.

It says, a semi colon is expected on the fifth line.


The up arrow points to the error statement.

Switch back to the Text Editor Let us go back to the Editor.

In Java, all statements are terminated with semicolons.

Type ; So go to the fifth line and add a semicolon.


Click on Save Click on the Save icon. It is necessary tosave the file before compiling
Switch back to the Terminal Let us go back to the Terminal.
javac HelloWorld.java Compile the file using javac Space HelloWorld dot java.
java HelloWorld The file is successfully compiled as we see no errors.

Now, run the program using the command

java HelloWorld and .



Output We see the output My first java program!

This is how you can handle errors in java.

As the series progresses, we will learn more about the errors.

Switch to Slides

Slide 4


We now see what are the naming conventions in java.
  • The class name should be in CamelCase.
  • Which means each new word begins with an upper case.
  • Example: class HelloWorld, class ChessGame.

So, H of hello and W of World are in uppercase.


Similarly C and G of Chess and Game respectively are in uppercase.

Slide 5


* The method name should be in mixed case.
  • Which means that the first word should begin with a lower case.
  • And all new words followed should begin with an upper case.
  • Also the method name should be a verb.


Slide 6 * Example: showString(), main(), goToHelp() Here s of show is in lowercase and S of string is in uppercase .The variable name should not begin with digits.
.
  • We cannot use keywords for our class, method or variable name.
  • For example: cannot use keywords like public, private, void, static and many more.


Slide 7

Summary

So in this tutorial, we have learnt to write, compile and run a simple java program.

We also saw the naming conventions followed in java.

Slide 8

Assignment

For self assessment write a simple java program to prints Java file name and class name should be same.


To know more about the Spoken Tutorial Project

Slide 9

About Slide

  • If you do not have good bandwidth, you can download and watch it


Slide 10

About Slide


The Spoken Tutorial Project Team
  • Conducts workshops using spoken tutorials
  • Gives certificates for those who pass an online test
  • For more details, please write to contact@spoken-tutorial.org


Slide 11

Acknowledgment

Spoken Tutorial Project is a part of the Talk to a Teacher project
  • It is supported by the National Mission on Education through ICT, MHRD, Government of India
  • More information on this Mission is available at


Slide 12

Contributor Slide

We have come to the end of this tutorial.

Thanks for joining.

This is Prathamesh Salunke signing off.

Jai Hind.

Contributors and Content Editors

Ashwini, Chandrika, Sneha