Learn With Reshu is here to help you all to get new Technological ideas and knowledge. I will try to create blogs on all technical topics and new tricks and tips. please do like share and subscribe Learn with Reshu to encourage me more for creating good help to others.
Thanks,
Best Regards
#learnwithReshu
Advanced Java Programming Advanced Java Programming :- Introduction to advance java As most of us already know that if we want to make normal applications it can be easily built using core Java concepts. But, when it we need to develop web applications, advanced Java fundamentals, like JSP, Servlets, JDBC etc. needed, so to add capabilities and features of the application advance java is essential for developers. Through the motive of this blog is to explain about Advanced Java, I will be giving you a complete insight into the fundamental concepts of Advance Java. Figure - 1.2 If you want to see complete video on this please have a look the video below. Learn with Resh u Advanced Java Programming Course ...
Get link
Facebook
X
Pinterest
Email
Other Apps
Primitive and Non Primitive Data types ,Difference between primitive and non-primitive data types
Get link
Facebook
X
Pinterest
Email
Other Apps
-
Primitive and Non Primitive Data types
A data typeis an attribute of a variable which tells the compiler or interpreter how the programmer intends to use the variables. It defines the operations that can be done on the data and what type of values can be stored. In this article, I will give you a brief insight into the different data types in java. According to the properties they possess, data types are divided into two groups:
Primitive Data Types
Non-Primitive Data Types
Primitive Data Types:
A primitive data type is pre-defined by the programming language. The size and type of variable values are specified, and it has no additional methods.
Non-Primitive Data Types:
These data types are not actually defined by the programming language but are created by the programmer. They are also called “reference variables” or “object references” since they reference a memory location which stores the data.
Now, let’s move further and get into the details of Primitive Data Types.
Primitive Data Types
Data types in Java are classified into 4 aspects as int, float, character and boolean. But, in general, there are 8 data types. They are as follows:
byte data type
boolean data type
char data type
shortdata type
int data type
longdata type
floatdata type
doubledata type
You can refer to the below figure to understand the different data types with respect to the memory allocated to them, and there defaults values
That was all about the data type. I hope you understood it. Now let’s understand each of these data types in depth i.e. byte data type.
01. Byte data type
This is an example of a primitive data type. It is an 8-bit signed two’s complement integer. It stores whole numbers that lie between -128 to 127. A byte data type is helpful for saving memory in large amounts. Now let’s write a small program and understand how it works.
1
2
3
4
5
6
7
8
9
classByteDatatype {
publicstaticvoidmain(String[] args) {
byte a, b;
a = 127;
b=177;
System.out.println(a); // prints 127
System.out.println(b); // throws an error because it cannot store more than 127 bits
}
}
Now let’s understand what is boolean data type.
02. boolean data type
A boolean data type comprises of a bit of information and can store only true or false values. This data type is used to track true/false conditions. Now let’s write a small program and understand how it works.
1
2
3
4
5
6
7
8
9
10
classboolean{
publicstaticvoidmain(String args[]){
booleanlanguage = true;
booleanNumber= false;
System.out.println(language); // Output will be true
System.out.println(Number); // Output will be false
}
}
That was all about the boolean data type. Now let’s move further and comprehend the following data type i.e. short
03. short data type
A short data type is greater than byte in terms of size and less than a integer. It stores the value that ranges from -32,768 to 32767. The default size of this data type: 2 bytes. Let’s take an example and understand the short data type.
1
2
3
4
5
6
classShort {
publicstaticvoidmain(String[] args) {
shortc= 3435,
System.out.println(c); // prints the value present in n i.e. 3435
}
}
Moving ahead, let’s move further and look at the next data type i.e. i char data type
04. char data type
This data type is used to store a single character. The character must be enclosed within single quotes, like ‘F’ or ‘f’. Alternatively, you can also use ASCII values to display certain characters. Let’s take a small example and see how it works.
1
2
3
4
5
6
7
8
charbeta = 'J';
chara = 65, b = 66, c = 67;
System.out.println(beta ); // prints J
System.out.println(a); // Displays 65
System.out.println(b); // Displays 66
System.out.println(c); // Displays 67
That was all about the char data type. I hope you understood it. Now let’s move further and understand the next data type on the list i.e. long data type.
05. long data type
This data type is a 64-bit two’s complement integer. By default, the size of a long data type is 64 bit and its value ranges from -263 to 263-1.
For example:
1
2
longnumber = 15000000000L;
System.out.println(number ); // prints 15000000000
That was all about the long data type. Now let’s move and see int data types.
06. int data type
This data type can store whole numbers from -2147483648 to 2147483647. Generally, int is the preferred data type when you create variables. with a numeric value.
For example:
1
2
intnumber = 5464564;
System.out.println(number ); // prints 5464564
Having understood this, now let’s see which is the next data type in the list.
07. Floating Datatypes
You should use a floating point type whenever you need a number with a decimal, such as 8.88 or 3.14515.
01. float data type
This data type can store fractional numbers from 3.4e−038 to 3.4e+038. Note that you should end the value with an “f”. Let’s take a small example and understand this data type in a detailed manner.
1
2
floatnum =67;
System.out.println(num); // prints the floating number value
So this is how you can use the float data type. Now let’s see one more floating data type i.e. double
02. double data type
The double data type can store fractional numbers from 1.7e−308 to 1.7e+308. Note that you should end the value with a “d”:
1
2
doublenum = 79.678d;
System.out.println(num); // prints double value
That was all about Double data type and this brings us to the end of Primitive Datatypes. Now let’s figure out the difference between primitive and non-primitive data types.
Difference between primitive and non-primitive data types
The difference betweenprimitiveandnon-primitivedata types are as follows:
Primitive types are predefined in java. Non-primitive types are created by the programmer and is not defined by Java.
Non Primitive types can be used to call methods to perform certain operations, while primitive types cannot.
A primitive type always has a value, whereas non-primitive types can be null.
A primitive type starts with a lowercase letter, while non-primitive types start with an uppercase letter.
The size of a primitive type depends on the data type, while non-primitive types have all the same size.
Non-Primitive Datatypes
Non-Primitive data types refer to objects and hence they are called reference types. Examples of non-primitive types include Strings, Arrays, Classes, Interface, etc. Below image depicts various non-primitive data types.
Let’s now understand these non-primitive data types in short.
Strings:
String is a sequence of characters. But in Java, a string is an object that represents a sequence of characters. The java.lang.String class is used to create a string object.
Arrays:
Arrays in Java are homogeneous data structures implemented in Java as objects. Arrays store one or more values of a specific data type and provide indexed access to store the same. A specific element in an array is accessed by its index.
Classes:
A class in Java is a blueprint which includes all your data. A class contains fields(variables) and methods to describe the behavior of an object.
Structure:
Non-primitive not just store a value, but rather a collection of values in various formats
So that was all about the non-primitive data types.
Learn Complete OOPS Concepts in one Project In this Page i will give a example Code for covering all oops concepts in only one single project. Class Model Code Example Explanation:- Suppose there is a Organization which has many departments and many Employees Some Employees are Part of Some Departments So In this Code example What i have created is A Organization Class Which is having Many Employees so One Employee Class and Employee is a part of Departments so We have Created one Departments Class Now Organization, Department and Employee has some task to be done so for that i have created Interfaces for each one where i H...
The “Spring Framework” is a large project. Under the Spring Framework label are actually about 20 different Spring projects. Spring MVC, Spring Security, Spring Integration, etc. So, it would be easy to get confused about what “Spring Core” is. The official Spring documentation, contains this image: “Spring Core” is typically used to refer to the functionality of the Core container. Beans, Core, Context, and SpEL. While there are about 30 Spring Framework projects, they all depend on this core container. Its this core functionality that has been around since the beginning of the Spring Framework. The core container, which has the Spring Context, manages dependency injection for us via Inversion of Control is used by all other Spring projects. Spring Boot Application In Hindi Cheers, Learn with Reshu
Polymorphism in Java Method Overriding and Method OverLoading in Java Java Polymorphism Polymorphism means "many forms", and it occurs when we have many classes that are related to each other by inheritance. Like we specified in the previous Blog; Inheritance lets us inherit attributes and methods from another class. Polymorphism uses those methods to perform different tasks. This allows us to perform a single action in different ways. Polymorphism are two types Method Overriding : It calls as compile time polymorphism or static or early binding. Method Overloading: It calls as Runtime polymorphism or dynamic or late binding. For example, think of a superclass called Animal that has a method called animalSound() . Subclasses of Animals could be Pigs, Cats, Dogs, Birds - And they also have their own implementation of an animal sound (the pig oinks, and the cat meows, etc.): This is a example o...
Comments
Post a Comment
Please do not comment any spam link in the comment box