Selenium With Java3-Data Types and Packages Intro
Selenium With Java3-Data Types and Packages Intro
When we specify the datatype, the system can understand the memory requirements
and the operations allowed on the corresponding variables.
ex : int a = 100;
Data Type
Size: 32 bit i.e n = 32 0 to 31
Value: -232 to 232 – 1 -2n to 2n -1
8 bits - 28 to 28-1 -128 to 127
16 bits -216 to 216-1 -32,768 to 32,767
32 bits -232 to 232-1 -2,147,483,648 to 2,147,483,647
Java actually uses Unicode, which includes ASCII and other characters from
languages around the world.
If we try to store a value bigger than that we will get a compilation error.
To work with single characters (ASCII values up to 127), we can use byte type as it uses only 1
byte of memory (against char which takes 2 bytes of memory).
SHORT
LONG
To store a value bigger than int range, we should use long type.
When using a constant bigger than int range, we should suffix it with ‘l’ or ‘L’ to indicate it to be
a long value.
long c=123456789012345L;
CHAR
The first 256 (numbered from 0 to 255) characters of UniCode are the ASCII set of characters
only.
FLOAT
float b=3.6f
float c=(float)3.6
DOUBLE
double a=3.9;
double b=834;
double c=’A’;
Boolean
boolean a=true
boolean g=10<20;
boolean d=false
CSE IS A PACKAGE.
EMPLOYEE IS A CLASS
class employee
{
CSE
EE
Created package
i.e. by using package name at the top of the program and saving it in the package directory.
Naming Conventions
college.tech.cse.Employee
college.tech.ee.Employee
Packages are
Built-in Packages
User-defined packages
Built-in Packages consist of a large number of classes which are a part of Java API.
java.lang
java.io
java.util
java.applet
java.awt ---
java.net
import java.applet.addApplet.*;
import java.lang
java.lang Contains language support classes (e.g classed which defines primitive data types,
math operations). This package is automatically imported.
println(“Welcome to Java” );
println(“Hello World!”);
java.util Contains utility classes which implement data structures like Linked List,
Dictionary and support ; for Date / Time operations.
Contain classes for implementing the components for graphical user interfaces (like button ,
menus ).
First we create a directory by the name myPackage (name should be same as the name of the
package).
Then create the MyClass inside the directory with the first statement being the package name.
package mypackage ;
System.out.println(s);
}
Note :
Name of the package must be same as the directory under which this file is
saved
import myPackage.MyClass;
import java.io;
Object.getNames (name);
System.out.println(“welcome”)
Note :
//import java.io.myPackage.MyClass;
import java.io;
import myPackage.*;
Subpackages
import java.util.vector ;
Class vector
{
Public static void main(string args[ ]
}
import java.util.*;
Based on the data type of a variable, the operating system allocates memory and decides what
can be stored in the reserved memory.
By assigning different data types to variables, you can store integers, decimals, or characters in
these variables.