0% found this document useful (0 votes)
112 views8 pages

Manual ECS353

This document introduces Java programming language by discussing programming languages in general, describing Java's features, and providing steps to set up a development environment and write a simple "Hello World" program. Specifically, it explains how to 1) install the Java Development Kit (JDK), 2) set environment variables to run Java programs, and 3) use Notepad to write, compile with javac, and run with java a basic HelloWorld application that prints text to the console.

Uploaded by

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

Manual ECS353

This document introduces Java programming language by discussing programming languages in general, describing Java's features, and providing steps to set up a development environment and write a simple "Hello World" program. Specifically, it explains how to 1) install the Java Development Kit (JDK), 2) set environment variables to run Java programs, and 3) use Notepad to write, compile with javac, and run with java a basic HelloWorld application that prints text to the console.

Uploaded by

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

Introduction to Java

Objectives:
Introduce programming languages.
Introduce Java programming language.
Show how to set up your system environment for Java development.
Write, compile and run your frst Java application "Hello World".
1.1 Programming Languages
By programming language, we mean a set of vocaulary, grammar and
liraries that construct a language we can use to write computer programs.
! programming language consists of the following"
#ocaulary" set of meaningful keywords that have specifc meaning in
the
programming language $also called reserved words%.
Synta& $grammar%" set of rules that constraint the way in which
programs are
written. ! program that does not follow these rules has one or more
syntax
errors.
Software 'evelopment (it $S'(% that contains the following"
)iraries" also *nown as !pplication +rogramming Interface $!+I%, these
fles are previously written classes and methods that contain some
common functionality.
,ompiler" the program that translates fles written in Java language
$human language% into inary fles $machine language% in order for the
computer to e ale to e&ecute them.
Interpreter" some programming languages does not compile the source
code fle into directly e&ecutale form $native code%, ut they instead
compile it into partially compiled fle that could e e&ecuted y a
program called interpreter.
1.2 Java Programming Language
Java programming language is an interpreted programming language, that
is, when the source code is compiled into inary fle, it needs an interpreter
called Java #irtual -achine $J#-% to run it.
Java compiler is called javac.exe, and interpreter is called .ava.e&e. /igure
0.0 shows a Java technology overview.
Figure 1.1: Java technology
1.3 Setting Up Your Machine for Java Development
1o e ale to write, compile and e&ecute Java applications, you need a set of
tools called Java Software 'evelopment (it $JSDK%. 1his S'( could e
otained from Java o2cial site at http"33.ava.sun.com.
!fter downloading the installation fle $aout 45 -B% you are ready to start
the installation process.
Follow the ollowing !rocedure to !re!are your "achine.
Ste! 1" 'oule clic* on .d*6078757546windows6i8946p.e&e icon, the setup
wi:ard appears as in
#gure 1.$" First ste! o JDK setu! wi%ard
Select I accept the terms in the license agreement and clic* on Next. ,ustom
setup dialog appears as in fgure 0.;.
Figure 1.&: Setu! o!tions
It is advisale that you change the installation path y clic*ing on Change
utton and selecting the
!ath '(:)jd*' as installation directory.
!fter you have done changing the path, clic* on Next to start the installation
and wait until it<s done. When installation is complete, clic* on Finish to
terminate installation wi:ard.
Ste! $:
=ou need now to defne some environment variales to e ale to use the
tools you>ve .ust installed. 1o defne an environment variale, right6clic* on
My Computer icon on the des*top or start menu, then select Properties from
the pop6up menu. 1he System Properties dialog appears, from the top of the
dialog o& select Advanced ta as shown in fgure 0.?.
Figure 1.+: ,indows advanced settings
/rom Advanced ta, clic* on nvironment !aria"les utton, @nvironment
#ariales dialog appears as shown in fgure 0.8.
Figure 1.-: .nviron"ent /ariables
1o add new environment variale, clic* on New utton in #ser !aria"les feld,
note that you may not modify system variales unless you have
administrator privileges. Ance you clic* on New utton, variale addition
dialog appears as in fgure 0.4.
Figure 1.0: 1dding new environ"ent variable dialog box
In !aria"le name feld enter the name of your varialesB in !aria"le value
feld enter the value of the variale then clic* on $%. =ou need to add two
variales to use with J'S("
+!1H" points to in directory in JS'( home directory $e. g. c"C.d*Cin%
,)!SS+!1H" points to the folder in which you will create you Java programs
$e. g.
c"C'ocuments and SettingsCStudentC'es*topC.ava%.
2he co"!uter is now ready to be used or Java develo!"ent.
1.4 riting! "ompiling an# $unning Your %irst Java
&pplication
1o write a Java program, open the command prompt y selecting run from
start menu and entering the command cmd in the dialog o&, the command
prompt console appears, show in fgure 0.D. ,hange to the directory you
have selected as Java directory
Figure 1.3: (o""and !ro"!t
for e'ample
c"C'ocuments and SettingsCStudentC'es*topC.ava% y using cd command.
1o write a new Java program using the notepad, enter the command notepad
&lename. /or instance, we will write a class named HelloWorld, so we will use
the command notepad HelloWorld..ava $/igure 0.9%. Eote that we use a ..ava
e&tension for all Java source fles, and we always use upper case characters
in the eginning of a class name. !fter starting the notepad, it will as* you
whether you wish to create a new fle with the name specifed, confrm fle
creation. It is important to *eep in mind that fle name and class name must
e the same, otherwise the compiler will generate an error message and the
fle will not compile.
Figure 1.4: note!ad co""and with !ara"eters
In the notepad, write the following code $always *eep in mind that Java is
case6sensitive language, for e&ample if you typed ,lass instead of class the
compiler will report a synta& error%
556ello,orld.java
57 2his is "y #rst java !rogra".
75
class 6ello,orld8
!ublic static void "ain9String: ; args<
8
Syste".out.!rintln9'6ello ,orld='<>
Syste".out.!rintln9'6ow r u $day?'<>
@ 55end o "ain "ethod
@ 55end o class
When you are done with code writing, save the fle and e&it notepad.
=our source code fle is now ready for compilation, to compile a Java source
code fle, use the command javac (lename. In our exa"!leA javac
6ello,orld.java. If everything is alright, the compiler will terminate without
any messages and go ac* to command prompt as shown in fgure 0.F.
Figure 1.B: successul co"!ilation
!fter compilation, i you run dir co""and,
you will notice that the compiler generated a new fle called
6ello,orld.class, this is the inary fle J#- will e&ecute.
1o run your application, use the command .ava ClassName , for our program,
we will use java 6ello,orld,
if everything is alright, you shall see the program output on the screen.
Eotice that some lines in the program egin with 55, these are called
comments, compiler does not read comments, so whatever your write in
them it will not aGect the functionality of your program, the notations 57
and 75 declare the eginning and ending of a loc* of comments, so we call
them multi)line comments.

You might also like