Scanner Class in Java

When I started learning Java around 8 years ago, I had a  problem. Because I'd already known C and C++, it was very hard for me to get input from console using Java code. C and C++ need just a line to get input whereas for Java we'd required a lot. Now it's more easier using Scanner class :

Reading From Keyboard :
import java.util.Scanner;

public class ScannerDemo {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
//
// Read string input for username
//
System.out.print("Username: ");
String username = scanner.nextLine();
//
// Read string input for password
//
System.out.print("Password: ");
String password = scanner.nextLine();
//
// Read an integer input for another challenge
//
System.out.print("What is 2 + 2: ");
int result = scanner.nextInt();
if (username.equals("admin") && password.equals("secret") && result == 4) {
System.out.println("Welcome to Java Application");
} else {
System.out.println("Invalid username or password, access denied!");
}
}
}

Note: Code is taken from this URL.

Reading From File:
import java.util.Scanner;
import java.io.*;
class HelpFile
{
    public static void main(String[] args) throws IOException
    {
        Scanner scanner = new Scanner(new File("test.txt"));
        while (scanner.hasNextLine())
         System.out.println(scanner.nextLine());
    }
}


Reading From Socket:
Scanner remote = new Scanner(socket.getInputStream());
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
 //read line from keyboard
line = keyboard.nextLine();
 //send line to remote node
 out.println(line);
 //wait for a line from remote node
line = remote.nextLine();       

Weka and R Tutorial

World is amazing because of web. One can solve problems based on other's approach by looking them in web. One can teach what he knows to others by releasing article, audio or video lectures in web. Here I've found a very interesting site, SentimentMining.net, that is very useful for people who are interested in data mining or sentiment mining and statistical analysis. I particularly liked weka video tutorial in the site. It also has tutorials for R but I've not explored that much.