0% found this document useful (0 votes)
12 views19 pages

Java Programming Overview and Features

The document provides an overview of Java programming, detailing its history, features, and differences from C and C++. It covers Java's object-oriented nature, platform independence, and robust security, as well as its application in internet programming and the Java environment, including the Java Development Kit (JDK) and Java Virtual Machine (JVM). Additionally, it explains Java program structure, data types, operators, and expressions.

Uploaded by

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

Java Programming Overview and Features

The document provides an overview of Java programming, detailing its history, features, and differences from C and C++. It covers Java's object-oriented nature, platform independence, and robust security, as well as its application in internet programming and the Java environment, including the Java Development Kit (JDK) and Java Virtual Machine (JVM). Additionally, it explains Java program structure, data types, operators, and expressions.

Uploaded by

sabbapraween01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Programming

Unit 1: Java Evolution and overview of Java Language


● History of Java:- Java is a general purpose, object oriented programming language developed
by sun Microsystems of USA in 1991.
● Java Features:- This language was developed to offer solutions to some of the problems
encountered in modern programming. Sun Microsystem officially describes Java with the
following attributes.
● Compiled and Interpreted:- Combines both approaches for making Java a two-stage system.
First, Java compiler translates source code into class file known as byte code instruction.
In the second stage, Java interpreter generates machine code for machine execution.
● Platform Independent and Portable :- Java program can be early moved from one computer
system to another anywhere anytime.
Java ensures portability in two ways. First java compiler generates
bytecode instruction that can be implemented on any machine. Secondly, the size of primitive
data types is machine independent.
● Object Oriented:- Java is a true object oriented language everything in java is an object. All
program codes and data are designed within objects and classes. Java comes with an extensive
set of classes, arranged in packages, that we can use in our program by Inheritance.
● Robust and Secure: - Robust means It provides many safeguards to ensure reliable code. It has
strict compile time and runtime checking for data types.
Security becomes an important issue for a language that is used for programming
on internet. The Java system not only verifies all memory access but also ensures that no viruses
are communicated with an applet.
● Distributed:-Java is designed as a distributed language for creating applications on networks.
It can share both data and program.
● Simple, Small and Familiar:- Java is a small and simple language. Many features of C and
C++ that are either redundant or sources of unreliable code are not part of java.
● Multithreaded and Interactive:- Multithreaded means handling multiple processes
simultaneously. Java supports multithreaded programs. This means that we need not wait for
the application to finish one task before beginning another.
● High Performance:- Java performance is impressive for an interpreted language , mainly due
to the use of intermediate byte code.
● Dynamic and Extensible:- Java is capable of dynamically linking in new class libraries,
methods and objects.
Java support functions written in C or C++ and named as native methods. The native
methods are linked dynamically at run time.
C++ Vs Java:- We are well known that java is developed to offer C and C++, but it differs from C
and C++ in many ways. Java appears to be similar to C ++ when positive commands only the
extension part of C++.
➢ The features of C++ were omitted from java or almost modified.
➢ Java does not support operator overloading.
➢ Java does not have template classes as in C++.
➢ Java does not support multiple inheritance of classes, but the same will be implemented
using “Interface”.
➢ Java does not support global declaration of every variables and methods, it is declared
within a class as a part of that class.
➢ Java does not use pointers.
➢ Java has replaced the destructor function with a finalize ( ) function.
➢ There are no header files in java.

How Java differs from C and C++


● Java and Internet:- Java is strongly associated with the internet because the first
application program written in java was hot Java, A web browser to run applets on the
internet. In fact, java applets have made the internet a true extension of the storage stream
of the local computer.
Internet users can also set up their website containing java applets that
could be used by other remote users of the internet i.e. why Java is popularly known as
internet language.
● Java and World Wide Web (WWW):- WWW is an open ended information retrieval system
designed to be used in the internet distributed environment. We know that web pages
provide both information and control to link the new pages and share the text available on
the web page. The requirement is to link the multi pages is designed in hypertext markup
language (HTML), the web pages contain HTML tags for finding, retrieval manipulation
and displaying documents worldwide with the support of java, web become more
interactive and dynamic with the support of web, we can run a java program from others
computer across the internet.
● Java support system:- The operation of java and java enabled browser on the internet
requires a variety of support systems namely.
➢ Internet connection:- Local computers should be connect to the internet.
➢ Web Server:-A program that accepts requests for information and sends the required
documents.
➢ Web Browser:-A program that provides access to WWW and runs java applets.
➢ HTML:- A language for creating hypertext for the web.
➢ Applet Tag:- For placing java applet in HTML documents.
➢ Java Code:- Java code is used for defining java applet.
➢ Byte Code:- Compiled java code that is referred to in the applet tag and transferred
to the user computer.
● Java Environment:-Java environment includes a large number of development tools such
as 100 classes and methods. The development of tools is part of the system known as Java
development kit (JDK) and the classes and methods are part of the java standard library
(JSL) also known as application program interface.
➢ Java Development Kit:- The java development kit comes with a collection of tools
that are used for developing and running java program namely.
❖ appletviewer:-Enables us to run java applets (without actually using a java-
compatible browser).
❖ java:- Java interpreter, which runs applets and applications by reading and
interpreting bytecode files.
❖ javac:-The java compiler, which translates java source to byte code files that
the interpreter can understand.
❖ javadoc:- Creates HTML format documentation from java source code files.
❖ javah:- Produces header files for use with native methods.
❖ javap:- Java disassembler, which enables us to convert byte code files into a
program description.
❖ jdb:-Java debugger, which helps us to find errors in our programs.
➢ Application Programming Interface:-The java standard library (API) includes
hundreds of classes and methods grouped into several functional packages. Most
commonly used packages.
❖ Language Support Package:-A collection of classes and methods required
for implementing basic features of java.
❖ Utilities Package:- A collection of classes to provide utility functions such
as date and time functions.
● Input / Output Package:- A collection of classes required for input/ output manipulation.
● Networking Package:- A collection of classes for communicating with other computers
via internet.
● AWT Package:-The abstract window tools kit package contains classes that implements
platform independent graphical user interface.
● Applet Package:- This includes a set of classes that allows us to create java applets.

Note: The use of these library classes will become evident when we start developing java
programs.
Java Program Structure:-
● Program Concept:- We have to develop an application through java language involving
the steps like
➢ Compiling some code into byte code using java compiler.
➢ Executing the byte code program using java interpreter.
Another approach is to run web application of java through applet and
supporting with java enabled web browser.

Java
source
code

Java compiler

Java
Java enable
interpreter
Web browser

Output Output

● Basic Structure:- Java program may contain many classes of which only one class defines
a main method. Classes contain data members and methods that operate on the data
members of the class. Methods may contain data type declaration and executable
statements.
A java Program contains:-
Documentation Section

Package Statement

Import Statement

Interface Statement

Class Definition

main Method class


Main method declaration
class <Class Name>
{
public static void main(String args[])
{
Local declaration;
Statements block;
}
}

Package Syntax:-
package <package name>;
● Import:- We have to include different classes or methods of a package available in the
system.
Syntax:-
import [Link];
Ex:-
import [Link].*;
import [Link];
Class Definition
Syntax
class <classname>
{
public static void main (string args[ ])
{
……………..
……………..
}
}
Ex:-
open an editor like Edit/notepad and create and save a file name :
[Link]
class SampleOne
{
public static void main (String args[])
{
[Link]("Welcome to Java");
[Link]("better than C++");
}
}
● Java Token:-We are well known that java program is a basically a collection of a class and
is defined by a set of declaration statements and method containing executable statements.
A java program is a collection of token, comment and blank spaces.
Java Tokens

Reserve word Identifier Literal Operators Separators

Keywords

● Reserve Word or Keywords:-A valid java word whose meaning available in java compiler.
The keywords are an essential part of a language definition and implement specific features
of the language. There are 60 reserve words.
Java Keywords
abstract Boolean break byte byvalue*
case cast* catch char class
const* continue default do double
else extends false* final finally
float for future* generic* goto*
if implements import inner* instance of
int interface long native new
null* operator* outer* package private
protected public rest* returns short
static super switch synchronized this
thread safe* throw throws transient true**
try var* void volatile while
* Reserved for future use
** These are values defined by java.
Note: ( Keywords & Identifies ) both Java word
Java word follow the following rules at the time of creation.
➢ The first character must be an alphabet.
➢ Other characters may be either alphabet or digit or underscore or a dollar
sign.
➢ Lowercase and uppercase are distinct.
➢ The length may be source line.

● Identifies:- A valid user’s defined word which is not a reserve word is called an identifiers
may be used as variables, class names, methods, objects, label, packages and interfaces in
a program.
An identifier name is designed by a programmer in a meaningful way so as to reflect
their purpose and nature.

EX:-
average
sum
student_name
day_temperature
first_day_of_week
total_marks etc.
● Literals:- Literals are generally a defined constant. It is a sequence of characters that
represent constant values to be stored in variables.
Integer Literals
25, - 75 etc
Floating point literals
23.5 , -275.00 etc
Character Literal
‘x’ ‘y’ ‘z’
String Literal
“Vinay Kumar Singh”
“Q.N. 5”
Boolean Literals: -
True , False

● Operators:- A variety of operators used in java language.


+ , - , * , / , < , > etc.
● Separator :- There are special characters involved in the programming to separate more
than one thing is called separation.
, ; : . () { } []
● Java statements:- We are well known that a complete sentence can be said to as statements
in natural languages like the same a java statements are used to perform specific task in the
program.
Java Statement

Expression
statement Guarding
Statement
Synchronizat
Labelled
ion
Statement
Control Statement
Statement

Selection Iteration Jump

Statement Statement Statement

if retur
if- switch brea con
n
else k tin
ue

while for
do

● Statements are Categorized in term of different objectives: -


Input / output / calculation statements
[Link]( )
[Link]( ) output
[Link].* / input
calculation Assignment statement
variable = AE/Val/Var/Constant/Function;
Expression:-
Assignment
Pre-Increment / Past Increment
Pre-decrement / Past decrement
Method calling
Allocation of Expression
Jumping:-
Label
Switch
break
continue
Looping / Iteration
for – Definite
while – In definite and entry controlled.
do-while – In definite and exit controlled.
Conditional / Selection statements
Sample if
if else statement
if else ladder statement
Nested if statement
switch statement
Implementation:-(i) Writing a program in any editor or Notepad having file name .java
extension.
(ii) Compilation of java program using java compiler.
[Link]
c:\JDK.3\bin>javac [Link]
(iii) Running the program: - A java interpreter is used to run compiled . class file using
[Link]
c:\JDK1.3\bin> java abc
program executes.
Java virtual Machine:- When a java program is compiled, the java compiler produces an inter
media code known as byte code for a machine having file extension .class. This machine is
called the java virtual machine, and it exists only inside the computer’s memory and performs
all major functions of a real computer.
Java Virtual Machine is an engine that provides a runtime environment to launch
the Java application and responsible for converting the byte code (.class file) which generated
by compiling the (.java file). JVM is a part of Java Runtime Environment (JRE).

● Constants and variables: - Constant is a fixed quality that cannot be changed during
execution of a java program generally constant are literals.
A variable is an identifier whose is used to store any value. The value
of a variable may be changed during execution of a program. A variable is declared within
the program and occupies some space in computer memory.
● Data Type:-A verify of data types available in java language. When we declare a variable,
they are defined by specific Datatype.
Data Types in Java

Primitive intrinsic Non – primitive


(derived)

Numeric Non-numeric Class Arrays

Interface
Integer Floating Character Boolean
Point

● Declaration of Variable:-We are well known that anything will be communicated in java
program through variables and the same variable must be declared before use in the java
programming. At the times of declaration of a variable we must have to know that.
➢ What is the name of variable.
➢ What type of data holed by a variable.
➢ In the proper place of variable declaration decides the scope of the variable.
Syntax:-
datatype list of variables;
EX:-
int count;
float x, y;
byte b ;
char c1, c2 , c3;
double pi;
Type Casting:- Sometimes there may be the situation in to store a value of one datatype into a
variable of another type. We must cast the value to be stored by proceeding it with the type
name in parenthesis.
Syntax:-
type var1 = (type) variable2;
int m = 50;
byte n = (byte) m;
long count = (long)m;
Unit 2: Operators and expressions
Operators and Expression:- Java supports a variety of operators namely:
➢ Arithmetic operator
➢ Relational operator
➢ logical operator
➢ Assignment operator
➢ Increment & Decrement
➢ Conditional operator
➢ Bitwise operator
➢ Special operator
Arithmetic operator:-
+ - * / % modulation.
int a , b;
a +b
Integer arithmetic:-
Both the operands must be integer.
Output result will be also integer.
The combination is also called integer arithmetic expression.
Real Arithmetic:-
Both operand must be real.
Output will be also real.
The combination is call real arithmetic expression.
Mixed Mode Arithmetic:-
One operand is real and other is integer and vice-versa.
Output result will be real.
The combination is called mixed mode arithmetic.
Ex:
10.5 – 3 ; int a , b;
float x . y;
y = x + a;
Relational operator:-
> < <= >= = = !=
We have to compare two qualities and depending on their relation the decision should be
taken. The output result will either be true or false. Combination is called relation operators.
4.5 < = 10 ------ True
12 > 5 --------- True
12 > 15 -------- False
Logical operator :-
&& || !
AND OR NOT
When the requirement is to combine two or more relational expressions, it is also called
logical expression or a compound relational expression. The output result of any logical
expression will be either true or false.
((a>b) &&(a>c))
Assignment operator:- This operator is used to make an assignment statement in this
concept the value variable, expression or function placed right side. The result of right-side
object will be assigned into the variable available on the left side.
x = 7;
a = b = c = d = 7;
a + = 1; a = a + 1;
Increment and Decrement operator :-
++ - -
Increment Decrement
Pre/ Post Pre/ Post
In both cases the value of variable on which the operators are used will be increased or will
be decreased by 1.
m=7
n=m++; m=8,n=7
n=++m; m=9,n=9
x = 6;
y=--x; x=5,y=5
y=x--; x=4,y=5
Conditional operator ( Ternary operator);
Syntax:-
(exp1)? exp2: exp 3
Bitwise operator:- Java has a distinction of supporting special operators known as bitwise
operators for manipulation of data at values of bit level.
Operator Meaning
& Bitwise AND
! Bitwise OR
~ Bitwise exclusive OR
^ Ones complement
<< Shift left
>> Shift right
>>> Shift right with zero fill
Special Operator:- Java supports some special operators of interest such as instance of
operator and member selection operator(.).
Instance of Operator:- The instance is an object reference operator and returns true if the
object on the left hand side is an instance of the class given on the right hand side. This
operator allows us to determine whether the object belongs to a particular class or not.
Ex:- Person instance of student
Is true is the object person belongs to the class student; Otherwise, it is false.
Dot Operator:- The dot operator ( . ) is used to access the instance variables and methods
of class objects.
Ex:-
[Link] // Reference to the variable age.
[Link]() // Reference to the method salary ();
It is also used to access classes and sub-package from a package.

Unit 3: Decision making and Looping


Decision making and Branching: - Whether the requirement is to check one or more condition
in a java program, the concepts of decision making and branching will be implement.
There are several branching statements available in java.
(i) Simple if statement
(ii) if else statement
(iii) if else Ladder statement
(iv) Nested if statement
(v) Switch statement
(i) simple if statement:- One condition is checked and if condition is true; the statement/(s)
after condition will be executed. In case of false result of the condition statement will be
ignored.
Syntax:-
If (condition) st1 / stb1;
Ex:-
Two number - highest
Two number - Lowest
(i) if (a > b ) g = a;
if ( a <= b) g = b;
(ii) if ( a < b) s = a;
if ( a > = b ) s = b;
(ii) if else statement:-
In this concept single condition will be checked.
In case of true result of condition, a statement/(s) after condition will be executed.
If case of false result of the condition the statement (s) followed else will be executed.
Syntax:-
if ( test expression) st1 / st B1;
else st2 / st B 2;
(1) if ( a > b ) g = a;
else g = b;
(2) if ( a < b ) s = a;
else s = b;
(3) if ( a > b ) { g =a;
s = b;
}
else { g = b;
s = a; }
(iii) if else ladder statement:- This statement is used to check multiple condition and based
on FIFO (first in first out) purple.
In this concept successive condition will be checked if the condition is false.
In case of true result of the condition the statement1 (s) followed after condition will be
executed.
Syntax;-
if (condition 1) st 1 / st B 1;
else if (condition 2) st 2 / st b 2;
else if (condition 3) st3 / st B 3;
else if (condition n) st n / st B n;
else st n+1 / st B n+1;
if (per > = 70) div = “ Distinction”;
else if (per > = 60) div = “ first”;
else if (per > = 50) div = “ second”;
else if (per > = 40) div = “ pass”;
else Div = “Fail”;
(iv) Nested if Statement:- This statement is used to check multiple conditions and based on
LIFO (Last In First Out) principle. In this concept Successive condition will be checked if
the preceding condition is true. In case of false result of any condition the statement/s
followed from last else will be executed.
Syntax:-
if (cond 1)
if (cond 2)
if (cond 3)
if (cond n) st1 / st B1;
else st 2 / st B 2;
else st n / st B n;
else st n +1 / st B n+1
Ex:-
if (per >=40)
if (per >=50)
if (per >=60)
if (per >=70) Div = “Distiction”;
else Div = “First”;
else Div = “Second”;
else Div = “Pass”;
else Div = “Fail”;
Switch ( ) Statement:- Also used for multiple branching.
* An expression value passed to the function.
* According to the possible expression value we must design the specific cases for
different.
* We have to match the expression value with the particular case value.
* There are four reserve words used in switch statement like:-
switch
case
break
default
* Every matching follows the statements look and then program execution reached at break
alternate the case.
* In case of non-matching of possible case values of the expression value the default case
will be executed and switch will be terminated.
Syntax:-
Switch (expression)
{ case value 1: st 1/ st B1; Break;
case value 2: st 2/ st B2; Break;
case value n: st n/ st n; Break;
default;
st n+1 / stB n+1;
}
Looping

Definte Indefinite

fixed

for ( )loop
Entry controlled Exit controlled

Before body At least

Checked the condition one time the body of


the loop must be
one time, may or not execution.
any time
do while loop
while loop
● for ( ) loop:- It is definite looping.
* Number of repetition of body of loop is fixed.
* In this concept three technical approaches of loop control variable maintained.
➢ Initialization
➢ Testing of condition
➢ Increment / Decrement of looping steps.
Syntax:-
for (initialization ; Teat condition; step increment / decrement)
statement1 / st B1;
To display 1 to 100
for ( i = 1 ; i < = 100; i ++)
{
[Link]( i + “ ”);
}
● While loop:-
➢ The number of repetitions is not known.
➢ We have to check the condition before execution of the body of the loop.
➢ The body may be executed at one time, many times or not any time.
Syntax:-
while (condition)
{ Body of loop
i = p;
while ( i < = 100)
{ system out print n ( i + b);
i ++ ;
}
● do while loop:-
* Number of repeatation is known.
* At least nature the body of loop must be executed.
Syntax:-
do
{ ……….. Body of loop
{ while (condition);
i = 0;
do
{
i ++;
[Link](i+” ”);
}
while (i < 100);
● Jumps in loop:- The concept of linear programming involve jumping throughout in the
program using goto label statement. In the object oriented programming basically in java
there is not the concept of jumping like the presence approach.
When the situation in a program is to jump from one part to another
conditionally the break statement is used. In case of using continue statement the looping
will be skilled to the next iteration.
Syntax :-I
Looping statement
if (condition) break;
Syntax:-II
Looping statement
{
if ( cond. ) continue;
………….
…………. { IInd part shipped
}
● Labeled loop:- In java we can used label to a block of statement. A label any valid java
variable name. In case of labeled looping, the jumping, the jumping will be condition to a
particular label name. A label name will be valid name followed by colon (:).
loop1: for (…………)
{………..
…………..}
(a) while (test condition)
{…………….
if (……..)
continue;
}
(b) do
{……….
if (…………….
continue;
…………
…………
while (test condition);

(C) for(initialization ; test condition; increment)


{
………….
if (………….)
continue;
}

You might also like