Manual ECS353

download Manual ECS353

of 8

Transcript of Manual ECS353

  • 8/12/2019 Manual ECS353

    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 rst Java application "Hello World".

    1.1 Programming Languages

    By programming language, we mean a set of vocaulary, grammar andliraries that construct a language we can use to write computer programs.! programming language consists of the following

    #ocaulary set of meaningful keywords that have specic meaning in

    theprogramming language $also called reserved words%.

    Synta& $grammar% set of rules that constraint the way in whichprograms are

    written. ! program that does not follow these rules has one or moresyntax

    errors. Software 'evelopment (it $S'(% that contains the following

    )iraries also *nown as !pplication +rogramming Interface $!+I%, theseles are previously written classes and methods that contain some

    common functionality. ompiler the program that translates les written in Java language

    $human language% into inary les $machine language% in order for thecomputer to e ale to e&ecute them.

    Interpreter some programming languages does not compile the sourcecode le into directly e&ecutale form $native code%, ut they insteadcompile it into partially compiled le that could e e&ecuted y aprogram called interpreter.

    1.2 Java Programming Language

    Java programming language is an interpreted programming language, thatis, when the source code is compiled into inary le, it needs an interpretercalled Java #irtual -achine $J#-% to run it.

    Java compiler is called javac.exe, and interpreter is called ava.e&e. /igure0.0 shows a Java technology overview.

  • 8/12/2019 Manual ECS353

    2/8

  • 8/12/2019 Manual ECS353

    3/8

    #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 gure 0.;.

    Figure 1.&: Setu! o!tions

    It is advisale that you change the installation path y clic*ing on Changeutton and selecting the!ath '(:)jd*' as installation directory.

    !fter you have done changing the path, clic* on Next to start the installationand wait until itve ust installed. 1o dene an environment variale, right6clic* onMy Computer icon on the des*top or start menu, then select Properties from

  • 8/12/2019 Manual ECS353

    4/8

    the pop6up menu. 1he System Properties dialog appears, from the top of thedialog o& selectAdvanced ta as shown in gure 0.?.

    Figure 1.+: ,indows advanced settings

    /rom Advanced ta, clic* on nvironment !aria"les utton, @nvironment#ariales dialog appears as shown in gure 0.8.

  • 8/12/2019 Manual ECS353

    5/8

    Figure 1.-: nviron"ent /ariables

    1o add new environment variale, clic* on New utton in #ser !aria"les eld,note that you may not modify system variales unless you haveadministrator privileges. Ance you clic* on New utton, variale additiondialog appears as in gure 0.4.

    Figure 1.0: dding new environ"ent variable dialog box

  • 8/12/2019 Manual ECS353

    6/8

    In !aria"le name eld enter the name of your variales in !aria"le valueeld enter the value of the variale then clic* on $%.=ou need to add twovariales to use with J'S( +!1H points to in directory in JS'( home directory $e. g. cCd*Cin% )!SS+!1H points to the folder in which you will create you Java programs

    $e. g.cC'ocuments and SettingsCStudentC'es*topCava%. 2heco"!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 fromstart menu and entering the command cmd in the dialog o&, the commandprompt console appears, show in gure 0.D. hange to the directory youhave selected as Java directory

    Figure 1.3: (o""and !ro"!t

    for e'ample

    cC'ocuments and SettingsCStudentC'es*topCava% y using cdcommand.

    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 usethe command notepad HelloWorld.ava $/igure 0.9%. Eote that we use a .ava

    e&tension for all Java source les, and we always use upper case charactersin the eginning of a class name. !fter starting the notepad, it will as* youwhether you wish to create a new le with the name specied, conrm lecreation. It is important to *eep in mind that le name and class name muste the same, otherwise the compiler will generate an error message and thele will not compile.

  • 8/12/2019 Manual ECS353

    7/8

    Figure 1.4: note!ad co""and with !ara"etersIn the notepad, write the following code $always *eep in mind that Java iscase6sensitive language, for e&ample if you typed lass instead of class thecompiler will report a synta& error%

    556ello,orld.java57 2his is "y #rst java !rogra".

    75class 6ello,orld8!ublic static void "ain9String ; args