Beruflich Dokumente
Kultur Dokumente
UNIVERSITY OF ENGINEERING
&
MANAGEMENT, JAIPUR
SUBMITTED BY:
SAURABH KUMAR
Enrollment No – 12016002001037
This is to certify that the project report entitled “Training on core java”
submitted by Saurabh Kumar (Roll:12016002001037) in partial fulfillment
of the requirements of the degree of Bachelor of Technology in Computer
Science & Engineering from University of Engineering and Management,
Jaipur was carried out in a systematic and procedural manner to the best
of our knowledge. It is a bona fide work of the candidate and was carried
out under our supervision and guidance during the academic session of
2016-2020.
_______________________
_______________________ ______________________
The endless thanks goes to Lord Almighty for all the blessings he has
showered onto me, which has enabled me to write this last note in my
research work. During the period of my research, as in the rest of my life, I
have been blessed by Almighty with some extraordinary people who have
spun a web of support around me. Words can never be enough in
expressing how grateful I am to those incredible people in my life who
made this thesis possible. I would like an attempt to thank them for
making my time during my research in the Institute a period I will
treasure. I am deeply indebted to my research supervisor, Professor
Sauvik Bal to give me such an interesting thesis topic. Each meeting with
him added in valuable aspects to the implementation and broadened my
perspective. He has guided me with his invaluable suggestions, lightened
up the way in my darkest times and encouraged me a lot in the academic
life.
SAURABH KUMAR
TRAINING ON CORE JAVA
WEBTEK LABS
5/6/2017
WEBTEK LABS
Introduction to Java
Java is one of the world's most important and widely used computer
languages, and it has held this distinction for many years. Unlike some other
computer languages whose influence has weared with passage of time, while
Java's has grown.
As of 2015, Java is one of the most popular programming languages in use,
particularly for client-server web applications, with a reported 9 million
developers using and working on it.
Evolution of Java
Java was initially launched as Java 1.0 but soon after its initial release, Java 1.1
was launched. Java 1.1 redefined event handling, new library elements were
added.
In Java 1.2 Swing and Collection framework was added
and suspend(), resume()and stop()methods were deprecated from Thread class.
No major changes were made into Java 1.3 but the next release that was Java
1.4 contained several important changes. Keywordassert, chained exceptions
and channel based I/O System wasintroduced.
Java 1.5 was called J2SE 5, it added following major new features :
Generics
Annotations
Autoboxing andautounboxing
Enumerations
For-eachLoop
Application of Java
Java is widely used in every corner of world and of human life. Java is not only
used in softwares but is also widely used in designing hardware controlling
software components. There are more than 930 million JRE downloads each
year and 3 billion mobile phones run java.
Following are some other usage of Java :
1. Developing DesktopApplications
2. Web Applications like Linkedin.com, Snapdeal.cometc
3. Mobile Operating System likeAndroid
4. EmbeddedSystems
Difference between JDK andJRE
JRE : The Java Runtime Environment (JRE) provides the libraries, the Java Virtual
Machine, and other components to run applets and applications written in the
Java programming language. JRE does not contain tools and utilities such as
compilersor debuggers for developing applets andapplications.
JDK : The JDK also called Java Development Kit is a superset of the JRE,
and contains everything that is in the JRE, plus tools such as the
compilers and debuggers necessary for developing applets and
applications.
FIRST JAVA PROGRAM
classHello
}
Class
} : class keyword is used to declare classes in Java
Public : It is an access specifier. Public means this function is visible to all.
Static : static is again a keyword used to make a function static. To execute a
static function you do not have to create an Object of the class. The main()
method here is called by JVM, without creating any object for class.
Void : It is the return type, meaning this function will not return anything.
Main : main() method is the most important method in a Java program. This is
the method which is executed, hence all the logic must be inside the main()
method. If a java class is not having a main() method, it causes compilation
error.
String[] args : This represents an array whose type is String and name is args.
We will discuss more about array in Java Array section.
System.out.println : This is used to print anything on the console like
printf in C language.
Step 3: Open command prompt and go to the directory where you saved
your first java program assuming it is saved in C:\
Step 4: Type javac Hello.javaand press Return(Enter KEY) to compile your code.
This command will call the Java Compiler asking it to compile the specified file.
If there are no errors in the code the command prompt will take you to the
next line.
Step 5: Now type java Helloon command prompt to run your program.
Once a primitive data type has been declared its type can never change,
although in most cases its value can change. These eight primitive type can be
put into four groups
Integer
This group includes byte, short, int, long
byte : It is 1 byte(8-bits) integer data type. Value range from -128 to 127.
Default value zero. example: byte b=10;
short : It is 2 bytes(16-bits) integer data type. Value range from -32768 to
32767. Default value zero. example: short s=11;
int : It is 4 bytes(32-bits) integer data type. Value range from -
2147483648 to 2147483647. Default value zero. example: int i=10;
long : It is 8 bytes(64-bits) integer data type. Value range from -
9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Default value
zero.
example: longl=100012;
Floating-PointNumber
This group includes float, double
Characters
This group represent char, which represent symbols in a character set, like
letters and numbers.
char : It is 2 bytes(16-bits) unsigned unicode character. Range 0 to
65,535. example: char c='a';
Identifiers in Java
All Java components require names. Name used for classes, methods,
interfaces and variables are called Identifier. Identifier must follow some
rules. Here are the rules:
Allidentifiers
muststartwitheitheraletter(atozorAtoZ)orcurrencycharacter($) or an
underscore.
Variable in Java
When we want to store any information, we store it in an address of the
computer.The naming of an address is known as variable. Variable is the name
of memory location.Java Programming language defines mainly three kind of
variables.
1. Instancevariables
2. StaticVariables
3. LocalVariables
String name;
intage;
}
Here name and age are instance variable of Student class.
Static variables in Java
Static are class variables declared with static keyword. Static variables are
initialized only once. Static variables are also used in declaring constant along
with final keyword.
classStudent
String name;
intage;
staticintinstituteCode=1101;
Features of Array
It is always indexed. Index begins from0.
It is a collection of similar datatypes.
It occupies a contiguous memorylocation.
Array Declaration
Syntax :
datatype[] identifier;
or
datatype identifier[];
Java Operators
Java provides a rich set of operators environment. Java operators can be
divided into following categories:
Arithmeticoperators
Relationoperators
Logicaloperators
Bitwiseoperators
Assignmentoperators
Conditionaloperators
Miscoperators
Arithmetic operators
Arithmetic operators are used in mathematical expression in the same way
that are used in algebra.
Operator Description
% remainder of division
Operator Description
> Check if operand on the left is greater than operand on the right
Logical operators
Java supports following 3 logical operator. Suppose a=1 and b=0;
|| Logical OR (a || b) is true
| Bitwise OR
^ Bitwise exclusive OR
Assignment Operators
Operato Description Example
r
= assigns values from right side operands to left side a=b
operand
+= adds right operand to the left operand and assign a+=b is
the result to left same as
a=a+b
-= subtracts right operand from the left operand and a-=bis same
assign the result to left operand as a=a-b
classStudent.
{
String name;
introllno;
intage;
}
Constructors in Java
classCar
String name ;
String model;
Car() //Constructor
name="";
model="";
Types of Constructor
There are two types of constructors:
DefaultConstructor
Parameterizedconstructor
Car c = new Car() //Default constructor invoked
Car c = new Car(name); //Parameterized constructor invoked
Constructor Overloading
String name;
String team;
intage;
name ="";
team ="";
age = 0;
name = n;
team = t;
age = a;
name = ckt.name;
team = ckt.team;
age = ckt.age;
publicString toString()
{
{
System.out.println(c3);
c1.name = "Virat";
c1.team= "India";
c1.age = 32;
What
}
is constructor chaining in Java?
}
Constructor chaining is a phenomena of calling one constructor from
another constructor of same class. Since constructor can only be called
from another constructor in Java, constructor chaining is used for this
purpose.
classTest
Test()
this(10);
Test(intx)
System.out.println("x="+x);
}
Java thiskeyword
this keyword is used to refer to currentobject.
this is always a reference to the object on which method wasinvoked.
this can be used to invoke current classconstructor.
this can be passed as an argument to anothermethod.
class Box
{
Double width, height,depth;
Box (double w, double h, doubled)
{
this.width =w;
this.height =h;
this.depth =d;
}
}
Here the this is used to initialize member of current object.Such
as, this.width refers to the variable width of the current object that
has invoked the constructor. width only refers to the parameter
received in the constructor i.e the argument passed while calling the
constructor.
privateString name;
public Car()
}
publicCar(String n)
}
Access and Non-Access Modifiers in Java
Modifiers are keywords in Java that are used to change the meaning of a variable
or method. In Java, modifiers are categorized into two types:
1. Access controlmodifier
1. Final
2. Static
3. Transient
4. Synchronized
5. Volatile
Inheritance (IS-A relationship) in Java
Purpose of Inheritance
1. It promotes the code reusabilty i.e the same methods and variables
child/sub/derivedclass.
Example Of Inheritance:
3. class Parent 4. {
5. public voidp1()
6. {
7. System.out.println("Parent method"); 8. }
9. }
10.public class Child extends Parent { 11.
12. public voidc1()
13. {
14. System.out.println("Childmethod");
15. }
16. public static void main(String[]args)
17. {
18. Child cobj = new Child();
}
Method overloading and Method overriding seems to be similar concepts
but they are not. Let's see some differences between both of them:
}
classcmd
for(inti=0;i<args.length;i++)
System.out.println(args[i]);
}
Execute this program as java cmd 10 20 30
}
}
Interfaces in Java
Interface is a pure abstract class .They are syntactically similar to classes, but
you cannot create instance of an Interface and their methods are declared
without any body. Interface is used to achieve complete abstraction in Java.
When you create an interface it defines what a class can do without saying
anything about how the class will do it.
All methods declared inside Java Interfaces are implicitly public and
interfaceMoveable
intAVG-SPEED = 40;
voidmove();
Difference Vehicle
between an Vehicle();
vc = new interface and an abstract class?
vc.move();
.
CONTENTS
INTRODUCTION
DIFFERENCE BETWEEN JDK AND JRE
PRIMITIVE DATATYPES
STATIC VARIABLE
ARRAY
OPERATORS
CONSTRUCTOR
THIS KEYWORD
MODIFIERS
INHERITANCE
COMMAND LINE ARGUMENT
INTERFACE
CONCLUSION
REFERENCE
REFERENCES
www.google.com
www.wikipedia.com
www.studymafia.org
www.javatutorialpoint.com