Big Data and Hadoop Training: Java Programming Hands On
Slide 1: Java Programming Hands-on
Hello and welcome to lesson number eight on Hadoop training offered by Simplilearn. In this lesson we will try to do some practical exercises in order to brush up our java programming skills.
Slide 2: Agenda
Here we will discuss some useful java programs and unit test program to test our java programming skills.
We will start with our first java program in the next slide.
Slide 3: Java Program – Swapping Two Integers
Let us try to create a program in java to swap two integers. Also, in the program, we need to create a user-defined class.
Slide 4: Executable Code – Swapping Two Integers
Here we create a user-defined class SwapNumbers which contains swap method (represented by the word swap with a pair of brackets in java programming syntax).
On line number seven, we create a scanner class object. On line number eight, and nine, we take inputs using Scanner class and assign it on x, and y variable.
On line number fourteen, we create a user-defined class (i.e. SwapNumbers).In this class, we use temp (t-e-m-p) as a third variable. On line number seventeen, we create a method (i.e. swap method), which actually swaps two variables.
On the next slide we will discuss another java program.
Slide 5: Java Program – Extracting a Substring
Let us now try to create a program in java to extract a substring without the first five characters from a given string.
Slide 6: Executable Code – Extracting a Substring
We use substring method to extract from a string (represented by the word substring with a pair of brackets in Java programming syntax).
On line number ten, we assign “hello simplilearn” on str (s-t-r) . On the next line, we use substring method and pass 5 as a parameter to discard first five characters and re-assign on str (s-t-r). On line twelve, we print it on console.