Professional Documents
Culture Documents
UCSC012 Internet Programming: Dr.S.Sumathi, Assistant Professor - Senior Grade Sri Ramakrishna Institute of Technology
UCSC012 Internet Programming: Dr.S.Sumathi, Assistant Professor - Senior Grade Sri Ramakrishna Institute of Technology
UCSC012 Internet Programming: Dr.S.Sumathi, Assistant Professor - Senior Grade Sri Ramakrishna Institute of Technology
INTERNET
PROGRAMMING
Dr.S.Sumathi,
Assistant Professor – Senior Grade
Sri Ramakrishna Institute of Technology
Introduction to Java Programming
■ Java is a class based object oriented programming language that is used in distributed environment on the internet .
■ It is a high level programming language that is easy to read and understand.
■ Java is popularly used in console, graphical interface, web and mobile applications, gaming applications, embedded
systems.
■ Java is also used as a software to develop devices such as washing machine, televisions, air conditioners, online
banking and shopping.
■ James Gosling and Sun Microsystems – 1991.
■ Write once and run anywhere – Code will be written only once but it run on any platforms
■ Java Standard Edition – core libraries like java.lang, java.util
■ Java Enterprise Edition – JSP, Java Servlets
■ Java Micro Edition – cell phones, set top boxes, hand helds
■ class Example
■ {
■ public static void main(String args[])
■ {
■ System.out.println(“Hello welcome to Java Programming”);
■ }
■ }
■ C:\>javac Example.java
■ C:\> java Example
■ dataType[] arrayRefVar;
– Eg: double[] myList;
■ Create the array using new operator
– arrayRefVar = new
dataType[arraySize];
■ It creates an array using new
dataType[arraySize].
■ It assigns the reference of the newly created
array to the variable arrayRefVar.
■
double[] myList = new double[10];
■ The unary bitwise complement operator "~" inverts a bit pattern; it can be
applied to any of the integral types, making every "0" a "1" and every "1"
a "0". For example, a byte contains 8 bits; applying this operator to a value
■ The bitwise & operator performs a
whose bit pattern is "00000000" would change its pattern to "11111111".
bitwise AND operation.
■ The signed left shift operator "<<" shifts a bit pattern to the left, and the
signed right shift operator ">>" shifts a bit pattern to the right. The bit
■ The bitwise ^ operator performs a
pattern is given by the left-hand operand, and the number of positions to bitwise exclusive OR operation.
shift by the right-hand operand. The unsigned right shift operator ">>>"
shifts a zero into the leftmost position, while the leftmost position after
■ // infinite loop
■ for ( ; ; ) {
■
■ // your code goes here
■ }
■ A class is a blueprint from which ■ A class can contain any of the following variable types.
individual objects are created. ■ Local variables − Variables defined inside methods,
constructors or blocks are called local variables. The
variable will be declared and initialized within the method
and the variable will be destroyed when the method has
completed.
■ Instance variables - A variable which is created inside
the class but outside the method is known as an instance
variable. Instance variable doesn't get memory at compile
time. It gets memory at runtime when an object or instance
is created. That is why it is known as an instance variable.
■ Class variables − Class variables are variables declared
within a class, outside any method, with the static
keyword.
■ In Java, a method is like a function which is used to expose the behavior of an object.
■ Advantage of Method
– Code Reusability
– Code Optimization
■ The new keyword is used to allocate memory at runtime. All objects get memory in
Heap memory area.
■ An entity that has state and behavior is known as an object e.g., chair, bike, marker, pen,
table, car, etc. It can be physical or logical (tangible and intangible). The example of an
intangible object is the banking system.
■ An object has three characteristics:
– State: represents the data (value) of an object.
– Behavior: represents the behavior (functionality) of an object such as deposit,
withdraw, etc.
– Identity: An object identity is typically implemented via a unique ID. The value of
the ID is not visible to the external user. However, it is used internally by the JVM
to identify each object uniquely.
■ For Example, Pen is an object. Its name is Reynolds; color is white, known as its state.
It is used to write, so writing is its behavior.
■ An object is an instance of a class. A class is a template or blueprint from which
objects are created. So, an object is the instance(result) of a class.
/Java Program to illustrate how to define //creating main method inside the Student class
a class and fields public static void main(String args[]){
String name; s1.insertRecord(111,"Karan");
s2.insertRecord(222,"Aryan");
void insertRecord(int r, String n){
s1.displayInformation();
rollno=r;
s2.displayInformation();
name=n; }
} }
class Employee{ public class TestEmployee {
public static void main(String[] args) {
int id;
Employee e1=new Employee();
String name;
Employee e2=new Employee();
float salary;
Employee e3=new Employee();
void insert(int i, String n, float s) {
e1.insert(101,"ajeet",45000);
id=i;
e2.insert(102,"irfan",25000);
name=n; e3.insert(103,"nakul",55000);
salary=s; e1.display();
} e2.display();
void display(){System.out.println(id+" "+name e3.display();
+" "+salary);} }
} }
■ By new keyword
■ By newInstance() method
■ By clone() method
■ By deserialization
■ By factory method etc.
■ In Java, a constructor is just like a method but without return type. It can also be
overloaded like Java methods.
■ Constructor overloading in Java is a technique of having more than one constructor with
different parameter lists. They are arranged in a way that each constructor performs a
different task. They are differentiated by the compiler by the number of parameters in
the list and their types.
■ There is no copy constructor in Java. However, we can copy the values from one object
to another like copy constructor in C++.
■ There are many ways to copy the values of one object into another in Java. They are:
■ By constructor
■ By assigning the values of one object into another
■ By clone() method of Object class
■ We can copy the values of one object into another by assigning the objects values to
another object. In this case, there is no need to create the constructor.