Anda di halaman 1dari 20

Introduction to Java

Version 1.0

23 October 2007

Course Objective

The Objective of Java course is: To understand basic programming concepts using Java syntax. To appreciate OOP concepts and encourage problem solving using OOP techniques. To understand various Java API and how to use them effectively in projects. To understand the need for exception handling and how to use in Java environment.

23 October 2007

What is Java?

Java is both: A Programming language A Platform

23 October 2007

The Java Programming Language

Java is an Object Oriented Programming language. Javas syntax is similar to C / C++ syntax. Java is both compiled and interpreted. The intermediate form is called Java byte code, which is platform independent. Byte codes are interpreted by JVM during runtime.

23 October 2007

Java Platform

The Java Platform has two components: The Java Virtual Machine (JVM) The Java Application Programming Interface (Java API)

23 October 2007

The Java Platform

The Java VM is base for Java platform and is ported onto various hardware-based and OS based platforms. The Java API is a large collection of ready-made, frequently used class libraries, stored in packages.

23 October 2007

The Java Environment

Java Program

Java API

JAVA PLATFORM

Java Virtual machine Native OS / Platform

23 October 2007

A Simple Java Program

/** This is our first Java Program */ class FirstClass { public static void main(String args[]) { System.out.println(Hello World.); } }

23 October 2007

Compiling and Running in Eclipse

23 October 2007

Java Data Types

Two major data types Primitive Because java program has to run on different architecture and OS, the size of the data should remain same. Otherwise, on different machines the output will be different Reference All objects are of type reference data type. Java doesnt allow directly to access memory. But objects are refered by pointers only.

23 October 2007

10

Primitive Data Types


(8 bit) (16 bit) (32 bit) (64 bit)

Integers byte short int long

23 October 2007

11

Primitive Data Types


(32 bit) (64 bit)

Real Numbers float double

Other Types char boolean (16 bit) (true / false)

23 October 2007

12

Reference Data Types

Examples: Arrays Strings Objects Interfaces The name reference means a pointer in the memory. All objects are referred by their memory location only. But user cannot directly access memory location. Memory management is taken care by JVM itself.

23 October 2007

13

Variable Names

Variable names in Java are legal Java identifier comprised of a series of Unicode characters. Variable names must not be Java keyword or a boolean literal Same variable name should not appear twice within a scope.

23 October 2007

14

Java Operators

Arithmetic Operators +, -, *, /, % Unary Arithmetic Operators ++, -Relational and Conditional Operators >, >=, <, <=, ==, !=, &&, ||, ! Bitwise Operators >>, <<, >>>, &, |, ^, ~ Ternary Operator: ()?():()

23 October 2007

15

Control Flow

Decision making if-else, switch-case Loop for, while, do-while Exception try-catch-finally, throw Miscellaneous Break, continue, label:, return

23 October 2007

16

Arrays in Java

Java arrays are objects. Array contains like-typed values. Array can contain both primitive and reference data types. When used with reference data types, reference (memory location) is only stored in arrays and not the real objects. Java supports multidimensional arrays. They are nothing but array of arrays.

23 October 2007

17

Arrays in Java

Array Declaration int myIntegers[]; int[] myIntegers; Array memory allocation: int myIntegers[] = new int[10]; Array Initialization: int myIntegers[] = {1,2,3,4,5};

23 October 2007

18

Strings in Java

A sequence of characters is encapsulated as a String object. Java uses + operator for String concatenation. Some useful String functions are: s.length(); s1.equals(s2); s1.subString(int startIndex, int upTo);

23 October 2007

19

Summary

In this session you learned about: Java Programming Language Java Platform Java Environment First Java Program Data Types Operators Control Flow Java Arrays and Strings

23 October 2007

20

Anda mungkin juga menyukai