Saturday 13 February 2016

Accept User Input in Java

For accepting user input in Java refer the following piece of code below :

import java.io.*;

public class User_Input {

public static void main(String[] args) {
String inp="";
System.out.println("Please enter your name : ");
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
inp=br.readLine();
}
catch(IOException e) {
e.printStackTrace();
}
System.out.println("Welcome " +inp);

}


}

Output:
Please enter your name : 
IronCladWriter
Welcome IronCladWriter

Make sure to import java.io.* so as to use the input/output functions. Notice that we have wrapped an InputStreamReader within a BufferedReader. Guys, do check out detailed documentation on BufferedReader and InputStreamReader for better understanding.

Friday 12 February 2016

Basic string manipulation in Java with Real Examples : Part 1

Hi guys, how you doing today? I just noticed I haven't written anything about Java in quite some time now. Well let's bring Java back into the spotlight with this light subject on basic string manipulation.

Lets try to cover some simple examples covering different scenarios :

Illustration 1 : Extract a substring from a string

In this example we simply extract a part of the string.

public class String_manip {

public static void main(String[] args) {
 String str = "Hello guys. Welcome to IroncladZone";
 
 String sub_str = str.substring(23, 35);
 
 System.out.println (sub_str);
}

}

Output : IroncladZone

Illustration 2 : Replace a substring from a string

In this example we replace the word "guys" with "goodfellas" within the string.

public class String_manip {

public static void main(String[] args) {
String str = "Hello guys. Welcome to IroncladZone";
String replaced_str = str.replace("guys", "goodfellas");
System.out.println(replaced_str);

}

}

Output : Hello goodfellas. Welcome to IroncladZone

Note that strings are immutable. Their value cannot be changed once its created. However we can create a new string with the replaced word/part.

Illustration 3 : Join / Combine two strings i.e Concatenation

In this we simply join 3 strings together using +

public class String_manip {

public static void main(String[] args) {
String str1 = "Welcome";
String str2 = "to";
String str3 = "IroncladZone";
System.out.println(str1 + str2 + str3);
System.out.println(str1 + " " + str2 + " " + str3);

}

}

Output : 
WelcometoIroncladZone
Welcome to IroncladZone

Illustration 4 : Print the length of the string


public class String_manip {

public static void main(String[] args) {
String str = "Welcome to IroncladZone";
System.out.println(str.length());

}

}

Output :
23

Note the length() function used to show the length of the string.

Illustration 5 : Split a string on a whitespace

public class String_manip {

public static void main(String[] args) {
String str = "Welcome to IroncladZone";
String[] new_str = str.split("\\s+");
System.out.println(new_str[0]);

}


}

Output :
Welcome

Notice the \\s+ regex for the whitespace.

That's it for today fellas. I'll try to include some more advanced scenarios in a 2nd part of this post. There's more to come guys, stay tuned...

Thursday 11 February 2016

How to list all Components of a Stream in IBM RTC

Inorder to list all the components of a stream in IBM RTC from the command line, run the following command.

Usage :

lscm list components -r repository-connection-name -w stream-name

Eg : 

lscm list components -r https://jtsrv.uk.hibm.company:9094/jazz -w htse.mydocs.midata.dev

Notice that for this command we haven't used quotes anywhere in the syntax. Also note for the -w switch for workspace, we need to supply the stream name.

The output would be obviously the list of components as expected, something like :

Workspace: (1001) "htse.mydocs.midata.dev"
     Component: (1091) "htse-mydocs-abc"
     Component: (1092) "htse-mydocs-xyz"
     Component: (1093) "htse-mydocs-pqr"

How to list all Streams of a project area in IBM RTC

In IBM Rational Team Concert, if you want to list all streams of a project area from the command line, here's a quick reference.

Usage :

lscm list streams --projectarea "project-area-name" -r repository-connection-name

Eg :

lscm list streams --projectarea "pdfservice.channels.group.prd" -r https://jtsrv.uk.hibm.company:9094/jazz

The output would be the names of all streams something like :

(1000) "htse.midata.dev"
(1001) "htse.mydocs.dev"
(1002) "pdfservice.channels.group.stream"

Kindly note that as per the syntax we need to use quotes only for the project area name and not for the repository connection.

How to list all Project Areas in IBM RTC from command line

Inorder to list all the project areas of a repository connection in IBM Rational Team Concert, run the following command :

lscm list projectareas -r repo-name

Eg :

lscm list project areas -r https://jtsrv.uk.hibm.company:9094/jazz

The output will list all the available project areas for only that repository.

Create Runnable Jar in Eclipse

Here's a quick pictorial on how to create an executable jar in Eclipse. Assuming you have a Java project in place, let's take a quick look into the steps.

Go to File menu -> Export. Expand Java to choose Runnable JAR File and click Next. Check out the screenshot for reference.


In the next screen, you simply have to choose the Destination folder where you want to save the executable Jar. Also choose the java application's Launch configuration. It also lets you save an Ant script describing the Jar file that you created. Check out this link for official detailed reference.

Shibuya - The Modern Tetris

A few months back I had some real trouble concentrating well on things. A friend of mine suggested I play Tetris once in a while to help improve my concentration. Well, that's when I stumbled across this simple awesome game - Shibuya. 

Shibuya Grandmaster is a modern day refined Tetris with the classic arcade look and feel. The objective of the game is very simple - match multiple blocks of the same color and take them out. But the game needs to be completed in 7 varying speeds. Though the game may seem extremely simple in the beginning, but gets really tough later. The speed list is as follows : 
  • Slow
  • Normal
  • Adept
  • Fury
  • Reflex
  • Machine
  • Gentle Rain
The slow speed is the easiest while the Gentle Rain is really really difficult. The continually faster speeds challenge your reflexes and thereby helps improve concentration. You really need to plan fast based on the upcoming blocks so as to form pairs. You have to couple your concentration with quick adept planning to successfully complete the level in stipulated 2 minutes. All in all, its a beautiful game of concentration and planning, highly recommended to players of all ages.

Check out my gameplay of the Reflex Mode below to get a taster : 


Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker