Post on 02-Jun-2018
8/10/2019 Advanced Java Lecture-1
1/48
1
Lecture 1: Overview of Java
8/10/2019 Advanced Java Lecture-1
2/48
2
Object OrientedLanguages??
Object Oriented Languages arebased upon Classes and Objects.
Helps us to create Real WorldApplicationsvery easily
8/10/2019 Advanced Java Lecture-1
3/48
3
JavasHistory
Developed by Sun Microsystems (ames!osling"
# general$purpose object$oriented language
Oa% $ &n 1''1 ava $ &n 1''
Hot ava ) *irst ava +nabled ,ro-ser
etscape avigator ) &n 1'' to incorporateava /ec0nology
,ased on
Designed 4or easy 5eb&nternet applications
8/10/2019 Advanced Java Lecture-1
4/48
6
Javas Magic : yte Code
/0e %ey t0at allo-s java to solvebot0 t0e security and t0e portabilityproblems
!ource Code yte Code
Output
Co"piler
(avac" J#M
(ava 7un/ime+nvironment"
8/10/2019 Advanced Java Lecture-1
5/48
ava8rogram
9irtualmac0ine
avaompiler
Mac0inecode
ava&nterpreter
,yte code
Sourcecode
,yte ode
9irtual Mac0ine 7eal Mac0ine
8/10/2019 Advanced Java Lecture-1
6/48
:
yte Code
/ranslating a java program into bytecode0elps ma%es it muc0 easier to run aprogram in a -ide variety o4 environments.
,yte ode is interpreted (-0ic0 0elps toma%e it secure"
&nterpretation is slo-er but t0e use o4bytecode enables t0e java run$time systemto e;ecute programs muc0 4aster t0an youmig0t e;pect.
8/10/2019 Advanced Java Lecture-1
7/48
Java Class Lifecycle
Source File
(.java)
Class File
(.class)
Compiler(javac)
Java Virtual Machie (JVM)
ClassLoa!er
"#teco!e Verifier
$terpreter
Securit# Maa%er
Operati% S#stem
&etwor'
or
File S#stem
securit# %atewa#
8/10/2019 Advanced Java Lecture-1
8/48
oats=c0aractersE
O4ten -ant to 0ave an array o4
objects Students= ,oo%s= Loans EE
eed to 4ollo- 3 steps.
8/10/2019 Advanced Java Lecture-1
39/48
Declaring t0e #rray
1. Declare t0e array
Student sPQF t0is declares s as an object
2 .reate t0e array sPQ G ne9StudentP1AQF
t0is sets up 1A spaces in memory t0at can0old re4erences to Student objects
3. reate Student objects and addt0em to t0e array sPAQ G ne9Student("F
8/10/2019 Advanced Java Lecture-1
40/48
8/10/2019 Advanced Java Lecture-1
41/48
#rrays are @;ed lengt0
Lengt0 is speci@ed at create time
&n java= all arrays store t0eallocated si?e in a variablenamed lengt0J.
5e can access t0e lengt0 o4arrays as arrayame.lengt0
e.%. it stu!ets.le%th()/ 00 G
#rrays ) Lengt0
8/10/2019 Advanced Java Lecture-1
42/48
Strings in java
8/10/2019 Advanced Java Lecture-1
43/48
Strings represent a seBuence o4 c0aracters./0e
easiest -ay to represent a seBuence o4c0aracters
in java is by using a c0aracter array.
+;ample0ar c0ar#rrayPQGne- c0arP6QF
c0ar#rrayPAQGTjUF
c0ar#rrayP1QGTaUFc0ar#rrayP2QGTvUF
c0ar#rrayP3QGTaUF
8/10/2019 Advanced Java Lecture-1
44/48
Strings may be declared and created as 4ollo-s
String stringameF
stringameGne- String(stringJ"F+g
String @rstnameF
@rstnameGne- String(#nilJ"F orString @rstnameGne- String(anilJ"F
8/10/2019 Advanced Java Lecture-1
45/48
Li%e arrays= it is possible to get t0elengt0 o4
string using t0e lengt'met0od o4 Strinclass
int mG@rstname.lengt0("F
ava strings can be concatenated usingt0e
Operator. +g=
String 4ullameGname1name2F J J J
8/10/2019 Advanced Java Lecture-1
46/48
String arrays
5e can create and use arrays t0at containstrings.
/0e statement
String item#rrayPQGne- StringP3QF
5ill create an item#rray o4 si?e 3 to 0oldt0ree string
constants
8/10/2019 Advanced Java Lecture-1
47/48
String met0ods
String class de@nes a number o4 met0odst0at allo- us to
accomplis0 a variety o4 stringmanipulation tas%s
8/10/2019 Advanced Java Lecture-1
48/48
S2Gs1.toLo-eraseF converts string s1 tolo9ercase
S2Gs1.topperaseF converts string s1 to
uppercaseS2Gs1.replace(T;U= UyU"F replace all appearance o& ,
9it' y
S1.eBuals(s2"F returns true i& s1 is e;ual to s3
S1.eBuals&gnorease(s2"F returns true i& s1