answersLogoWhite

0


Best Answer

Java defined int as a 32-bit number because that is generally large enough to hold the information you need.

The size of an int in C may actually have either 16 or 32 bits, depending on the implementation. Basically, the specifications for any C implementation in UNIX must have 32-bit ints, while the ISO C standard only requires 16-bit ints. The stdint.h and limits.h files exist exactly because not all implementations are the same, and these files will define the min/max values of the integral types.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

Characters in C are ASCII characters. There are only 256 different characters in the ASCII character set, and so 8-bits are enough to store this data.

Characters in Java are 16-bit Unicode characters (65536 different characters), so twice as much storage is needed to store the extra characters.

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

32-bit integers are common in programming languages, and the Java developers simply decided to stick with convention.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why java takes 4 byte of int while c has 2?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How integer classified in java?

int short byte long


What is java int?

This groups includes byte,short,int and long.Integer data type is used for storing integer values.The size of the int is 32 bit.The range of the int is -2,147,483,648 to 2,147,483,648


What are the only types in Java that are not classes?

The non-class Java data types are primitives: * byte * short * int * long * float * double * boolean * char


How do you write a function which takes 2 arguments - a byte and a field in the byte and returns the value of?

bool F1(int byte,int pos) { return(byte & 1<<pos) } //pos -> position in the field // say byte is b1011 and pos is 2 then it will return value 0


Eight basic data types used in java?

char, boolean, byte, short, int, long, double, or float


What are java kaywords?

if ,while,do , int ,float, for,switch,else,


What is the memory size of integer pointer?

for C: sizeof (int), often 2 or 4 bytefor Java: 4 byte


What are fundamental data types in java?

Assuming by "fundamental" you mean the primitive data types: boolean, byte, char, short, int, long, float, and double


What is meant by wrapper classes?

Java has several "primitive" types (byte, short, int, float, double, boolean, char). Wrapper classes refer to the classes which "wrap up" each of these. For example, the Byte class contains a byte primitive and the methods to modify the class.


Why char consumes 2 bytes in java and int consumes 4 bytes in java?

in java, char consumes two bytes because it uses unicode instead of ascii. and int takes 4 bytes because 32-bit no will be taken


Write the program for two matrix adds in java?

import java.io.*; class mat { protected static void main()throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader()); int a[][]=new int[10][10]; int b[][]=new int[10][10]; int c[][]=new int[10][10]; for(byte i=0;i<10;i++) { for(byte j=0;j<10;j++) { System.out.print("Enter the value of a[ "+i+" ][ "+j+"]: "); a[i][j]=Integer.parseInt(in.readLine()); } } for(byte i=0;i<10;i++) { for(byte j=0;j<10;j++) { System.out.print("Enter the value of b["+i+" ][ "+j+" ]: "); b[i][j]=Integer.parseInt(in.readLine()); c[i][j]=a[i][j]+b[i][j]; } } for(byte i=0;i<10;i++) { System.out.println(); for(byte j=0;j<10;j++) { System.out.print(c[i][j]+" "); } } }}


Write a java program to find addition of two matricess?

import java.io.*; class mat { protected static void main()throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader()); int a[][]=new int[10][10]; int b[][]=new int[10][10]; int c[][]=new int[10][10]; for(byte i=0;i<10;i++) { for(byte j=0;j<10;j++) { System.out.print("Enter the value of a[ "+i+" ][ "+j+"]: "); a[i][j]=Integer.parseInt(in.readLine()); } } for(byte i=0;i<10;i++) { for(byte j=0;j<10;j++) { System.out.print("Enter the value of b["+i+" ][ "+j+" ]: "); b[i][j]=Integer.parseInt(in.readLine()); c[i][j]=a[i][j]+b[i][j]; } } for(byte i=0;i<10;i++) { System.out.println(); for(byte j=0;j<10;j++) { System.out.print(c[i][j]+" "); } } }}