0% found this document useful (0 votes)
16 views59 pages

2 Lesson (History and Development)

Java, created by James Gosling at Sun Microsystems in the early 1990s, was initially named Oak and is known for its features like platform independence, object-orientation, and security. It uses a compiler to convert high-level language into machine-level language and employs a Java Virtual Machine (JVM) to interpret bytecode for execution. Java programs can be developed using tools like the Java Development Kit (JDK) and BlueJ IDE, and they utilize a variety of data types, operators, and control structures.

Uploaded by

Kuntal Ware
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views59 pages

2 Lesson (History and Development)

Java, created by James Gosling at Sun Microsystems in the early 1990s, was initially named Oak and is known for its features like platform independence, object-orientation, and security. It uses a compiler to convert high-level language into machine-level language and employs a Java Virtual Machine (JVM) to interpret bytecode for execution. Java programs can be developed using tools like the Java Development Kit (JDK) and BlueJ IDE, and they utilize a variety of data types, operators, and control structures.

Uploaded by

Kuntal Ware
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 59

History

And
Development
Of
Java
 Creator of Java : James Gosling
(Father of Java).

 Java was designed at Sun


Microsystems in early 1990’s.

 Earlier name of Java : Oak.

 Later Oak was renamed as Java.

 Java was publicly released on


FEATURES OF
JAVA
Compiled and interpreted
Platform independent
Object-oriented
Robust
Distributed
Dynamic
Multithreaded
Secure
Supports multimedia
Available free of cost
Compil
er
&
All high level languages (HLL)
need to be converted to machine
level languages (MLL) so that
computer can understand the
program after taking required
inputs.

 The conversion of HLL to MLL


can be done in 2 possible ways :
either by Compiler or by
 Code is nothing but a program.
 Program is nothing but a set of
instructions.
Source program Translator Object program

High Level Compiler/ Machine Level


Language Interpreter Language
Source Program : A Program which
is input to a Translator (Compiler /
Interpreter).

Object Program : This program is


ource Program
&
Object Program
Source Code/Program Object Code/Program

1) It is in the form of text 1) It is in the form of binary


numbers

2) Is Human Readable 2) Is Machine Readable

3) Is generated by human 3) Is generated by Translator

4) Is a input which is given to 4) Is output of compiler


compiler
What Is a Compiler ?
Software by which all high level
instructions are converted into
machine level language at
once ,is known as Compiler.

Here, all the errors are listed


together after checking the
entire program.


High Level Language Compiler Low Level Language

Source Translator Object


Program Program
What
Is
a
Interpreter ?
Software by which the
conversion of high level
instruction is done line by line to
machine level language ,is known
as Interpreter.

If an error is found on any


line ,the execution stops till it is
corrected.


High Level Language Interpreter Low Level Language

Source Translator Object


Program Program
What Is a Byte Code ?
Java
JAVA compile
Program r

Java
byte
code

Java Java
Java
interpreter interpreter
interpreter
for Windows for Windows
for Windows
Vista XP
8
Java Virtual
• Java is a high level language.

• Program written in HLL is


compiled and then converted to
intermediate language called Byte
code.

• Byte code looks a lot like machine


language.

• The Java programs that have been


What
Is
a
Java Virtual Machine
•Programs written in Java are
compiled into Java Byte code,
which is then interpreted by a
special Java Interpreter for a
specific platform.
• Actually this Java interpreter is
known as Java Virtual Machine
(JVM).
Message :-
Objects interact with one another through
messages.

Message Passing :-
When the objects need to interact with one
another, they pass / request information to
one another. This interaction is known as
message passing.
Types
Of
Java Programs
There are two types of java
programs:
♦ Stand alone applications: Any
software application developed
with Java for a stand-alone
machine. It is also referred as
an application program
Java Development Kit (JDK)
It is a pack of a large number of development
tools.
Plays a great role in the development and
execution of Java programs.
Predefined classes and methods grouped in
packages
Commonly used tools : javac, java, javadoc,
appletviewer, etc.
JAVA API’s
Java API (Application Program Interface) is a
collection of pre-compiled codes grouped into
various functional packages that can be used
while creating programs in Java.
Java.lang
Java.io
Java.applet
Java.math
Jawa.awt
Java.net
Java.text
Basic Structure
In
Java
Programming
// Simple Java Program

Access Keywor Name of the


specifier d class
public class grade_std Declaration of
{ main function
public static void main (String args[])
{
System.out.println (“ Welcome to the World of Java “);
} // end of main
} // end of class Output semicol
statement
Opening & closing of
Opening & main function
Points To Remember
 Class name should be meaningful and
relevant to the program.

 Termination of each statement must be with a


semicolon (;).

 The opening of bracket ( { )indicates the beginning of a


class and main function.

 Closing of bracket ( } )indicates the closing of class and


main function.
Java
Reserved
Words
• Java reserved words are the
words which has particular
meaning and is stored in java
library or java packages.

•List
caseof reserved words : -
 switch
 else
 break
 static etc…. (refer book)
Comment
Symbol
In
Java Programs
Comments /*….*/ and // …. are
non-executable statement.
 It tells more or detailed
information about program.
 It makes user easy to
understand.
 The comments are ignored by
the compiler and not executed
at all even if you write a valid
 Examples:

 Single line comment :


// Sum of two numbers
// You are learning Java
Programming Language

 Multi line comment :

/* Java is one of the


Java example :
/* program Helloworld.java */
Public class Helloworld
{ public static void main(string args[ ])
{ system . Out println ( “Hello World ! !”);
} // main ends here
}
◘ Initial class Hello World :- it means that a class is being defined. It is a initial class that define
the program name and begin with keyword public.
◘ Method main :- is where an application begins executing. If no main is there , no execution will
take place. Sometimes it drives your program.
◘ System.out.println(“Hello World!!”) :- this statement prints Hello World!! On the output device
i.e. monitor
◘ public main (…):- is the first method called by java environment when a program is executed
so it has to be accessible from java environment. Hence the access specifier has to be public.
◘ static :- it used to call the method without creating an instance of the class.

What is a BlueJ?
ÞIt is basically an IDE (Integrated Development Environment ). It includes following tools in it :
Þ an editor : which you can use to write your program.
Þ a debugger :- which helps you find your mistakes.
Þ a viewer: which lets you see parts of your program graphically.
Java Character set :
Character set is a set of valid characters that a language can recognize. A character
represents any letter, digit or any other sign. Java uses the Unicode character set.
Unicode is a two-byte character code set . We can use Unicode by using ‘ \u ’
followed by a four digit hexadecimal number.
For e.g.. \u00AE -- it used for symbol ‘ @ ‘
\u0394 --- it used for symbol delta ‘ ∆ ‘
Tokens:- The smallest individual unit in a program is known as a Token.
For e.g.. Keywords, identifiers, literals, punctuators, operators.
1) Keywords :- are the words that convey a special meaning to the language
compiler. These are reserved for special purpose . E.g. break, float, goto, char etc.
2) Identifiers:- are fundamental building blocks of a program and are used as the
general terminology for the names given to different parts of the program. E.g.
variable, objects, classes etc.
It follows some rules :
1) they can have alphabets, digits and underscore and doller sign character.
2) they must not be a keyword or null literal.
3) they must not begin with a digit.
4) they can be of any length.
5) Java is case sensitive i.e. upper and lower case alphabets are treated differently.
e.g. some valid identifiers : Date9_7_99 , _DS , $1_to_$10
e.g. some invalid identifiers : Date9-7-99, break, My.File
3) Literals(Constants):- are data items that are fixed data values. Types of literals:
i) Integer literal ii) floating literal iii) Boolean literal
iv) Character literal v) string literal vi) the null literal
ii) Integer literal :- are whole number without any fractional part . It must have at
least one digit and must not contain any decimal point. It may contain + or – sign.

there are three types:- 1) Decimal Integer Literals


2) Octal Integer Literals
3) Hexadecimal Integer Literals
ii) Floating Literals: it also called as real literals , which having fractional parts.
e.g. 2.0, 17.5, -13.0, -0.00625, 172.E5
iii) Boolean Literals:- it has two values, represented by the literals true and false.
iv) Character literals:- a single character enclosed in a single quotes.
e.g. ‘a’ , ‘%’ , ‘z’
v) String Literals:- multiple character constants are treated as string literals. Which
enclosed in double quotes,
e.g. “abc”, “\ab”, “seema’s pen”
vi) Null Literals:- a null literal is always of the null type.
Separators : the following nine characters are the separators (punctuators):
(),{ },[ ],;,,,.
Operators: there are 37 tokens called as operators. Some examples are given below
= > < ! ~ : <= && ||
Data Types : are means to identify the type of data and associated operations of
handling it. There are two types
1) Primitive ( Intrinsic) data types : it come as a parts of the languages. E.g. int, float,
char etc.
2) Reference data types : are constructed from primitive data types. E.g. arrays,
classes
that used to store the memory address of an object.
1) Primitive Data types: it supports following four types of primitive data types :
1) Numeric Integer primitive types :- are used to store numeric values. It’s types
are
a) byte b) int c) short d) long

byte 8 bit (1 Byte) Byte length integer -128 to +127


Type Size Description Range
Short 16 bits ( 2 Bytes) Short integer -32,768 to +32,767
Int 32 bits (4 Bytes) Integer -2 billion to + 2 billion
Long 64 bits(8 Bytes) Long Integer -10E18 to + 10E18
2) Fractional Numeric Types:
Type Size
float 32 bits (4 bytes)
double 64 bits (8 bytes)

3) Character Types :
Type Size Description examples
Char 16 bits (2 Bytes) Single Character Alphabets and numerals

4) Boolean Type :
Type Size Description Range
Boolean Java reserve 8 bits Logical or boolean True or false
but uses 1 bit values
Variables: is a named memory lacation, which holds a data value of a
particular data types.
e.g. int radius = 5;
Float x= 0.27;
Operators in Java:
An operator is a symbol which represents a mathematical or logical
operation that can be performed on a data value.
The data value on which an operation is performed using an operator is
called the operand.
now we are studying types of operators :
1) Arithmetic Operators: a) Unary Operators i) Unary + :- if a=5 then +a
means 5.
if a= -4 then +a means -4
ii) Unary - :- if a=5 then -a means - 5.
if a= -4 then -a means 4
b) Binary Operators i) Addition (+): 4+20 results
in 24
ii)Subtraction (-):- 14-3 evaluates
to11
iii) Multiplication(*):- 3*4
evaluates to 12
◙ Increment / Decrement Operators (++ , --) :
++ is a increment operator and – is a decrement operator. The operator ++
adds 1 to its operand, and – subtracts one.
i.e. a = a + 1; is same as ++a or a++
And a = a – 1; is same as –a or a—
◙ Relational Operators : it gives the results in terms of true and false.

== Equal to

!= Not equal to
> Greater than
< Less than
>= Greater than or equal to

<= Less than or equal to

◙ Logical Operator :
&& -> all conditions must be satisfied
|| -> any one condition of the given conditions must be
satisfied
! -> Logical NOT
◘ Conditional Operator : this operators is ternary operator i.e. it
requires three operands . The general form of conditional operator is as
follow :
expression ? expression2 : expression3
If expression 1 is true it takes the value of expression2 otherwise value of
expression3
e.g. result = marks >= 50 ? ‘P” : ‘F’
◘ The [ ] operator: it used to declare array, to create arrays, and to access
a particular element in an array.
e.g. marks of 20 students, sales of 30 salesmen etc.
It declare as float [ ] arrayoffloats = new floats [10]
◘ The . Operator : it access instance members of an
object or class members of a class
◘ the ( ) operator: the method’s arguments are listed
between ( ). You can specify it as empty.
◘The (type) operator: it converts a value to specified type.
◘ The new operator: it use to create a new object or a new array.
◘The instanceof operator : it checks whether its first operand is instance
Operator Precedence:
It determines the order in which expression are evaluated.
e.g. the expression y = 6 + 4 / 2 it determines the order for
evaluation.
But, increment & decrement are evaluated before arithmetic,
Arithmetic are evaluated before comparisons, and
Comparisons are evaluated before logical expression.
Assignment expression are evaluated last.
So here division is evaluated before addition and
Value of y will be 8.
Operator Associativity: it determines the grouping of
Operands and operators in an expression.
e.g. x = a + ( b – c ) here, addition &subtraction have same
precedence rating but parentheses evaluate first and
then value of answer is added in operand ‘a’ .
Selection Statements: Where condition is the expression that is
being evaluated. If this condition is true,
a) If statement ; statement is executed. If it is false,
Syntax:- if (expression) statement is ignored (not executed) and
the program continues right after this
statement ; conditional structure.

e.g. program to print largest number of the three.


public class p1
{ public void test (int x, int y, int z)
{
int max = 0;
max = x ;
if(y>max)
max = y;
If (z > max)
Max=z;
System.out.println(“Largest number is “ +max);
}}
If — else statement :
e.g. Write a program to check whether the given number is even or
not.
Public Class number
{
boolean checkEven( int num)
{
If(num%2 = = 0)
return true;
else
return false;
}
}
The Switch statement:
Syntax::
Switch (expression)
{
case constant 1 : statement-sequence 1;
break;
case constant 2 : statement-sequence 2;
break;
:
:
case constant n : statement-sequence n;
break;
[default : statement-sequence];
}

break statement:
It causes the termination of the statement
and it skip over part of the code.
The For Loop:
Syntax:

For (initialization expression ; test expression ;


update expression)
Body of the loop ;
The While Loop:
Syntax :
While (expression)
Loop body
The loop iterates while the expression evaluates
to true. When the expression becomes false, the
program control passes to the line after the loop
body code.
The Do While Loop:
Syntax:
Do { statement;
}
While (test – expression);
this loop always executes at least
once, because it evaluates its test
expression at the bottom of the
loop after executing its loop body
statements.
Expression :
An expression is composed of one or more operations. it is a valid
combination of operators, constants and variable.
The following code describes the
use of different arithmetic
Arithmetic Expressions : expressions.
Java Arithmetic expressions use arithmetic
operators such as +, -, /, *, and %. The % operator
int x, y, z; // Three integer
is the remainder or modulo operator. Arithmetic
variables
expressions are used to assign arithmetic values //declared at the
to variables. An expression is a combination same
of time.
literals, operators, variables, and parentheses
used to calculate a value. x = 10;
y = 12;
z = y / x; // z is assigned the
Boolean expressions value
Java Boolean expressions are expressions which are either
//of true or
y divided byfalse.
x.
The different boolean operators are < (less than), > (greater than),
== (equal to), >= (greater or equal to), <= (less or equal), != (not equal to).

Example:
Boolean expressions : are expressions which are either true or false. The
different boolean operators are < (less than), > (greater than), = (equal to),
>= (greater or equal to), <= (less or equal), != (not equal to).
Example:

((x - y) == (z + 1)); // This expression checks


// if (x - y) equals (z + 1).

A boolean expression can also be a combination of other


boolean expressions. Two or more boolean expressions
can be connected using &&logical AND) and || (logical OR)
operators.
The && operator represents logical AND. The expression
s true only if both boolean expressions are true. The || operator
represents logical OR. This expression would be true if any
one of the associated expressions is true.
mple:
x = 10; int y = 4; int z = 5;
<= 10) && (y > 1) // This expression checks if x is less
han 10 AND y is greater than 1.
s expression is TRUE.

y == 41) || (z == 5) // This expression checks if x*y is equal


40 OR if z is equal to 5.
his expression is FALSE
Type Conversion :
When constants and variables of different types
are mixed
In an expression , they are converted to the same
type.
1) Implicit type conversion:
It performed by the compiler without
programmer’s
Intervention. It applied when different data types
are
mixed in an expression. Java compiler converts all
The Rule for conversion :
If either operand is of type double, the other is converted to
double.
 if either operand is of type float, the other is converted to float
If either operand is of type long, the other is converted to long
 otherwise , both operands is of type int.
E.g.
char ch; int I float fl; double db;
result = (ch / i) + ( fl*db) - ( fl + i)

int double
float

int double float

double

double
2) Explicit type conversion:
It is a user defined that forces an expression to be of
specific type
(type) expression
Where type is a valid Java data type to which conversion
is to be done.
e.g. (float) (x + y / 2)

Declaring Member Variables:


A class’s state is represented by its member
variables. It declare in the body of the class.
Syntax :
Classdeclaration
{
member variable declarations
method declarations
}
The class variable can be of two types:
1) Class variable (static variable) : it is declared once for a class.
2) Instance Variable : it is created for every object of the class
e.g. if there are 10 objects of a class type, there would be 10 copies of
instance variables
Controlling Access to Members of a class:
Member variable and methods are collectively known as members.
Access or visibility rules determine whether a method or
a data variable can be accessed by another method in
another class or subclass.
Java provides four access modifiers:
1.public : access by any other class anywhere.
2.protected : accessible by the package classes and any subclasses
that are in other subclasses.
3. Default: accessible to classes in the same package but
not by classes in other packages.
4.private: accessible only within the class.

The new operator:


Is used to create an object of a class and associate the
object with a variable that names it.
Syntax:
class_variable = new class_name ( );
e.g. city metro ;
metro = new city ( ) ;
Methods :
There are at least three reasons why we use methods :
1)To cope with complexity : when programs become more and
more complex i.e. large in a size to remove its complexity we have
to divide it into small easily understood tasks. This techniques
provided by Java called as method.
2) Hiding Details :once a method is defined , it can be used
in a program. But we don’t care how the method’s task is
Performed.
e.g. if we have to find square root of variable x.
The details of calculating a square root are hidden from us.
3)Reuse:
Once a task is packaged in a method, that method is
Available to be accessed, or called from anywhere in a program
And it can called from other programs.
Method / function prototype : is the first line of the function
definition that tells the program about the type of the value returned
by the method and the number and type of arguments.
Method / function Signature: it basically refers to the number and
types of arguments. it is a part of the method prototype.
Accessing a Method/function:
Is callled by providing the method name, followed by the parameters
being sent enclosed in parentheses.

Actual and formal parameters:


The parameters that appear in method
definition are
Called formal parameters and the
parameters that appears in method call
statement are called actual
Parameters.
Actual and formal parameters:
The parameters that appear in method definition are
Called formal parameters and the parameters that
appears in method call statement are called actual
Parameters.
e.g.
// method definition
Public int mult (int x, int y) // x & y formal parameters
{
Return x*y;
}
// code fragment where the method mult is used
// must be part of some other method
Int length = 10;
Int width = 5;
Int area = mult(length , width); // method call statement &
actual // parameters are defined
Arguments to Methods/Functions:
There are two methods
1) Call by Value ( Pass by Value):
This mechanism copies the values of actual parameters into
the formal parameters i.e. the method creates its own copy of
Argument values and then uses them.
The original copy of the argument value remains same.

2) Call by Reference (Pass by Reference):


here in place of passing a value to the method
THANK
YOU

You might also like