Use of split function

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package WordSplit;

import java.util.Arrays;

/**
 *
 * @author SHASHI
 */
public class WordsSplit {
   
   
    public static void main(String[] args) {
       
        String sentences=  "Generates HTML. Building HTML from a helper class is\n" +
"probably not really worth it for real projects (JSP is\n" +
"better), but we haven’t covered logic in servlets yet. But\n" +
"the general principle still holds: if you are doing the same\n" +
"thing in several servlets, move the code into shared class";
        String[] words = sentences.split("[\\n .(),]");      // as many punctuation we put we receive as many seperation point on the sentences.
       
        System.out.println(" In string form"+Arrays.toString(words)  );
       
        for (int i = 0; i < words.length; i++) {
            System.out.println(" "+words[i]);
           
           
        }
       
       
       
    }
   
   
}


#########################OUTPUT##############################################

run:
 In string form[Generates, HTML, , Building, HTML, from, a, helper, class, is, probably, not, really, worth, it, for, real, projects, , JSP, is, better, , , but, we, haven’t, covered, logic, in, servlets, yet, , But, the, general, principle, still, holds:, if, you, are, doing, the, same, thing, in, several, servlets, , move, the, code, into, shared, class]
 Generates
 HTML

 Building
 HTML
 from
 a
 helper
 class
 is
 probably
 not
 really
 worth
 it
 for
 real
 projects

 JSP
 is
 better


 but
 we
 haven’t
 covered
 logic
 in
 servlets
 yet

 But
 the
 general
 principle
 still
 holds:
 if
 you
 are
 doing
 the
 same
 thing
 in
 several
 servlets

 move
 the
 code
 into
 shared
 class
BUILD SUCCESSFUL (total time: 0 seconds)















Use of Static keyword


package dice;
import java.util.Random;

public class Dice {
static int no_of_sides = 6;
int face_value = 0;
int roll() {
Random r = new Random();
this.face_value = r.nextInt(no_of_sides) + 1;
return this.face_value;
}
static class FirstDice {
static String color = "red";
}
static class SecondDice {
static String color = "black";
}
public static void main(String[] args) {
Dice d = new Dice();
System.out.println("The first die has color " + FirstDice.color + " and has face value after rolling as " + d.roll());
System.out.println("The second die has color " + SecondDice.color + " and has face value after rolling as " + d.roll());
}
}


/**    comments
Here, we have used the static keyword to call the variable(colour ) directly in main method.
We made the inner class(firstDice) static and then the variable colour static to display the colour of  first dice in main method.
Also, in the main method which is static, any variable which needs to be accessed should be static and for the non-static, the variable, function or method, which needs to be  accessed should be accessed by creating an instance of the class, which we have done for calling the function roll in the main method.

**/