Sri Lanka News

Only available on StudyMode
  • Download(s): 136
  • Published: August 5, 2013
Open Document
Text Preview
HSIT 2130
Fundamentals of Programming

By Budditha Hettige
Department of Statistics and Computer Science
1

Overview
• • • • • • • • • Exercises (Previous Lesson) The JAVA Programming Languages Java Virtual Machine Characteristics What is a class? JAVA Standards JAVA Keywords How Install JAVA Sample Java Program 2

Exercises
Draw a flowchart for the following
1. 2. 3. Enter two number from key bard and print average Enter three number and find the maximum number Process of the ATM machine

3

JAVA
• Is a programming language created by James Gosling from Sun Microsystems in 1991 • Is a general-purpose, class-based, objectoriented Programming language • is intended to let application developers “write once, run anywhere.” • Current version (JDK) 7u21 • URL : http://www.oracle.com/

4

Java cont…
• Java programming language consists
– Java compiler: Java compiler translates Java coding into byte-code – Java virtual machine(JVM) Java virtual machine interprets this byte-code and runs the program – Java class libraries Java Class Library is a set of dynamically loadable libraries that Java applications can call at run time 5

Java Virtual Machine (JVM) Architecture
JAVA Source File (.java) Java Virtual Machine Byte code Verifier Memory Manager JAVA Bite code (.class)

Java Compiler

Interpreter

Java API

6

JAVA Vs C++
JAVA Source File (.java)

C++ Source File (.cpp)

Java Compiler

C++ Compiler

JAVA Bite code (.class)

Executable program (.exe) Operating system can directly execute

Java VM

JAVA VM can directly execute

7

Characteristics
Java has the following properties • Platform independent • Object-orientated programming language • Strongly-typed programming language • Interpreted and compiled language • Automatic memory management 8

Platform independent
• Can Run on any Platform
– Windows – Linux – MaC OS
JAVA Source File (.java)

Java Compiler

JAVA Bite code (.class)

Java VM

9

Object-orientated programming language
• Object-oriented programming (OOP) is a programming paradigm that represents concepts as "objects" that have data fields (State) and methods (Behavior)

• What is an Objects?
– Object is a software bundle of related state and behavior – Characteristics: state and behavior – Example (Person) • State (Name, NIC, height) • Behavior (Speech, Sleep, eat)

– Object is an instance of a class
(instance is a specific realization of any object)
10

What is a class?
• A Java class is a group of Java methods and variables
• Example (Person) – State (Name, NIC, height) – Behavior (Speech, Sleep, eat) class Person { }
11

Requirements for Class name
• Class name must begin with letter of the alphabet • Contains only letters, digits, underscores or dollar sign • Cannot be a language reserved keywords (public, class etc) • Name cannot be following values (true, false or null) 12

Java Class name standard
• Begin with uppercase letter • No spaces • Emphasizes new word with an initial uppercase letter Example • EmployeRecords • Student • FirstExample • SampleProgram 13

Java Keywords

14

Install JAVA
• Download Java Development Kit (JDK)
– http://www.oracle.com

• • • •

RUN Installation setup SET PATH for the JAVA Test JAVA is working Video Link – http://www.dscs.sjp.ac.lk/~budditha/java/vd/ins/install.html

15

Simple Java Program
• A class with a main Method
public class FirstProgram { public static void main(String[] args) { System.out.println("Hello"); } } FirstProgram Operating System

Output

Main Method 16

A class without a main Method
public class FirstProgram { }

Operating System Can not Execute the program

FirstProgram Operating System

17

Your first Java program
• Open a text editor (text pad, Notepad etc.) • Type the following sample • Save program as “FirstProgram.java” public class FirstProgram { public static void main(String[] args) {...
tracking img