Java/C2/Strings/English-timed
From Script | Spoken-Tutorial
Revision as of 20:19, 20 March 2015 by Sandhya.np14 (Talk | contribs)
Time | Narration |
00:01 | Welcome to the spoken tutorial on Strings in Java. |
00:05 | In this tutorial, you will learn how to: |
00:08 | create strings, add strings and perform basic string operations like converting to lower case and upper case. |
00:18 | For this tutorial, we are using
Ubuntu 11.10, JDK 1.6 and Eclipse 3.7 |
00:26 | To follow this tutorial, you must have the knowledge of data types in Java. |
00:32 | If not, for relevant tutorials, please visit our website as shown. |
00:40 | String in Java, is a sequence of characters. |
00:44 | Before starting with Strings, we will first see the character data type. |
00:50 | Let us now switch to eclipse. |
00:55 | we have the 'Eclipse IDE' and the skeleton required for the rest of the code. |
01:00 | We have created a class StringDemo and added the main method. |
01:07 | Inside the main method, type: char star equal to in single quotes asterisks. |
01:19 | This statement creates a variable with name star and of the type char. |
01:25 | It can store exactly one character. |
01:28 | Let us print a word using a few characters. |
01:33 | Remove the char line and type: |
01:36 | char c1 equal to in single quotes 'c' |
01:43 | char c2 equal to in single quotes 'a' |
01:49 | char c3 equal to in single quotes 'r' |
01:55 | We have created three characters to make the word car. |
01:59 | Now let us use them to print the word. |
02:02 | Type: |
02:04 | System.out.print(c1); |
02:12 | System.out.print(c2); |
02:22 | System.out.print(c3); |
02:31 | Please note that I’m using print instead of println so that all the characters are printed on the same line. |
02:39 | save the file and run it. |
02:43 | As we can see, the output is as expected. |
02:46 | But this method only prints the word but does not create one. |
02:50 | To create a word, we use the String data type. |
02:54 | Let us try it out. |
02:57 | Remove everything inside the main method and type: |
03:03 | String greet equal to "Hello Learner"; |
03:16 | Note that 'S' in the word String is in uppercase. |
03:19 | And we are using double quotes instead of single quotes as delimiters. |
03:25 | This statement creates a variable greet that is of the type String. |
03:31 | Now Let us print the message. |
03:33 | System.out.println(greet); |
03:44 | Save the file and run it. |
03:51 | As we can see, the message has been stored in the variable and it has been printed. |
03:57 | Strings can also be added in Java. |
04:00 | let us see how to do so. |
04:04 | I'm removing the Learner from the message. |
04:08 | We'll store the name in a different variable. |
04:14 | String name equal to “Java”; |
04:22 | Now we’ll add the strings to make a message. |
04:28 | String msg equal to greet plus name; |
04:42 | change the greet println(greet) in the print statement to message println(msg) save the file and run it. |
04:56 | We can see that the output shows the greeting and the name. |
05:00 | But there is no 'space' separating them. |
05:02 | So, let us create a space character. |
05:08 | char SPACE equal to in single quotes space |
05:17 | Note that I have used all uppercase letters in the variable name so that it is clear. |
05:23 | You can change it as you want. |
05:26 | Now, let us add the space to the message. |
05:29 | greet plus SPACE plus name |
05:36 | save the file and run it. |
05:40 | Now we can see the output is clear and as expected. |
05:45 | Let us look at a few string operations. |
05:50 | I’m changing a few characters of the word “Hello” to upper case and of the word “java” to uppercase. |
06:05 | Often, when users give input, we have values like this, in mixed case. |
06:11 | So, Let us run the file to see the output. |
06:18 | As we can see, the output is not clean. |
06:22 | So let us use the String methods to clean the input. |
06:27 | Type: greet equal to greet.toLowerCase(); |
06:41 | This statement converts each character of the string greet to lowercase. |
06:47 | name equal to name.toUpperCase(); |
06:58 | This statement converts each character of the string name to uppercase. |
07:03 | Save the file and Run it. |
07:08 | As we can see, the output is now clean after we have used the String methods. |
07:13 | This is how we create strings and perform string operations. |
07:18 | There are more String methods and |
07:19 | We'll discuss them as we move on to complex topics. |
07:26 | This brings us to the end of this tutorial. |
07:29 | In this tutorial, we have learnt: |
07:31 | how to create strings, add strings |
07:33 | and perform string operations like converting to lower case and upper case. |
07:39 | As an assignment for this tutorial: |
07:41 | Read about the concat method of Strings in Java. Find out how is it different from adding strings. |
07:50 | To know more about the 'Spoken Tutorial' project, watch the video available at the following link. |
07:55 | It summarizes the Spoken Tutorial project. |
07:58 | If you do not have good bandwidth, you can download and watch it. |
08:03 | The Spoken Tutorial Project Team: |
08:05 | Conducts workshops using spoken tutorials. |
08:07 | Gives certificates to those who pass an online test. For more details, please write to contact AT spoken HYPHEN tutorial DOT org. |
08:17 | 'Spoken Tutorial' Project is a part of the 'Talk to a Teacher' project. |
08:21 | It supported by the National Mission on Education through ICT, MHRD, Government of India. |
08:28 | More information on this mission is available at the following link: spoken HYPHEN tutorial DOT org SLASH NMEICT HYPHEN Intro. |
08:33 | This tutorial has been contributed by TalentSprint. Thanks for joining. |