Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views28 pages

Overview of Java

Uploaded by

piedpiperbot
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)
4 views28 pages

Overview of Java

Uploaded by

piedpiperbot
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
You are on page 1/ 28

JAVA

FUNDAMENTALS
Presented BY
Keywords
Source Code & Machine
Java Byte Code
Code
05 It is an machine instruction for
The code written by a programmer is
JVM. It is independent of the
usually called the Source Code.
computer it has to run upon.
Whereas, the code which a machine
can understand is known as Machine
Code or Native Executable Code 01 04 Java Virtual Machine (JVM)
JVM enables a computer to run
Compiler & Interpreter
Java programs as well as other
Compiler is a special program which languages that are also compiled
converts source code to machine to Java Byte Code.
code, all at once. Interpreter is a
special program which translates the Java API
program instruction by instruction i.e 02 03
line by line. JAVA API are libraries of compiled
code that can be used in your
programs. In simple words, it
consists of variables & functions
which can be used by
programmers in their applications.
Programming Paradigms
All computer programs consist of two elements: code and data. A program can be
conceptually organized around its code or around its data.

● FIRST PARADIGM

Process Oriented Programming (POP): A programming language that follows a


step-by-step approach to break down a task into a collection of variables & routines
through a sequence of instructions. It is a list of instruction which execute in a
systematic order that tell the computer what to do. Procedural languages such as C
employ this model to considerable success.
Programming Paradigms
● SECOND PARADIGM:

Object Oriented Programming (OOP): To manage increasing complexity, this second


approach, was conceived. OOP uses classes and objects to create models based on
the real world environment. It organizes a program around its data (that is, objects)
and a set of well-defined interfaces to that data.

Soon you will see, by switching the controlling entity to Data, you can achieve several benefits
General OOP Concepts
Data
Abstraction

The object-oriented approach is based on


certain concepts which have been
developed with a view to overcome the General
Polymorphism OOP Encapsulation
drawbacks of conventional programming
Concepts
approaches.

Inheritance
OOP Concepts
ENCAPSULATION:

● It is basically the simple process of wrapping of various


characteristics of a program such as code, etc., into a
single unit.

● One way to think about encapsulation is as a protective


wrapper that prevents the code and data from being
arbitrarily accessed by other code defined outside the
wrapper.

● In JAVA, encapsulation is best represented by


methods/functions. To prevent malicious codes from
accessing a method, keywords such as public, private,
friendly, etc. help secure the encapsulated code.
OOP Concepts
ABSTRACTION:

● ------------
OOP Concepts
INHERITANCE:

● Inheritance is the process by which one object acquires the


properties of another object.

● Inheritance and encapsulation go hand in hand.


For example: “ If a given class encapsulates some
attributes, then any subclass will have the
same attributes plus it adds to its existing
properties.”

● ‘extends’ is the keyword used to inherit the properties of a


class.
OOP Concepts
POLYMORPHISM:

● The word polymorphism means having many forms. In


simple words, we can define polymorphism as the ability of a
SHAPE
message to be displayed in more than one form. area( )

● There are two types of polymorphism:


i) Compile Time Polymorphism
eg. Method overloading, Operator Overloading
CIRCLE RECTANGLE
area(circle) area(rectangle)
ii) Runtime Polymorphism
eg. Method Overriding
What’s Inside a Java Program?

public : Access specifier which indicates whether other methods/classes have access to it or not.

Void : Indicates the return type of the method, alternatives are int, float, double,etc.

System.out.println(“...”) : Prints anything within the quotes on the standard output device

/*…*/ : Syntax for multiline comments. Anything within the these would not be executed by the compiler.

String args[ ] : declares a parameter named args, which is an array of instances of the class String
Lexical Issues
Java uses the Unicode character set. Unicode is a two byte character code which
represents almost all characters in the alphabet system.

One can refer to a Unicode character by using the escape sequence \u followed by
four digit hexadecimal number.

A token is the smallest individual unit in a JAVA program. Java has 5 types of tokens:

Keywords Identifiers Literals Punctuators Operators


Lexical Issues
Keyword: Literally words which constitute the syntax of the code. true, false, null are not keywords
but reserved words.

Identifiers: Are used to name any method/class/variable, etc.

Literals: Also known as constants eg. 12, 14.5, etc. These have fixed values.

Separators: ( ) { } [ ] ; , . All these nine constitute as separators.

Operators: There are approximately 37 operators:


Data Types
Data can be of many types e.g. character, integer, real, etc. Data types are means to
identify the type of data and associated operations of handling it. Java data types are of two
types:

● PRIMITIVE DATA TYPES: byte, short, int, long, float, double, char, boolean

● REFERENCE DATA TYPES: classes, arrays, interface


Data Types
Variables
● Variables are named memory location, which holds a data value of a particular data type.

Its syntax is: datatype variable_name = value


For example: int i = 5 ;
The above example stores value 5 in variable i of the data type int.

● Variables have to be declared first before using them.


● Second step involves initializing the variable. This can be done by two methods:

i) Static Initialization - int a = 10 ;


ii) Dynamic Initialization - int b = a*10 ;

Adding the final keyword before the datatype during declaration makes the variable a constant.
Operators
An operator in Java is a symbol that is used to perform operations like addition, subtraction, relation, etc.
Some of the operators in java are:

● Arithmetic Operators
○ Unary Operator : [ + , - ] NOTE NOTE
○ Binary Operator : [ + , - , * , / , % ]
Increment & Postfix operators
● Increment / Decrement Operators : [ ++ , -- ] Decrement are have higher
○ Prefix unary operators precedence over
○ Postfix prefix operators.

● Relational Operators : [ < , > , <= , >= , == , != ]

● Logical Operators : [ && , || , ! ] Java Shorthand Operators

● Assignment Operators : [ = , += , -= , *= , /= , %= ]
Operators
● Shift Operators : [ >> , << , >>> ]

● Other Operators

○ Conditional / Ternary Operator : [ expression1 ? expression2 : expression3 ]

○ [ ] Operator : for arrays

○ Dot Operator : [ . ]

○ ( ) Operator : for declaring or calling a method

○ new Operator : for creating a new object or an array


Type Conversion
● Implicit Type Conversion

This type of conversion is usually performed automatically


by the compiler

● Explicit Conversion

Also known as Type Casting. This type of conversion is performed


manually by the user in the code itself.

The syntax of this conversion is:- (type) expression


Control Statements

Conditional Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit
Statements amet odio vel purus bibendum luctus.

Looping Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit
Statements amet odio vel purus bibendum luctus.

Jump Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis
Statements sit amet odio vel purus bibendum luctus.
Conditional Statements

● The ‘if’ statement

● The ‘if-else’ statement

● The ‘else-if’ statement


Conditional Statements

● The ‘switch’ statement


NOTE
Every switch case
should end with a
break keyword to
prevent
fall-through.

The last case should always be the default case, even though not necessary but a good programming practice.
Looping Statements

● The ‘for’ statement

● The ‘while’ statement

● The ‘do-while’ statement


Looping Statements

● Every looping statement has:


Jump Statements
● The ‘break’ statement
A break statement skips the rest of the loop and jumps over to the
statement following the loop NOTE
The difference between
● The ‘continue’ statement break and continue is
It is used to skip the rest of the current loop iteration and start the next break terminates the
iteration. entire loop but continue
Eg. If continue is encountered in the 2nd iteration, the rest of the code is terminates the particular
skipped and the 3rd iteration begins running. iteration of the loop.

● The ‘return’ statement


It is used to terminate a function call and send the control back to the
function which initiated the function call.
All About Arrays
An array is a collection of variables of the same type that are reference by a common name, to avoid
multiple variable declarations.
Arrays are of two types:

● One-dimensional Arrays : Comprised of finite homogeneous elements.

● Multi-dimensional Arrays : Comprised of elements, each of which is itself an array.

Arrays are declared in the following manner:

One-dimensional- type array_name[ ] = new type[size]; or type[ ] array_name = new type[size];

Two-dimensional- type array_name[ ][ ] = new type [rows] [columns]; or


type[ ][ ] array_name = new type [rows] [columns];
All About Arrays
An array
Keywords
SAMPLE TEXT
THANK YOU!

You might also like