Sunday, April 5, 2015

Learning Java, if you know C : Part-1 , Data Type

The only thing I like about blogs is you can look back and see how under-developed your mind was.

Again after getting bore of all things possible, i am here. This time I will be putting a series of article.

More for my sake than yours. Before we get down to main thing for which we are here, I will just say watching HOUSE OF CARDS, has taken a toll on me . I was want to get into politics.

Other point , EVERNOTE is cool.I mostly write my most of the articles there, but since my company doesn't allow me to access it ( WE ARE STILL NOT FREE). I have to migrate my articles to BLOGGER.  In starting things will be simply copy-paste.


There will be no coherent structure by which we will learn , it will simply be chaotic.


DATA TYPES

Learning Java

1. What happens when a data-type is assigned value greater than it can hold

 > Both in C and Java, there will be no error thrown, but the value shown will not be correct. The value will be represented in bits and then only those bits whose are defined
for the data-type will be used to display the value.

 > NEW THING LEARNED : there is no signed type in Java, in C only int,char,long,short are UNSIGNED, float and double not.

 ********************************************************* JAVA PROGRAM *********************************************************
 public class intmaxsize{

public static void main(String[] args)
{
short a=(short)65535;
System.out.println(Short.BYTES);
System.out.println(" " + a);
}
}

// Java doesn't have concept of unsigned datatype like in C/C++.
// Also like C/C++ , there is no error thrown on excedding the max size, the binary representation of bits allocated to the number is displayed
 ********************************************************* JAVA PROGRAM *********************************************************

  ********************************************************* C PROGRAM *********************************************************

 #include
#include

using namespace std;


int main()
{
unsigned short a=65536;
cout << sizeof(a) <<" ";
cout << a;
return 0;
}

// short can store upto 65535 only, but even if we store value greater than that no error will be thrown at run time or compile time, only wrong value will be stored
 ********************************************************* C PROGRAM *********************************************************


No comments:

Post a Comment