String to Integer

In JAVA programming it is very frequent demand of converting an int/Integer to String.

Below snapshot shows how this is done. Easy to remember.
Integer to String

public class DataTypeCoversionDemo {
            private static String strVar = "11";
            private static int intVar = 22;
            private static Integer integerVar = 222;
     
      public static void main(String[] args) {      
          convertInt_String();   
      }

      public static void convertInt_String(){
            // ********* Integer to int ********** //
            Integer tInteger = Integer.valueOf(intVar);
            int tSimpleIntValue = tInteger.intValue();

            System.out.println("Simple Int to Integer  :- " + tInteger); //22      
            System.out.println("Integer to Simple int :- " + tSimpleIntValue); //22

            // ********* int to String ********* //
            String tString = String.valueOf(intVar);
            int tInt = Integer.parseInt(strVar);

            System.out.println("Simple Int to String :- " + tString); //22
            System.out.println("String to Simple Int :- " + tInt); //11

            // ******* Integer to String ******* //  
            String tString2 = integerVar.toString();
            Integer tInteger2 = Integer.parseInt(strVar);        

            System.out.println("Integer to String :- " + tString2); //222
            System.out.println("String to Integer :- " + tInteger2); //11
      }
}

Chars are digits?

When I was a kid for my computer classes, my master said – “Computer understands only binary digits”.

I thought – he is bluffing.  

I was into a position to digest — Okay computer understands 1 as 1, 2 as 2 — Coz I had a knowledge of decimal to binary conversion.

1 — 0000 0000 0000 0001 ( for 16 bit m/c)

5 — 0000 0000 0000 0110 ( for 16 bit m/c)

But I was not ready to accept the way my teacher said. I ask myself – How come “A” will be represented as some 1, 2, 3, 4 – in digit format. So if I write “Hello World” — does it mean ?- Is this something like 4324421625834  or 0010 1000 0011 1100…..

After 4 years of my engineering and 6 years of IT experience, I was going through the “Primitive Data Types” in the book “Java Certification by Khalid A. Mughal & Rolf W. Rasmussen”.

 The diagram in the book has given me a big shock!!!!!!!!!!!!!!!!!  
               
Primitive Data Types in Java
 How come the char data type is grouped under “Integral types”?

 After reading carefully I came to know — Oh it’s an unsigned number.

So what — still it’s a number!

After rehearsing the same line again and again –> “Characters are represented by the data type char. Their values are unsigned integers that denote all the 65536 (2 pow 16) characters in the 16-bit Unicode character set. This includes letters, digits, and special characters.

Ok, so got it finally. What does the line say … even if it is a character that will be stored as some integer values ( of course unsigned).

 So to say further ‘A’ is infact \u0041 [\u for Unicode, followed by for digit Hexadecimal number  – equivalent to 65 in Decimal ]

 This is where A is interpreted as \u0041 or 65 in decimal or 0000 0000 0110 0001 in binary.

Once A is a digit, your computer will understand it as

‘A’ – 65 – 0000 0000 0110 0001

‘a’ – 97 – 0000 0000 0100 0001

This explanation also proves that why char has been grouped under Integral types in the diagram.

And also my master was right -“Computer understands only binary digits”.

 Now look at the below Java code now:

public class CharTypeDemo {
	public static void main(String[] args) {
		char char1 = 'a';  // I will be stored in computes as 61 only, but you will be able to see me as it is
		char char2 = '\u0061'; // because of "\\u" plz put my converted charter value
		
		int int1 = 'a';  // should be a type conversion here from char to int
		int int2 = 97;
		
		System.out.println("char1   char2   int1  int2");
		System.out.println(char1 + "\t" + char2 + "\t"  + int1 + "\t" + int2);	
	}
}

Output:

char1 char2 int1 int2
a a 97 97

Education System in India

Since last two decades, I have been seeing a continuous growth in India. Things have changed (sry its improved) a lot from 90 to 2000. But still this growth is limited to metros & cities only. We have to move ahead further to make a better India in all perspectives.

We have been blaming the system, we have been complaining about it. There would be another way of solving, what is the maximum contribution that an individual can do to make this system better rather than expecting someone to correct it. Let me put my 100% which could be almost a negligence but still it will.

I will pin point to the education system in India, which is the base for any Indian to project him/her for revamping our country. Are we right to the track? We were the Indians to bring the 1st university in the world (Nalanda University). Can I put a line graph which connects today’s education system with the historical India? Somewhere I read, Intruders came to India and they have stolen our four VEDAS, a place where all sort of knowledge have been grooved in those 4 mega books. My concern is to say, if we Indians were the ACE in education system in entire world, then why today’s India is struggling to bring a primary school to the remote villages? I thank to all those Bollywood innovators, to make a move in this regard may be its Tare Zameen Pe, 3 Idiots or Pathshala.  They are not just eye-opener in fact they convey the responsibilities of each of us. I thank them to remind the Indians that despite your 9 to 5 job, there are more to do. Just don’t sleep.

Governments are planning and no doubt they are executing them successfully more or less; It’s a high time for all Indians to contribute for a better India. I will say implementation of UNIQUE ID system in India will make a big difference, just hoping the involved team gives their best. If Indian Railway (largest management in the world) website can serve the millions Indian well, then lets hope the new database will serve a better purpose. We must cooperate for any new ideas for making a better India.

School Chale Hum