• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

What is the effect of primitive data types on the nature of programming languages?

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why the languages which are having primitive data types in them are considered to be not purely object oriented ,why is said that any language which depends on such primitive data types has actually an involvement of the machine architecture and hence it is not called a pure-object oriented programming language.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Theoretically, in a pure object-oriented language, every value that you can express in the language should be an object.

But primitives types (at least in Java) are not objects - you have to think about them and deal with them differently than with objects. You can't call methods on primitive types, for example.

Someone else recently asked another question about primitive types, and I wrote an answer explaining why they are actually a feature from the underlying machine architecture that's showing up at a higher level - see my answer here.
 
radha gogia
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Without primitives in the language, the compiler would still generate bytecode that uses primitives on the JVM.



Sir,actually I could understand a bit but I am unable to get the meaning of the above sentence.I am actually unable to get the fact that how are primitives actually considered by the machine ,and in which form do they reside as a part of hardware and how is it related to the functioning of the regsiters.
 
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically the common computing systems that we use are modeled using five main components which are the CPU, ROM, RAM, I/O Ports...

The CPU itself is made up of discrete components called registers which are memory elements where each element in the register can store 2 discrete values 0 and 1...

According to the architecture, each register has a finite number of these elements which we can informally consider as its width... If we say each register is 8 bits wide then it will look like -> 00000000

These components are use to perform the operations of the CPU such as arithmetic, logic, control, etc...

Now RAM is just a sequence of these same memory elements grouped together in 8's which are called bytes where each byte has an address...

Example layout of RAM:
00000000 ; address no 1
00000000 ; address no 2
00000000 ; address no 3
00000000 ; address no 4

Now if you write something like the following :
byte value1 = 4;
byte value2 = 8;

The system finds unused bytes and initializes them as follows:
value1: 00000100 ; address no 1
value2: 00001000 ; address no 2

Now if you write the following:
byte value3 = (byte)(value1+value2);

What happens is the CPU loads the first byte in a register and adds the second byte to it then stores in it byte 3 as follows:
00000100 <- in CPU register
+
00001000
--------------
00001100 <- this goes in the byte at address no 3

So that:
value3: 00001100 ; address no 3

Now you can see that primitives are just memory mappings of the machine that specifies byte locations and how much bytes are used to represent a value...
 
radha gogia
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Now you can see that primitives are just memory mappings of the machine that specifies byte locations and how much bytes are used to represent a value...



Sir,I understood what you explained but I am unable to get the meaning of the statement which I just quoted,and just one confusion that in C we actually cannot divide two float values ,but in java ,we can do it ,so that means there must be some code present inside either the compiler which would actually tell which operations can be performed on a particular data type.

Also,Is there a need to consider primitive data types of system dependent and system independent languages.every language do contain primitive data types.primitive data types of system dependent languages like 'C' depend on systems architecture on the other hand primitive data types of system independent languages don't.

So basically the major query is around that how do primitive data types depend on the system architecture and actually inside a system,in which format are they present ,i.e is there some code defined for these primitive data types,.

One more thing which I would like to put forward is that I just wrote one program in C for checking the size of an integer variable,so in one of the compiler I got the output to be 2 bytes and in other compiler ,the output was 4 bytes,so basically how is that different compilers show different outputs,so that raises more curioisty in actually identifying how do primitive data types actually dealt inside a system.
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

radha gogia wrote:in C we actually cannot divide two float values


I'm afraid that I to program in C and this statement is untrue... You must have mistaken divide for modulo...

Machines are simply physical realizations of mathematical concepts... In our digital computing machines the realization is simply a usage of a finite number of elements to represent data and information...
Designers and implementers of programming languages can abstract the underlying elements in any way they see it fit to provide a system of communication that is both effective and efficient to balance the nature of things...
Hence different compilers providing different implementations for the same abstraction which is approved and laid out in the design of the language itself...

Informally speaking, in C it states that an int can be no less than a short which is 2 bytes but on architectures where it allows for larger sizes it can be larger...
 
Marshal
Posts: 80613
467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Discussion too difficult for “beginning”. Moving discussion.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic