Вы находитесь на странице: 1из 20

Department of Computer Science and Engineering (CSE)

JAVA Programming (CST-254)

JAVA Fundamentals

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Java Basics
First was C.
C++ as an extension to C.
provides the capabilities of OOPS
a hybrid language
JAVA
was developed in 1991
by James Gosling
at Sun Microsystems
Oak was initial name.
became popular in 1995

considered as the native language

Java is a Full OOPS

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Features of JAVA
Simple
Object-Oriented
Distributed
Interpreted
Robust
Secure
Architecture-Neutral
Portable
Performance
Multithreaded

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

OOP Concepts
Procedural Approach
Focus on procedures
data is shared
More difficult to modify
Hard to manage complexity

Object Oriented Approach


Data and operations are grouped together
Classes reflect concepts

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Principles of OOP
Abstraction

Encapsulation

Inheritance

Polymorphism

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Principles of OOP
Abstraction
Ignore
irrelevant features,
properties, or
functions
Emphasize on relevant ones
represent complex reality
highlights the properties of an entity
is achieved by using
Abstract classes
Interfaces

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Principles of OOP

Declare all data members ( fields ) as private


Some may be private
interaction is only through the classs constructors and public
methods
Constructors and public methods serve as the interface
Ensures that structural changes remain local
Hides implementation details
reduces complexity
easier maintenance

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Principles of OOP
Inheritance

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Principles of OOP
Polymorphism

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

BENEFITS OF OOPS

Solve problems easily


redundant code decreases
Communication becomes easy
High security
Multiple objects co-exist
Easy Object mapping
easy project partitioniong

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

JAVA Virtual Machine

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Source Code

Java
Compile

Linux JVM Win JVM Mac JVM

Linux Machine Windows Machine


Mac Machine

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

JAVA Primitive Data Types


Data Characteristics Range
Type
byte 8 bit signed integer -128 to 127
short 16 bit signed integer -32768 to 32767
int 32 bit signed integer -2,147,483,648 to 2,147,483,647
long 64 bit signed integer -9,223,372,036,854,775,808 to-
9,223,372,036,854,775,807
float 32 bit floating point + 1.4E-45 to
number + 3.4028235E+38
double 64 bit floating point + 4.9E-324 to
number + 1.7976931348623157E+308
boolean true or false NA, note Java booleans cannot be
converted to or from other types
char 16 bit, Unicode Unicode character, \u0000 to \uFFFF
Can mix with integer types

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Variable Definitions
Variable definitions
name of place in memory
contain data
All variables have:
Data type
Name
Value
also called literal
Semicolon
e.g.
String s = MC697;
int count = 5;

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Variable Definitions
Initializing Variables

Assignment operator (=)

Used to assign value to a variable


char c = a; - note the single quotes
Boolean b = true;
double d = 1.25;
default to null.
All should be initialized.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Expressions and Operators

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Operators
Basic Assignment: =
Arithmetic Operators: +, -, *, /, %(remainder)
integer, floating point, and mixed arithmetic and
expressions
Assignment Operators: +=, -=, *=, /=, %=
increment and decrement operators: ++, --
prefix and postfix.
avoid use inside expressions.
int x = 3;
x++;

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Expressions
Evaluation is based on the precedence of operators

Automatic conversion of numerical primitive data types

results are surprising

take care while mixing

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Operator Precedence
Order Operators Name

1 . [] (parameters) array indexes, parms


2 ++ -- ! ~ instanceof unary operators
3 new (type)expr creation and cast
4 * / % multiply and divide
5 + - addition and subtraction
6 << >> >>> bitwise shifts
7 < > <= >= relational operators
8 != == equality operators
9 & bitwise and
10 ^ bitwise xor
11 | bitwise or
12 && logical and
13 || logical or
14 ?: conditional
(ternary) operator
15 = += -= *= /= assignment

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

THANKS..

University Institute of Engineering (UIE)

Вам также может понравиться