Questions tagged [primitive]

A primitive type is a data type provided by a programming language as a basic building block.

The actual range of primitive data types that is available is dependent upon the specific programming language that is being used. For example, in C, strings are a composite but built-in data type, whereas in modern dialects of BASIC and in JavaScript, they are assimilated to a primitive data type that is both basic and built-in.

Classic basic primitive types may include:


  • (character, char)
  • (integer, int, short, long, byte) with a variety of precisions
  • number (float, double, real, double precision)
  • number (fixed) with a variety of precisions and a programmer-selected scale
  • , logical values (true, false)

Reference

977 questions
15
votes
4 answers

Java char array seems to need more than 2 bytes per char

When I run following program(running with "java -Xmx151M -cp . com.some.package.xmlfun.Main") : package com.some.package.xmlfun; public class Main { public static void main(String [] args) { char [] chars = new char[50 * 1024 * 1024]; …
user2528238
  • 153
  • 5
15
votes
3 answers

why are there Primitive datatype in Java?

Possible Duplicate: When we have wrappers classes, why primitives are supported? If there are Wrapper classes which make Java pure object-oriented language, then why are there Primitive datatypes which can be used in Java???
user2003432
  • 181
  • 1
  • 4
14
votes
4 answers

JavaScript style: don't use wrapper objects for primitive types

In the Google JavaScript style guide, it says not to use wrapper objects for primitive types. It says it's "dangerous" to do so. To prove its point, it uses the example: var x = new Boolean(false); if (x) { alert('hi'); // Shows 'hi'. } OK, I…
Bill
  • 561
  • 6
  • 15
14
votes
4 answers

Why C++ primitive types are not initialized like the rest of types?

I know that, in C++, when you write int i; you can not make any assumptions about the value that the variable will hold until you effectively assign it a value. However, if you write int i = int(); then you have the guarantee that i will be 0. So…
jdehesa
  • 58,456
  • 7
  • 77
  • 121
14
votes
3 answers

What does int.class mean

In java int, float and etc., are primitive types. Wrapper classes are used in case we need to use it with generics. But still the following declaration works in java, Class intClass=int.class How can we call int.class even though it is a…
Hariharan
  • 881
  • 1
  • 13
  • 25
14
votes
7 answers

Purpose of byte type in Java

I read this line in the Java tutorial: byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large…
Hải Phong
  • 5,094
  • 6
  • 31
  • 49
14
votes
3 answers

Are primitive types different in Java and C#?

I am manually converting code from Java to C# and struggling with (what I call) primitive types (see, e.g. Do autoboxing and unboxing behave differently in Java and C#). From the answers I understand that double (C#) and Double (C#) are equivalent…
peter.murray.rust
  • 37,407
  • 44
  • 153
  • 217
13
votes
5 answers

Is int an object in Java?

More precisely, is int a part of the Integer class (a stripped down version or something) or is it something else entirely? I am aware that int is a value type and Integer a reference type, but does int inherit from Object anyway? (I am assuming…
soandos
  • 4,978
  • 13
  • 62
  • 96
13
votes
2 answers

javascript: do primitive strings have methods?

MDN states: primitive, primitive value A data that is not an object and does not have any methods. JavaScript has 5 primitive datatypes: string, number, boolean, null, undefined. With the exception of null and undefined, all primitives values have…
Pacerier
  • 86,231
  • 106
  • 366
  • 634
13
votes
3 answers

Does int.class autobox to Class

I am sure my question doesn't make sense, but it's because I don't know what I am seeing or how to describe it... The following code compiles fine, but it shouldn't because int is not the same type as Integer. Shouldn't this give a compiler error?…
leat
  • 1,418
  • 1
  • 15
  • 21
13
votes
1 answer

How does the GetBytes function work?

I wrote my own class which converts C# standard primitives into byte arrays. Later on, I took a look at the BitConverter class source, to see how pros did it. My code example: public static byte[] getBytes(short value) { byte[] bytes = new…
Scavs
  • 673
  • 1
  • 5
  • 16
13
votes
3 answers

How can we use .class on primitive types?

When we say Class c = Integer.class; System.out.println(c); it prints class java.lang.Integer which makes sense because java.lang.Integer is a class. So we can have a corresponding Class object. But when I do Class c1 =…
Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
13
votes
1 answer

Confusion in 16-bit data-type range

In a 16 Bit C compiler we have 2 bytes to store an integer, and 1 byte for a character. For unsigned integers the range is 0 to 65535. For signed integers the range is -32768 to 32767. For unsigned character, 0 to 255. According to the integer…
Smith Dwayne
  • 2,675
  • 8
  • 46
  • 75
12
votes
1 answer

Make Swagger use primitive int and boolean in generated models

By default, for "type": "boolean" in JSON spec, Swagger will generate a Boolean (object, non-primitive, nullable) field in model. Is there a way to make Swagger generate boolean (primitive, non-nullable) fields in models instead? The rationale is:…
alamar
  • 18,729
  • 4
  • 64
  • 97
12
votes
2 answers

If `[` is a function for subsetting in R, what is `]`?

I'm reading the advanced R introduction by Hadley Wickham, where he states that [ (and +, -, {, etc) are functions, so that [ can be used in this manner > x <- list(1:3, 4:9, 10:12) > sapply(x, "[", 2) [1] 2 5 11 Which is perfectly fine and…
Xizam
  • 699
  • 7
  • 21