Data Types
- It is a set (range) of values which has similar characteristics.
- It is a collection of data with a value which has a meaning and its characteristics.
- It determines the type of the data which is held by a variable.
Example:
int x;
Where, ‘int’ is an integer data type and, x is a variable.
In the above example it shows that the variable ‘x’ can store only the integer type value.
Data Types | Memory Size |
Char | 2 bytes |
Boolean | 1 bit |
Short | 2 bytes |
Int | 4 bytes |
long | 8 bytes |
Float | 4 bytes |
Double | 8 bytes |
Example Program:
package Sample;
public class DataTypes {
public static void main(String[] args)
{
int i = 5; // integer
float f = 5.99f; // floating point number
char c = 'A'; // character
boolean b = true; // boolean
String Text = "ScriptWithMe"; // String
System.out.println(i);
System.out.println(f);
System.out.printl(c);
System.out.println(b);
System.out.println(Text);
}
}
Output:
5
5.99
A
true
ScriptWithMe
Variables
- To store values in memory, we need to reserve some space which is done using a variable.
- During the execution of a program, we can modify the value of a variable.
TYPES OF VARIABLES:
- Local Variables.
- Instance Variables.
- Static Variables.
LOCAL VARIABLE:
- If a variable is defined within a block or constructor, or method, then it is known as a Local Variable.
- Its initialization is mandatory.
Example:
Output:
INSTANCE VARIABLE:
- If a variable is declared inside a class when an object of the class is created and destroyed when an object is destroyed, then it is known as Instance Variable.
- It is a non-static variable.
- It is declared in a class but not inside the method, block or constructor.
- Unlike local variables, here, we can use an access specifier along with an instance variable.
- It always gets a default value.
- Its initialization is not mandatory.
- It cannot be reinitialized directly with a class.
- It can be accessed only by creating objects.
- Each object has its separate copy of the instance variable.
Example:
Output:
STATIC VARIABLE:
- Its declaration is similar to an instance variable, and the only difference is that the static variables are declared using the keyword “static”.
- It is created at the beginning of program execution and destroyed automatically when execution end.
- Its initialization is not mandatory.
- We can only have one copy of the static variable per class.
- As static variables are common to all the class objects, changes will be reflected in other objects.
- We need not create an object of that class for accessing the static variable, and we can simply access the variable as className.variableName
Example:
Output:
Java Reserved Keywords
- There are 49 reserved keywords defined within Java.
- These 49 keywords can’t be used as names for a variable, class, or method.
abstract |
continue |
goto |
package |
synchronized |
assert |
default |
if |
private |
this |
boolean |
do |
Implements |
protected |
throw |
break |
double |
import |
public |
throws |
byte |
else |
instanceof |
return |
transient |
case |
extends |
int |
short |
try |
catch |
final |
interface |
static |
void |
char |
finally |
long |
strictfb |
volatile |
class |
float |
native |
super |
while |
const |
for |
new |
switch |
|
Java Reserved words |
- The const and goto keywords are reserved words but not used.
- In addition to the above keywords, Java also reserves the following: true, false, and null. These are values defined by Java, and these words are not used for the names of variables, classes and so on.
Who is the course for?
- This course is designed for the students, employees, software programmers who want to learn Java programming from scratch to end.
- After successfully completing this course you will be able to understand how the Java programming works and use it in the real time environment.
Prerequisites before starting this course:
- Before entering into this course you should have the basic understanding of how computer technology works.
- If you don’t have any experience in Java or any other programming language then this course is for you.
- If your intermediate level of knowledge in Java programming and you want to enhance your Java skills to advance level then this course is for you.
- All you need is just any of the one device mobile, laptop, or PC and internet connection.
Questions 🙵 Answers.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eu orci faucibus orci malesuada semper eget non tellus. Cras sed dignissim purus. Mauris varius neque leo, eu pellentesque justo venenatis et. Sed ultricies risus non turpis tempus, nec nulla suscipit. In comdo urna eu turpis accumsan, et viverra mauris fringillaCras interdum
Video 48 Min + 2 Min read to complete
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eu orci faucibus orci malesuada semper eget non tellus. Cras sed dignissim purus. Mauris varius neque leo, eu pellentesque justo venenatis et. Sed ultricies risus non turpis tempus, nec nulla suscipit. In comdo urna eu turpis accumsan, et viverra mauris fringillaCras interdum
Video 48 Min + 2 Min read to complete
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eu orci faucibus orci malesuada semper eget non tellus. Cras sed dignissim purus. Mauris varius neque leo, eu pellentesque justo venenatis et. Sed ultricies risus non turpis tempus, nec nulla suscipit. In comdo urna eu turpis accumsan, et viverra mauris fringillaCras interdum
Video 48 Min + 2 Min read to complete
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eu orci faucibus orci malesuada semper eget non tellus. Cras sed dignissim purus. Mauris varius neque leo, eu pellentesque justo venenatis et. Sed ultricies risus non turpis tempus, nec nulla suscipit. In comdo urna eu turpis accumsan, et viverra mauris fringillaCras interdum
Video 48 Min + 2 Min read to complete
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eu orci faucibus orci malesuada semper eget non tellus. Cras sed dignissim purus. Mauris varius neque leo, eu pellentesque justo venenatis et. Sed ultricies risus non turpis tempus, nec nulla suscipit. In comdo urna eu turpis accumsan, et viverra mauris fringillaCras interdum
Video 48 Min + 2 Min read to complete