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
-1
votes
2 answers

Set a short value in constructor call

I have an enum with a constructor: enum myEnum { A(0), B(1), C(2); private final short value; private myEnum(short value) { this.value = value; } public short getValue() { return this.value; …
JavaA
  • 37
  • 11
-1
votes
1 answer

Unable to create a constant value of type. Only primitive types or enumeration types are supported

I have an entity like the following : class Serial { public int Id { get; set; } public string No { get; set; } } what I have to get is a list of serials by a list of serial ids, but continuously I get the error : Unable to create a…
Hooman L
  • 151
  • 2
  • 8
-1
votes
3 answers

Arithmetic operation on primitive class variables

Couldn't find an explicit description of what's happening so thought i'd bring this up to the community. public class Temp { static int i; int j; int sum = i+j; } public class Main{ public static void main(String[] args){ Temp obj = new…
-1
votes
2 answers

Binary Search with Primitive Types

I am currently in a class for Java Programming and am completely new to Java. I am trying to create a program that will use binary search for the value 45.3 class findValue { public static void main(String args[]) { double a[] = new double[6];…
-1
votes
1 answer

Parse different data type Java

Since int is less precise than double I thought I needed to cast it when parsing it into a method. Yet the following code runs fine. Why? public class MyClass { public static void main(String[] args) { System.out.println(met(3/2)); …
ocram
  • 1,384
  • 6
  • 20
  • 36
-1
votes
2 answers

very new to the programming and at the little exercise I cannot see where I am wrong

So maybe many of you knows the exercise we need to do about learning primitives, where we need to print h3110 w0r1d 2.0 true so mine is this; public class main { public static void main(String[] args) { // H3110 w0r1d 2.0 true byte bir = 0; …
Unknown
  • 13
  • 2
-1
votes
1 answer

Integer parameters formula returns integer

Code below makes foo value as -1149239296 i. e. integer value which is out of bounds: int bar = 3000; long foo = bar * 1024 * 1024; Seems like Java takes type of first parameter and tryes to return formula's result with that type. Where in Java…
Maxim Korobov
  • 2,574
  • 1
  • 26
  • 44
-1
votes
3 answers

Store signed value in Byte

I was trying to store byte value in a variable and trying to perform some logic based upon this calculation. byte mByteValue = -129; // Holding byte value Problem is I am always getting value 127, due to which my logic fails everytime. Any…
Saurabh
  • 975
  • 2
  • 12
  • 27
-1
votes
1 answer

Doing double - int in java

For example if I do this: double decPart = 5.57 - 5; System.out.println(decPart); it returns 0.5700000000000003, instead of just 0.57. I can print it out properly using System.out.printf("%.2f", decPart), but that doesn't solve the problem (Note:…
-1
votes
3 answers

Shortcut to assign a negative value to primitives

I remember reading somewhere in Java, possibly Oracle documentation that there is a shortcut to assign a flip value of a primitive. Similar to: int i = 0; i += 3; System.out.println(i); Output is 3, but what if I wanted -3? Or if given -3, make it…
Otanan
  • 459
  • 3
  • 12
-1
votes
1 answer

GeneralPath and the Composite pattern

A GeneralPath object contains Shapes and is itself a Shape. Would this be an example of a class that uses the Composite Pattern? I am confused by the Composite Pattern condition: "Clients treat a composite object as a primitive object." Is this use…
user3000731
  • 93
  • 2
  • 11
-1
votes
1 answer

Size of a Java Object that contains only primitive types

I have a class that is consisted of the following primitive types only: public class Test{ private int a1; //size of int =4 private long a2; //size of long = 8 private double a3[]; //size of double =8 } Moreover, I have an object for this class…
Mike B
  • 1,522
  • 1
  • 14
  • 24
-1
votes
1 answer

How To Convert a DWORD / QWORD From C To Double In Java

I have unsigned 32-bit, 64-bit primitives that are stored as bytes. I need to use them in Java. So I thought build them back together from bytes. First I'm playing with random bytes to make sure everything is calculated correctly. But I've…
Bitterblue
  • 13,162
  • 17
  • 86
  • 124
-1
votes
1 answer

Reflection get fundamental types

Looking for a way to get the fundamental/core types in c# without using the IsPrimitive and a bunch of "||". Basically I want the decimal, datetime, string to be included, but I don't want to specifically look for them. I remember seeing something…
Alwyn
  • 8,079
  • 12
  • 59
  • 107
-1
votes
1 answer

Convert short array to signed byte array in Java

As input I'm getting a short array like {20, 250, 12, 255}. I need to convert it to byte[] {20,-6,12,-1} I tried to use ByteBuffer: short[] data = {20, 250, 12, 255}; ByteBuffer dbuf = ByteBuffer.allocate(data.length*2); …
Alexey
  • 39
  • 5