0% found this document useful (0 votes)
27 views12 pages

Notes (27sept2024 (

The document discusses the basics of Java programming, including how to check Java versions, create directories, and write simple Java programs. It explains the structure of Java classes, the importance of the main method, and how the Java Virtual Machine (JVM) executes Java bytecode. Additionally, it introduces JShell as a tool for interactive Java coding and highlights various commands and concepts related to Java syntax and structure.

Uploaded by

ysanjaysahu0035
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views12 pages

Notes (27sept2024 (

The document discusses the basics of Java programming, including how to check Java versions, create directories, and write simple Java programs. It explains the structure of Java classes, the importance of the main method, and how the Java Virtual Machine (JVM) executes Java bytecode. Additionally, it introduces JShell as a tool for interactive Java coding and highlights various commands and concepts related to Java syntax and structure.

Uploaded by

ysanjaysahu0035
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Lectue 3

Covereol

"Dndeukndg
-flatpem Deperdenay
Jsheol ntoduken
vs VS.

ommans:
Open Gmmad prompt & wate -
Javac - Vesion
L Java -veson
vesjon
jon installed o
to check we have Cvect JDk
o.4
Java ( 2). o. 4
fr the
Caue (Rupop) it is she ston commad
Conm hd & ves on hhi.o.u
Java
In
Text
So how we cel) wte o
elitor Kels open Notehd & wnte.
fut ceate a duecloy (fidey)
in wich we eil) save Jaro pogsm'.
Command i’ md aapgn
’name the

mkdiy

md os mko Comind to make


ma duetty
w Can Uye ea he
clasngme

kequad clais fustfopan


puble stehe vord main (Sting[] aggs
welome toiJeng's Lechua);
System.ou pmustihC"Hello
3

fRatagam jove name


44me ?
Heae we an have
Bame fr eveug Java Pm
A e Hneed not be to dave hiy fle
name fo hyve both
public then iF s nece uy
>But if the cles is auganz o the
ton Code
rame same fox befte
clas hame & fle|prgam blce to make t acesiLle
we declae
clas
’ And Genecably we dott declaue it ppublie then the class
e hot be wed in
eveycehexe , pnvae
mery ? can
wld be packap
anothe pachage clases, makigi easle to
>Lpachyos helps gioup aeatd

Packyes deil Ra e.
#is simi lau to folders on gou Kiptp
who
Ca thu Aame name Conentin s et by Sun, go tat eveyone
Codes in Jave oalstant ay haming oles.
eil have 4 Cohsistent
hy baevt we incleded any heacdey oo packae hee
ke we include in C&Ctt ( #inclydle &tdioh> &
<
#include <ieshream>) to prgom vsok ?
Ans: Tke Jara.foy
king prcka n autonh ally imporkd by the
Jave Compile for erey Jav progem So ho need to
wAnt

>But t we can to use clases fom othe packs, then


we have b import thoye
hose explicitly.
Ls one the Core in
java
Contains flin damendal clases that aue asenhad for ave
pgmnig 9 Systm, Shong, okyrd, Thaed, Moth (cto
pufam baK mathemhcl fenchn), Excephen ct.
the Comp? ethon & Exerhen flw He
Undestandg

Soe
Gomoiler
Codle

je fle -chws fle


Skp2- £neruckon;.

Jvy oloo||-
Byte
Code Oufpdt
-class
is an instuchon ded od
syecade kn
is"epretntad by e bit (one byte). Hence it is
bgtec de
onvet byteCede os Jm coorks?
How Jvm
’Jv is abstact campahing Batl-y machine hang
Înstuehon dd(bylec ole) & nmai pulates mimong
time
but it khous

A class fle co ia huel


hteing Java Vis
He
the clas le format. ymbol table. and
Machine intuucton (or bytecooeg) and a
deme othe ancil lhy infomaton
he
RMecute He
when we Rvecute CommodJave Heladenny then
Jrm waould bo launched meshg qn ihetsce of Jvm wouled
be ceated in meimong and t ajo has aome Jvm memoy
Now clas lae lod the cas fle int memoy (Jvm
mtinny). naw the byke code wnld be veufed by byteole
yfrode
veifuto Hat the saeee byteo de adheest He
ense Hat the
te of he java Ranguaye &doesnt viola te acres
bo do dome othe Che kiy on byke co de.
Then i evetig is ok in Hhe byteode, execuhon eng
exe ustes He ingtchon oith the
help o inteypreky
JIT CGmpile, Intepeteu inlep»eds Hhe czde Joe Rine &
exeuk Aome Calleol methods JIT ompile
Co nes int pichue & may Conpile into machine Code &
then this macine Codle s cathed in memony . Subsequent
Call to Hat method eill exe cuke the nate code fnstea
the
up exeruton.
Ard then ou get the outped.
the Stuctue of
Urdeuad
dlaus fistfagum Name of the cla

3
class, we shudd folls Uppe, Comel (se or
fwkde namig the
fasal Case Conveion]

mun

hethd

Cah acces it. f w


method su publie do tHt evepne
min leill not be 4Ble to access it
?! public Jvm
dont make
Pagn will be Compiled corecly but uil
un il)l
main meftod not found '" So lwe e ta
Take it publie to ma ke it aCcesible for Jvm hae to

frgum txeuton atat on main()) mehod.


P4 sac allos the JvM to invoke the main Declaing
An însne f the class CondehiNg . methad with
cueahy nain vee nol <tc, Hhe JvM would
neeol to 4ett arn
ebject of he clas befue tnvoking the method., which wold
lead to Complex1hes .
’hehe mein method iy oirecty Called
the Jv when
stet. The dttC mmain method a
ehty point in Java as well as in dome othe
pongumming
Langas, maling easie, fr the dvm &developou fo
Csqnse the Pony hbing pont.
Vod is justa retn type, void means thee is no ehun value
main is the name o ths method.
l we dewt declae main mehod as stehe, pngum
ull be
Carnpi led corectly but it uaill nod nn, 1t wall gpve eur
main metho M hot slate
thet aue ajumenth toto main method Thu
metho must bbegiven qnd the aungy
Hke ony auy nime other theas
ag (ewpCan wsnt)
also fne
It is a way to pas Comn9nd ine agomens lweasl dlus
ths tn in Sate vides
The
meted s. pod
of the anadud Jova me}hod signaae for te pgum tod
point, Wthoud i4 JVM wont reognye the mn method
& may hot be able to atad the poum
Withoud Stig] becays usethe,o puguom all tonple ueafly
but wil) na un the violation f the co huento
JVM.

>rSgkm.ou. pritn (" Hela Lwelamt to deme Lectue')


y Biu u q cosy to pnn outpud to shandad otpt in
Java.
ahy
piotln(o is o methed in iniSHream clau bsed t prtnt ang
Cugument pased to H adds anes ine to he output
out is an irsance object Pontshream claes ad out s
statie membe of Systin clas. od membelfeld repregent
the standad output stearn (unly the Gonele) te'ahich
text and dada cin be pandeol.
J a fral clau in the farg. Ling Psckage. Sne
he Jva,
clas

provide, vajeus felds & metods f sandad input,


odpud standd output
- So Bejally Sydtm o efou te the
Connected to the Coryele. we can crect
e anthe outod deshnation if

) we Can Use nnt() method athee than pnnthn C). pnntl


newline after He output
javg-io. fonStrea rs

put Pontin

|Syskm.od.po.ttey
brachce Queghons
Cue wdte a pogum to pont you name, age & hibby
ines. hty
Que wika prgum pont the foHucing patteu -

Que Waka prgsm e pnt dmef inteyes (lo +1) iy


Syptom out. pan) &Sysken cod.pontnU
Cod e
Que 9 wlat wuld be the output of the foll g
clos Preche'ngam
pable she void mawnl
lotis);
System out-pmt (("lo")
out ponth
Sypem. outpontln
Systm. outpatin C lotIs);
sstem.out. pr
Syskem.outpand('a'),
otooduchn to Jshel
JShell is an fnde etive tool fox leig the Java pmggmn
ige ano prottypiny Java Code.Loop (REPL), which
5VShel) io a Read- Eva agte-fint
evalustes declaudion, shtm enu & expreio ay
enteucd é imeditely dhe the esalb
line
fom the Comnand
JShell wes

and sbppi shel! Coromhd on the


To tat JShelt , ente the
Command Rine
mut be îngtallel on
NoTE: JDk9 or bighe vesions

To exit JShell, ente /exit ye the -v ophon:


!

JShel0 in veboye nmode,


To staut
Jshele -V

statcneh; methodu, veyable, & clu


+ Jshel ceplh JaA Ihese pieces t Java
defntion; impord e expressions,
srippet
shele > it a - ;
a

| aeated vaugble vebose modd


we ae in

aololeol t the end a a Cmplek


NoE- Semicolarny out automey
digpet if not tnteedl
when qh txpresien is entereol that doewt have
a meol vaunsle. aa su9tch veuable is eeated da Hat
t value Can
be rfeeneed Aote
shell > 345

| aeted scteh vaugLle I : int

’ Jshell > vo)d dhuply(){


Syster out.pant ("Hello boeleomt to Jenny's letus)
|eeeted method g duply(
Jskele > diaply ()
>

Hello lweltene foto Jeny's Lectues


hee ae_many Jshell comnghds ued to Contol he ehulyoh ntt
opomatn
(vas -give, nformetion abut cuue»t veuable
/methods - qves infe abot cauent mettod
/list - gives lit o entecd anppet
NoTE, stety
&quto maticly executd befee sheo steul, do that
Can get o aosk qekly. dhcuw all He enties foom
we can

we e last tad comand


all the JShell ommonds
So JShe@ is q REPL Fo Java whieh meg
w # deads Hte Comnahd or code sesmert be type
(D
ti ft eva lustes and exeruk the code
the develpe
wnte ode to outpud he vesulte
back for inore
input
NoTEJShele doesnt replace an lDE.

mnd to be treuted.
Stafemed- he Complehe c
to do semething
Gmputer t
Hsan istuchon f
(ss);
pato satements
egpsionu ae
Expression!-
An expresion value when eralasted
opeuands Hat psduce o Tesult co
3+
(Q+5)* 3
aluag tedo a velae and on be pad ot
eypuesien
shetomebt
int a = St3;=Shtement
shftments

when evaluted &Stetemer


ipiesiers pooolre q vabe
n
actin and oy y not
Contin
hot contais expresiny
ue Cant bwe have mo Cas in q Java flep G
than on
Can hove but only one cles Con be publie
name ot publhe cass & home of ave fle must
the
be 4ame. clau al clese

Gn be aithat pulte apeufe,


we hae 3 clase is the jare fle. So te campilahon
Que Suppe ue hut
thee cls iles woulel be geAeed- So in this Case we
qble to tdertty which olas Cortas main methedl (enty point)

One Soluon is check He doee codle & fh oud w ch class


hs min method but tbis is tediouy cwok fr any one. So
Cohveten nuley set by Sun,

So i recon4Nded fo have one


you hae mulhple clases in dinge v fle then mke
clos publie wich is haung so
sAve the file pyblie clay home
whch eles hes maun,

&o to be tecuted.
clasey in
Bete to have nesteol clases f yoo

Had the public cloy should have nainmetho

You might also like