answersLogoWhite

0


Best Answer

class constructor is a function which has the same name as the class name and has no return type.

primitive data types are the fundamental data types which are independent.

eg:int,char,float etc..............

User Avatar

Wiki User

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

Wiki User

12y ago

Java provides wrapper classes for each of the primitives types (byte, short, int, float, double, etc.) with the same name but starting with uppercase letter (e.g. Byte, Short, Integer, Float, Double, etc.)

Java performs auto-boxing which auto-converts one form to the other so you can use both forms interchangeably.

Integer i = new Integer(1234);

int i2 = i; // same as i2 = i.intValue()

Likewise, if a method has an Integer argument then calling it with an int primitive auto-converts it to an Integer instance as well.

But beware that if the Wrapper class object is null then using it in context of a primitive results in a NullPointerException being thrown.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are Class Constructor and Primitive data types?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Can you declare and define the constructor within class?

Yes, you can declare and define the constructor within a class. A constructor is a special member function of a class that is automatically called when an object of the class is created. It is used to initialize the object's data members. The constructor can be declared and defined within the class definition or can be defined outside the class definition using the scope resolution operator (::).


What are the properties of class in c plus plus?

A constructor is not a function. A function is a type, as specified by its return type, and must return a value of that type unless the type is void. A constructor does not return anything, not even void. The purpose of a constructor is to both allocate and initialise memory for an object of the type being constructed. If a valid object cannot be constructed for any reason, the constructor must throw an exception. If the object's class has no data members (attributes), the class does not require a constructor. This is typically the case for most abstract data types and base classes which are used purely as interfaces. Constructors differ from functions in that all constructors have an initialisation section that is used specifically to initialise non-static data members. The body of the constructor is rarely used except to perform initialisations that cannot be more easily performed by the initialisation section. A class may have more than one constructor to provide alternative methods of construction based upon the number and type of arguments supplied (if any). When no arguments are required or all arguments have default values then the constructor is known as the default constructor. If the constructor has only one argument the constructor is known as a conversion constructor (because the argument is converted to an object of the class). However, if the constructor argument is a constant reference to an object of the same class, then it is known as a copy constructor, and when the constructor argument is an rvalue reference, it is known as a move constructor. If copy and/or move constructors are provided for a class, the equivalent assignment operators should also be provided for that class. All other constructors are known as user-defined constructors.


Variables as object in java?

There are two main categories of variables in Java. They are primitive and non primitive. Primitive data types are the basic data types like int, float, char etc. These are not objects. The other non primitive data types are all types of Java Objects. Example: String, ArrayList etc.


What are the types of non primitive in java?

There are 8 primitive data types: byte, short, int, long, float, double, boolean, charany other data type in Java can be considered non primitive data type.Ex: StringString data type can also be known as the primitive data type because it is already provided by the Java language, since it is not a data type but its a class, but as we know that we can use the classes as types for the variables/instance variables, as we use while creating an object of any class, hence the classes that we create and use them as a datatype are known as non-primitive datatype....for any query, mail me on engineer.sooraj@gmail.com or call me on +92-331-350-6956.....


What is DataInputStream?

This section demonstrates you the use of DataInputStream class. The class DataInputStream allows to read primitive Java data types from an underlying input stream. It reads the file line by line.

Related questions

What is wrapper class in java?

wrapper class is a predefined class .it is used for converting primitive data types into object type


What is the difference between class data type and basic type in c plus plus .How can someone know which one is class type and which one is basic type.?

Basic types (primitive data types) have no methods associated with them.


Can you declare and define the constructor within class?

Yes, you can declare and define the constructor within a class. A constructor is a special member function of a class that is automatically called when an object of the class is created. It is used to initialize the object's data members. The constructor can be declared and defined within the class definition or can be defined outside the class definition using the scope resolution operator (::).


Variables as object in java?

There are two main categories of variables in Java. They are primitive and non primitive. Primitive data types are the basic data types like int, float, char etc. These are not objects. The other non primitive data types are all types of Java Objects. Example: String, ArrayList etc.


What are the properties of class in c plus plus?

A constructor is not a function. A function is a type, as specified by its return type, and must return a value of that type unless the type is void. A constructor does not return anything, not even void. The purpose of a constructor is to both allocate and initialise memory for an object of the type being constructed. If a valid object cannot be constructed for any reason, the constructor must throw an exception. If the object's class has no data members (attributes), the class does not require a constructor. This is typically the case for most abstract data types and base classes which are used purely as interfaces. Constructors differ from functions in that all constructors have an initialisation section that is used specifically to initialise non-static data members. The body of the constructor is rarely used except to perform initialisations that cannot be more easily performed by the initialisation section. A class may have more than one constructor to provide alternative methods of construction based upon the number and type of arguments supplied (if any). When no arguments are required or all arguments have default values then the constructor is known as the default constructor. If the constructor has only one argument the constructor is known as a conversion constructor (because the argument is converted to an object of the class). However, if the constructor argument is a constant reference to an object of the same class, then it is known as a copy constructor, and when the constructor argument is an rvalue reference, it is known as a move constructor. If copy and/or move constructors are provided for a class, the equivalent assignment operators should also be provided for that class. All other constructors are known as user-defined constructors.


What are the types of non primitive in java?

There are 8 primitive data types: byte, short, int, long, float, double, boolean, charany other data type in Java can be considered non primitive data type.Ex: StringString data type can also be known as the primitive data type because it is already provided by the Java language, since it is not a data type but its a class, but as we know that we can use the classes as types for the variables/instance variables, as we use while creating an object of any class, hence the classes that we create and use them as a datatype are known as non-primitive datatype....for any query, mail me on engineer.sooraj@gmail.com or call me on +92-331-350-6956.....


Is array a primitive data structure?

No, it's not. But it can be based on primitive data types (int, char, long, double and so on).


What is primitive and composite data types in DBMS?

a composite data type is any data type which can be constructed in a program using its programming language's primitive data types and other composite types. The act of constructing a composite type is known as composition.


What is DataInputStream?

This section demonstrates you the use of DataInputStream class. The class DataInputStream allows to read primitive Java data types from an underlying input stream. It reads the file line by line.


How many simple data types are there?

There are a total of 8 simple or primitive data types in Java. They are:byteshortintfloatdoublebooleanlong andString


Functions of primitive data types?

defines the value of a cell


What is the purpose of constructor in object oriented programming?

A constructor in a class is one of the first pieces of code to be executed when you instantiate a class. The purpose of constructors is to have code that initialize the class and prepare the variables that may be required by the class...