Difference between revisions of "Java/C2/First-Java-Program/English-timed"
From Script | Spoken-Tutorial
PoojaMoolya (Talk | contribs) |
|||
(28 intermediate revisions by 9 users not shown) | |||
Line 1: | Line 1: | ||
− | |||
{| border=1 | {| border=1 | ||
− | || '''Time | + | || '''Time''' |
|| '''Narration''' | || '''Narration''' | ||
Line 10: | Line 9: | ||
|- | |- | ||
| 00:09 | | 00:09 | ||
− | | | + | | In this tutorial, we will learn: |
|- | |- | ||
| 00:11 | | 00:11 | ||
− | | To create a simple | + | | To create a simple Java program |
|- | |- | ||
| 00:14 | | 00:14 | ||
− | | To compile the program | + | | To compile the program |
|- | |- | ||
| 00:16 | | 00:16 | ||
− | | To run the program | + | | To run the program and |
|- | |- | ||
| 00:19 | | 00:19 | ||
− | | About the naming conventions followed in | + | | About the naming conventions followed in Java. |
|- | |- | ||
− | | 00: | + | | 00:23 |
− | | Here we are using | + | | Here we are using '''Ubuntu version 11.10''' and '''jdk 1.6'''. |
− | + | ||
− | + | ||
|- | |- | ||
| 00:32 | | 00:32 | ||
− | | To follow this tutorial '''JDK 1.6 '''must be installed on your system. | + | | To follow this tutorial, '''JDK 1.6 '''must be installed on your system. |
|- | |- | ||
| 00:39 | | 00:39 | ||
− | |If not, for relevant tutorial please visit our website which is as shown. | + | |If not, for relevant tutorial, please visit our website which is as shown. |
|- | |- | ||
| 00:46 | | 00:46 | ||
− | |Alright now | + | |Alright, now let us write our first Java program. |
|- | |- | ||
| 00:51 | | 00:51 | ||
− | |For that you need a '''Terminal''' and you need a '''Text | + | |For that, you need a '''Terminal''' and you need a '''Text Editor'''. |
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| 00:56 | | 00:56 | ||
− | | I am using '''gedit''' as my '''Text Editor''' | + | | I am using '''gedit''' as my '''Text Editor'''. |
|- | |- | ||
|01:01 | |01:01 | ||
− | | In the '''text editor''' | + | | In the '''text editor''', we will first create the '''class''' '''HelloWorld'''. |
|- | |- | ||
| 01:06 | | 01:06 | ||
− | |So type | + | |So, type: class '''HelloWorld'''. "HelloWorld" is the name of the '''class'''. |
− | + | ||
|- | |- | ||
| 01:17 | | 01:17 | ||
− | | And | + | | And, open curly bracket. '''Enter''' and close curly bracket. |
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| 01:24 | | 01:24 | ||
− | | The code between | + | | The code between these two curly brackets will belong to the '''class''' 'HelloWorld'. |
|- | |- | ||
| 01:33 | | 01:33 | ||
− | | Now save the file by clicking on '''Save '''icon at the top | + | | Now save the file by clicking on '''Save''' icon at the top. |
|- | |- | ||
Line 87: | Line 77: | ||
|- | |- | ||
| 01:43 | | 01:43 | ||
− | | so'''Save As | + | | so '''Save As''' Dialog box appears. |
|- | |- | ||
Line 95: | Line 85: | ||
|- | |- | ||
| 01:51 | | 01:51 | ||
− | | Here, in the home directory | + | | Here, in the '''home''' directory, I will create a folder. |
|- | |- | ||
| 01:57 | | 01:57 | ||
− | |Let us name it | + | |Let us name it '''Demo''' and press '''Enter'''. |
+ | |||
|- | |- | ||
| 02:02 | | 02:02 | ||
− | |Then inside this folder we will save the file. | + | |Then, inside this folder we will save the file. |
|- | |- | ||
| 02:08 | | 02:08 | ||
− | | In the '''Name''' text-box, type the name of the class. | + | | In the '''Name''' text-box, type the name of the '''class'''. |
|- | |- | ||
| 02:13 | | 02:13 | ||
− | |In | + | |In Java, the name of the class and the file name should be same. |
|- | |- | ||
| 02:20 | | 02:20 | ||
− | |Recall that we | + | |Recall that we created '''class HelloWorld'''. |
− | + | ||
|- | |- | ||
| 02:25 | | 02:25 | ||
− | |So we will save the file | + | |So, we will '''save''' the file as ''' HelloWorld dot java'''. |
|- | |- | ||
| 02:33 | | 02:33 | ||
− | | '''Dot '''java is the file extension given to | + | | '''Dot Java''' (.java) is the file extension given to the Java file. |
|- | |- | ||
|02:39 | |02:39 | ||
− | | Then click on '''Save '''button. So the file is now saved. | + | | Then click on '''Save''' button. So the file is now saved. |
|- | |- | ||
| 02:47 | | 02:47 | ||
− | | Inside the class, we write the '''main''' | + | | Inside the '''class''', we write the '''main method'''. |
− | + | ||
|- | |- | ||
| 02:53 | | 02:53 | ||
− | |So type: | + | |So, type: '''public static void main''' parentheses inside parentheses '''String''' '''arg''' square brackets. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| 03:10 | | 03:10 | ||
− | |''' | + | |'''main''' function marks the starting point of the program. |
− | + | ||
|- | |- | ||
| 03:15 | | 03:15 | ||
− | |We will describe | + | |We will describe '''public, static, void''' and '''String '''in a future tutorial. |
− | + | ||
|- | |- | ||
| 03:23 | | 03:23 | ||
− | |Then once again, open curly bracket | + | |Then once again, open curly bracket, |
|- | |- | ||
| 03:27 | | 03:27 | ||
− | | | + | |press '''Enter '''and close curly bracket. |
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| 03:32 | | 03:32 | ||
− | | The code between these two curly brackets will belong to the main method. | + | | The code between these two curly brackets will belong to the '''main method'''. |
|- | |- | ||
| 03:41 | | 03:41 | ||
| We will now write a code to display a line on the '''Terminal'''. | | We will now write a code to display a line on the '''Terminal'''. | ||
− | |||
|- | |- | ||
| 03:46 | | 03:46 | ||
− | |So | + | |So, inside '''main''' '''method''', type: '''System''' dot '''out''' dot '''println''' parentheses semicolon. |
− | + | ||
|- | |- | ||
| 03:59 | | 03:59 | ||
− | |This is the statement | + | |This is the statement used to print a line. |
+ | |- | ||
+ | | 04:05 | ||
+ | |Semicolon is used to terminate a line. | ||
|- | |- | ||
| 04:10 | | 04:10 | ||
− | |Now let us tell Java, | + | |Now let us tell Java, what to print. |
− | + | ||
|- | |- | ||
| 04:13 | | 04:13 | ||
− | | So | + | | So, within parentheses in double quotes, type: '''My first Java program''' exclamation mark. |
|- | |- | ||
| 04:30 | | 04:30 | ||
− | | Let us | + | | Let us save the file by clicking on '''Save''' icon. |
|- | |- | ||
| 04:36 | | 04:36 | ||
− | | Let's go | + | | Let's go to the '''Terminal'''. |
|- | |- | ||
| 04:38 | | 04:38 | ||
− | | | + | |Make sure that you are in the directory where you saved your 'HelloWorld.java' |
− | + | ||
|- | |- | ||
| 04:46 | | 04:46 | ||
− | |Remember that I am in my home directory. | + | |Remember that I am in my '''home''' directory. |
− | + | |- | |
− | + | ||
| 04:50 | | 04:50 | ||
− | |So | + | |So, type: '''cd''' Space '''Demo ''' and hit '''Enter'''. |
+ | |- | ||
+ | | 04:56 | ||
+ | |'''ls''', press '''Enter'''. | ||
|- | |- | ||
| 04:59 | | 04:59 | ||
− | |We see | + | |We see 'HelloWorld.java' file present in the 'Demo' folder. |
|- | |- | ||
| 05:06 | | 05:06 | ||
− | | | + | | Let's compile this file. So, type: '''javac''' Space ''' HelloWorld''' dot '''java''' and hit '''Enter'''. |
− | + | ||
|- | |- | ||
| 05:21 | | 05:21 | ||
− | |This | + | |This compiles the file that we have created. |
|- | |- | ||
| 05:25 | | 05:25 | ||
− | | Alright now the file is compiled as we see no error. | + | | Alright, now the file is compiled as we see no error. |
|- | |- | ||
Line 238: | Line 217: | ||
|- | |- | ||
| 05:36 | | 05:36 | ||
− | |This file can run anywhere. | + | |This file can '''run''' anywhere. |
|- | |- | ||
| 05:38 | | 05:38 | ||
− | |That is, on any '''Operating System. ''' | + | |That is, on any '''Operating System.''' |
|- | |- | ||
Line 251: | Line 230: | ||
| 05:45 | | 05:45 | ||
|Hence, java is rightly described as “write once, run anywhere.” | |Hence, java is rightly described as “write once, run anywhere.” | ||
− | |||
− | |||
|- | |- | ||
| 05:51 | | 05:51 | ||
− | | So | + | | So, after successful compilation, '''run''' the program using the command, |
|- | |- | ||
| 05:56 | | 05:56 | ||
− | | | + | |'''java'''(This time no c) space '''HelloWorld'''(and no dot java extension) and hit '''Enter'''. |
|- | |- | ||
| 06:07 | | 06:07 | ||
− | | You will get | + | | You will get the output '''My first java program!''' |
|- | |- | ||
| 06:13 | | 06:13 | ||
− | |So we have written our first java program.Let us go back to '''editor''' | + | |So, we have written our first java program. Let us go back to the '''editor'''. |
− | |||
|- | |- | ||
| 06:22 | | 06:22 | ||
− | | Now, remove the | + | | Now, remove the semicolon which is at the end of the statement. |
|- | |- | ||
| 06:27 | | 06:27 | ||
− | | | + | |Click on '''Save''' icon. |
|- | |- | ||
| 06:29 | | 06:29 | ||
− | | | + | | Let us go back to the '''Terminal'''. |
|- | |- | ||
| 06:33 | | 06:33 | ||
− | | Run the command '''''javac ''' ''' HelloWorld '''dot''' java | + | | Run the '''command''' '''javac''' '''HelloWorld''' dot '''java'''. |
|- | |- | ||
Line 293: | Line 269: | ||
|- | |- | ||
| 06:44 | | 06:44 | ||
− | |It says, a | + | |It says, a semicolon (;) is expected on the fifth line. |
− | + | ||
|- | |- | ||
| 06:52 | | 06:52 | ||
− | |The up arrow points to the error statement. | + | |The up-arrow points to the error statement. |
|- | |- | ||
| 06:57 | | 06:57 | ||
− | | Let us go back to the ''' | + | | Let us go back to the '''Editor'''. |
|- | |- | ||
Line 309: | Line 284: | ||
|- | |- | ||
− | | | + | |07:06 |
− | | So go to the fifth line and add a semicolon. | + | | So, go to the fifth line and add a semicolon. |
− | + | ||
− | + | ||
|- | |- | ||
| 07:13 | | 07:13 | ||
− | | Click on the '''Save '''icon. It is necessary to save the file before compiling | + | | Click on the '''Save '''icon. It is necessary to save the file before compiling. |
|- | |- | ||
Line 324: | Line 297: | ||
|- | |- | ||
| 07:25 | | 07:25 | ||
− | |Compile the file using | + | |Compile the file using '''javac HelloWorld''' dot '''java'''. |
|- | |- | ||
| 07:32 | | 07:32 | ||
− | | | + | |The file is successfully compiled as we see no errors. |
|- | |- | ||
| 07:36 | | 07:36 | ||
− | |Now, run the program using the command | + | |Now, run the program using the command '''java''' '''HelloWorld''' and |
− | + | ||
|- | |- | ||
| 07:45 | | 07:45 | ||
− | | | + | | we see the output '''My first Java program!''' |
|- | |- | ||
| 07:49 | | 07:49 | ||
− | |This is how you handle errors in java. | + | |This is how you handle '''errors''' in java. |
|- | |- | ||
Line 353: | Line 325: | ||
|- | |- | ||
| 08:06 | | 08:06 | ||
− | | | + | | The '''class''' name should be in CamelCase |
+ | |||
|- | |- | ||
| 08:10 | | 08:10 | ||
− | | | + | | which means each new word begins with an ''upper case''. |
+ | |||
|- | |- | ||
| 08:14 | | 08:14 | ||
− | | | + | | Example: class HelloWorld, class ChessGame. |
|- | |- | ||
| 08:19 | | 08:19 | ||
− | |So, | + | |So, 'H' of 'Hello' and 'W' of 'World' are in uppercase. |
− | + | ||
|- | |- | ||
| 08:25 | | 08:25 | ||
− | |Similarly C and G of | + | |Similarly, 'C' and 'G' of 'ChessGame' respectively are in uppercase. |
|- | |- | ||
| 08:31 | | 08:31 | ||
− | | The method name should be the mixed case. | + | | The '''method''' name should be the mixed case. |
+ | |||
|- | |- | ||
| 08:35 | | 08:35 | ||
− | | | + | | which means that the first word should begin with a lowercase. |
+ | |||
|- | |- | ||
| 08:39 | | 08:39 | ||
− | | | + | |and all new words followed should begin with an uppercase. |
+ | |||
|- | |- | ||
| 08:44 | | 08:44 | ||
− | |Also the method name should be a verb. | + | |Also the '''method''' name should be a verb. |
− | + | ||
− | + | ||
|- | |- | ||
| 08:48 | | 08:48 | ||
− | | For | + | | For Example: showString(), main(), goToHelp(). Here 's' of show is in lowercase while 'S' of string is in uppercase. |
+ | |||
+ | |- | ||
+ | |09:02 | ||
+ | |The variable name should not begin with digits. | ||
+ | |||
|- | |- | ||
| 09:06 | | 09:06 | ||
− | | We cannot use keywords for our class, method or variable name. | + | | We cannot use keywords for our '''class, method''' or '''variable name'''. |
+ | |||
|- | |- | ||
| 09:13 | | 09:13 | ||
− | |For example: cannot use keywords like''' public, private, void, static | + | |For example: cannot use keywords like '''public, private, void, static''' and many more. |
− | + | ||
− | + | ||
|- | |- | ||
| 09:22 | | 09:22 | ||
− | | So in this tutorial, we have learnt to write, compile and run a simple java program. | + | | So in this tutorial, we have learnt to write, compile and '''run''' a simple java program. |
|- | |- | ||
Line 407: | Line 385: | ||
|- | |- | ||
|09:35 | |09:35 | ||
− | + | |For self assessment, write a simple java program to print "Java file name and class name should be same". | |
− | + | ||
|- | |- | ||
| 09:47 | | 09:47 | ||
− | |To know more about the Spoken Tutorial Project | + | |To know more about the Spoken Tutorial Project, |
|- | |- | ||
| 09:50 | | 09:50 | ||
− | | | + | | watch the video available at [http://spoken-tutorial.org/What_is_a_Spoken_Tutorial] |
+ | |||
|- | |- | ||
| 09:58 | | 09:58 | ||
− | | It | + | | It summarizes the Spoken Tutorial project. |
|- | |- | ||
| 10:02 | | 10:02 | ||
− | | If you do not have good bandwidth, you can download and watch it | + | | If you do not have good bandwidth, you can download and watch it. |
|- | |- | ||
| 10:08 | | 10:08 | ||
− | | The Spoken Tutorial Project | + | | The Spoken Tutorial Project team: |
|- | |- | ||
| 10:10 | | 10:10 | ||
− | | Conducts workshops using spoken tutorials | + | | Conducts workshops using spoken tutorials. |
|- | |- | ||
| 10:13 | | 10:13 | ||
− | |Gives certificates | + | |Gives certificates to those who pass an online test. |
|- | |- | ||
| 10:17 | | 10:17 | ||
| For more details, please write to contact@spoken-tutorial.org | | For more details, please write to contact@spoken-tutorial.org | ||
− | |||
− | |||
|- | |- | ||
| 10:25 | | 10:25 | ||
− | | Spoken Tutorial | + | | Spoken Tutorial project is a part of the Talk to a Teacher project. |
|- | |- | ||
| 10:30 | | 10:30 | ||
− | |It is supported by the National Mission on Education through ICT, MHRD, Government of India | + | |It is supported by the National Mission on Education through ICT, MHRD, Government of India. |
|- | |- | ||
| 10:38 | | 10:38 | ||
− | | More information on this | + | | More information on this mission is available at: [http://spoken-tutorial.org/NMEICT-Intro]. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
Line 469: | Line 441: | ||
|- | |- | ||
| 10:53 | | 10:53 | ||
− | |This is Prathamesh Salunke signing off. Jai Hind. | + | |This is Prathamesh Salunke, signing off. Jai Hind. |
|} | |} |
Latest revision as of 11:25, 19 April 2017
Time | Narration |
00:02 | Welcome to the Spoken Tutorial on getting started with the First java program. |
00:09 | In this tutorial, we will learn: |
00:11 | To create a simple Java program |
00:14 | To compile the program |
00:16 | To run the program and |
00:19 | About the naming conventions followed in Java. |
00:23 | Here we are using Ubuntu version 11.10 and jdk 1.6. |
00:32 | To follow this tutorial, JDK 1.6 must be installed on your system. |
00:39 | If not, for relevant tutorial, please visit our website which is as shown. |
00:46 | Alright, now let us write our first Java program. |
00:51 | For that, you need a Terminal and you need a Text Editor. |
00:56 | I am using gedit as my Text Editor. |
01:01 | In the text editor, we will first create the class HelloWorld. |
01:06 | So, type: class HelloWorld. "HelloWorld" is the name of the class. |
01:17 | And, open curly bracket. Enter and close curly bracket. |
01:24 | The code between these two curly brackets will belong to the class 'HelloWorld'. |
01:33 | Now save the file by clicking on Save icon at the top. |
01:37 | It is a good practice to save the file frequently. |
01:43 | so Save As Dialog box appears. |
01:46 | Browse the location where you want to save your file. |
01:51 | Here, in the home directory, I will create a folder. |
01:57 | Let us name it Demo and press Enter. |
02:02 | Then, inside this folder we will save the file. |
02:08 | In the Name text-box, type the name of the class. |
02:13 | In Java, the name of the class and the file name should be same. |
02:20 | Recall that we created class HelloWorld. |
02:25 | So, we will save the file as HelloWorld dot java. |
02:33 | Dot Java (.java) is the file extension given to the Java file. |
02:39 | Then click on Save button. So the file is now saved. |
02:47 | Inside the class, we write the main method. |
02:53 | So, type: public static void main parentheses inside parentheses String arg square brackets. |
03:10 | main function marks the starting point of the program. |
03:15 | We will describe public, static, void and String in a future tutorial. |
03:23 | Then once again, open curly bracket, |
03:27 | press Enter and close curly bracket. |
03:32 | The code between these two curly brackets will belong to the main method. |
03:41 | We will now write a code to display a line on the Terminal. |
03:46 | So, inside main method, type: System dot out dot println parentheses semicolon. |
03:59 | This is the statement used to print a line. |
04:05 | Semicolon is used to terminate a line. |
04:10 | Now let us tell Java, what to print. |
04:13 | So, within parentheses in double quotes, type: My first Java program exclamation mark. |
04:30 | Let us save the file by clicking on Save icon. |
04:36 | Let's go to the Terminal. |
04:38 | Make sure that you are in the directory where you saved your 'HelloWorld.java' |
04:46 | Remember that I am in my home directory. |
04:50 | So, type: cd Space Demo and hit Enter. |
04:56 | ls, press Enter. |
04:59 | We see 'HelloWorld.java' file present in the 'Demo' folder. |
05:06 | Let's compile this file. So, type: javac Space HelloWorld dot java and hit Enter. |
05:21 | This compiles the file that we have created. |
05:25 | Alright, now the file is compiled as we see no error. |
05:30 | We can see HelloWorld.class file created. |
05:36 | This file can run anywhere. |
05:38 | That is, on any Operating System. |
05:41 | We do not need java compiler as well. |
05:45 | Hence, java is rightly described as “write once, run anywhere.” |
05:51 | So, after successful compilation, run the program using the command, |
05:56 | java(This time no c) space HelloWorld(and no dot java extension) and hit Enter. |
06:07 | You will get the output My first java program! |
06:13 | So, we have written our first java program. Let us go back to the editor. |
06:22 | Now, remove the semicolon which is at the end of the statement. |
06:27 | Click on Save icon. |
06:29 | Let us go back to the Terminal. |
06:33 | Run the command javac HelloWorld dot java. |
06:41 | The compiler gives an error. |
06:44 | It says, a semicolon (;) is expected on the fifth line. |
06:52 | The up-arrow points to the error statement. |
06:57 | Let us go back to the Editor. |
07:01 | In Java, all statements are terminated with semicolons. |
07:06 | So, go to the fifth line and add a semicolon. |
07:13 | Click on the Save icon. It is necessary to save the file before compiling. |
07:22 | Let us go back to the Terminal. |
07:25 | Compile the file using javac HelloWorld dot java. |
07:32 | The file is successfully compiled as we see no errors. |
07:36 | Now, run the program using the command java HelloWorld and |
07:45 | we see the output My first Java program! |
07:49 | This is how you handle errors in java. |
07:54 | As the series progresses, we will learn more about the errors. |
08:02 | We now see what are the naming conventions in java. |
08:06 | The class name should be in CamelCase |
08:10 | which means each new word begins with an upper case. |
08:14 | Example: class HelloWorld, class ChessGame. |
08:19 | So, 'H' of 'Hello' and 'W' of 'World' are in uppercase. |
08:25 | Similarly, 'C' and 'G' of 'ChessGame' respectively are in uppercase. |
08:31 | The method name should be the mixed case. |
08:35 | which means that the first word should begin with a lowercase. |
08:39 | and all new words followed should begin with an uppercase. |
08:44 | Also the method name should be a verb. |
08:48 | For Example: showString(), main(), goToHelp(). Here 's' of show is in lowercase while 'S' of string is in uppercase. |
09:02 | The variable name should not begin with digits. |
09:06 | We cannot use keywords for our class, method or variable name. |
09:13 | For example: cannot use keywords like public, private, void, static and many more. |
09:22 | So in this tutorial, we have learnt to write, compile and run a simple java program. |
09:30 | We also saw the naming conventions followed in java. |
09:35 | For self assessment, write a simple java program to print "Java file name and class name should be same". |
09:47 | To know more about the Spoken Tutorial Project, |
09:50 | watch the video available at [1] |
09:58 | It summarizes the Spoken Tutorial project. |
10:02 | If you do not have good bandwidth, you can download and watch it. |
10:08 | The Spoken Tutorial Project team: |
10:10 | Conducts workshops using spoken tutorials. |
10:13 | Gives certificates to those who pass an online test. |
10:17 | For more details, please write to contact@spoken-tutorial.org |
10:25 | Spoken Tutorial project is a part of the Talk to a Teacher project. |
10:30 | It is supported by the National Mission on Education through ICT, MHRD, Government of India. |
10:38 | More information on this mission is available at: [2]. |
10:49 | We have come to the end of this tutorial. |
10:51 | Thanks for joining. |
10:53 | This is Prathamesh Salunke, signing off. Jai Hind. |
Contributors and Content Editors
Arya Ratish, Ashwini, Gaurav, Kavita salve, PoojaMoolya, Pratik kamble, Priyacst, Sandhya.np14, Sneha, Vasudeva ahitanal