Java

Only available on StudyMode
  • Download(s) : 198
  • Published : April 8, 2013
Open Document
Text Preview
Java Language Programming
Basic Programming Elements

Tiberiu Leţia: Software Engineering –Java Programming Language – Programming Basic Elements

1

Content 1. Stand alone applications and mini-applications 2. Name and identifiers 3. Java program structure 4. Data types 5. Operators 6. Flow execution control

Tiberiu Leţia: Software Engineering –Java Programming Language – Programming Basic Elements

2

1. Stand alone applications and mini-applications
Mini- applications = applets stand alone application) = program that can be used independently. They have main() method public static void main (String[] args)

launching the execution (run program) Java interpreter  java numeProgram

Tiberiu Leţia: Software Engineering –Java Programming Language – Programming Basic Elements

3

Applet A Java program that extends Applet class. This class doesn’t contain main method the program cannot be launched using Java interpreter. They are used in Web pages (via HTML file). Web server browser (ex. Internet Explorer, Mozilla Firefox).

Tiberiu Leţia: Software Engineering –Java Programming Language – Programming Basic Elements

4

2. Names and Identifiers
An identifier is a sequence of unlimited length of letters and digits where the first is compulsory a letter. They are string of characters representing names given to variable, classes or methods. They should differ from keywords (including null, false and true). Names are used for referring entities like packages, class types, interfaces, type members, parameters, local variables etc. The names can be:  simple - ex.: xxx  composed – sequences of identifiers separated by ".". ex.: xxx.yyy.zzz Tiberiu Leţia: Software Engineering –Java Programming Language – Programming Basic Elements 5

abstract do import public try boolean double instanceof return void break else int short volatile byte extends interface static while case final long super catch finally native switch char float new synchronized class for null this const goto package throw continue if private throws default implements protected transient Keywords Tiberiu Leţia: Software Engineering –Java Programming Language – Programming Basic Elements 6

Ex.: java.awt.BorderLayout java.lang.System.out.println()

Tiberiu Leţia: Software Engineering –Java Programming Language – Programming Basic Elements

7

3. Java Program Structure
Lexical entities:  comments –  keywords  identifiers  literals  separators – signs ({, }, [, ], ;, . and ,) used to separate lexical entities  operators Variables Constants Expressions Tiberiu Leţia: Software Engineering –Java Programming Language – Programming Basic Elements 8

Instructions – lexical units that describe what the program has to perform – the instructions are separated by ”;”. Code block { instructions; }. packages subpackages

Tiberiu Leţia: Software Engineering –Java Programming Language – Programming Basic Elements

9

Source files Code source  filename.java Compiler javac  filename.class Package declaration: package NumePachet;

Tiberiu Leţia: Software Engineering –Java Programming Language – Programming Basic Elements

10

Program example:
/** Program name * Comments */ public class NumeClasaPrincipala { /** * Metoda principala a aplicatiei * * Se pot transmite parametrii prin tabelul argumente */ public static void main (String[] args) { // Aici se adauga codul programului System.out.println("Salut! Merge programul!"); }//terminare metoda main }

de

Tiberiu Leţia: Software Engineering –Java Programming Language – Programming Basic Elements

11

Compilation  javac Running java NumeClasaprincipala

Tiberiu Leţia: Software Engineering –Java Programming Language – Programming Basic Elements

12

4. Data Types
Type variabileName; Variable types in Java:  reference - classes, interfaces, arrays (or null) and  primitive data. Where are they used?

Tiberiu Leţia: Software Engineering –Java...
tracking img