0% found this document useful (0 votes)
37 views41 pages

Java Programming Basics and Concepts

Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere" (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of computer architecture. As of 2016, Java is one of the most popular programming languages in use, particularly for client-server web applications.

Uploaded by

Sohail Shaghasi
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)
37 views41 pages

Java Programming Basics and Concepts

Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere" (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of computer architecture. As of 2016, Java is one of the most popular programming languages in use, particularly for client-server web applications.

Uploaded by

Sohail Shaghasi
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

Java Fundamentals

Sohail Shaghasi
[Link]@[Link]
Course Overview
What is computer program?
What is high level and low level language?
Introduction to Java.
What is an IDE?
How Java program Gets executed (Java life cycle)?
What is Variable?
What is Variable Scope?
What is Constant?

[Link]@[Link]
Course Overview Cont.
What is Operator?
What is primitive type?
What is String?
What is array?
What are control statements (if / else, Switch , For, while, Break/Continue)?
What is function/Method?
What is Class ?
What is Constructor?
What is Object ?
What is Access Modifiers?
What is OOP?
Pillars of OOP

[Link]@[Link]
What is Computer Program?

Program is a set of instruction given to a computer to perform a specific task.


Some examples of computer programs:
A web browser like Mozilla Firefox and Apple Safari can be used to view web pages
on the Internet.
An office suite can be used to write documents or spreadsheets.
Video games are computer programs.

[Link]@[Link]
What is High level and Low Level
language?
Characteristics of High level languages:
Easier to understand and user friendly.
Extremely portable.
Can be debugged in an easier manner.

Characteristics of Low level language:


Extremely difficult to understand.
Nearer to Machine code.
Appropriate for developing new operating system.
Appropriate for microcontrollers programming.
[Link]@[Link]
Introduction to Java

Programming language based on C and C++.


Designed to be written once and run anywhere (cross platform).
Runs on virtual machine.
Very similar to C#.
Java is Object Oriented.

[Link]@[Link]
What is an IDE?
IDE means
Integrated Development Environment.
An IDE is software application.
Eclipse, Netbeans and Microsoft Visual studio are IDEs.
You can do many things using IDE
Implement databases.
Design User interfaces.
Program an application.
Compile/build an application
Test an application.
Debug an application.
Diagraming.
[Link]@[Link]
Java life Cycle
How Java program gets executed?

[Link]@[Link]
What is Variable?
Just like a variable in a math equation
1+3=4
1+x=?
Without variables programs would be non-interactive
Variables allow us to store data in our program
Opposite of a constant
Syntax:
The number 3 is a constant
X is a variable

[Link]@[Link]
What is Variable Scope?

Global Variables:
Declared outside any function.
Local Variable:
Declare inside a function.
To simplify things, just think of the scope as anything
between the curly braces {}. The outer curly braces are
called the outer blocks , and the inner curly braces are
called inner blocks.

[Link]@[Link]
What is constant?

It is a variable whose value cant change.

[Link]@[Link]
What is Operator?

Assignment
=
+=
-=
*=
/=
%=

[Link]@[Link]
Operators Cont

Relational
>
<
>=
<=
==
!=

[Link]@[Link]
Operators Cont.

Logical
&&
||
!

[Link]@[Link]
What are primitive types?
What is Array?

An array is a group of contiguous or related data items that share a common name.
Used when programs have to handle large amount of data
Each value is stored at a specific position
Position is called a index or superscript. Base index = 0 0 69

1 61
index
2 70

3 89 values

4 23

5 10
[Link]@[Link]

6 9
Array Cont.

Like any other variables, arrays must declared and created before
they can be used. Creation of arrays involve three steps:
Declare the array
Create storage area in primary memory.
Put values into the array (i.e., Memory location)

String[] students = new String[10];


String[] students = new String []{st1, st2, st3};

[Link]@[Link]
What are Control statements?

if else
switch
while
do while
For
For Each
break
continue
[Link]@[Link]
If - else

if(conditional_statement)
{
statement to be executed if conditional_statement becomes true
}
Else
{
statements to be executed if the above conditional_statement
becomes false
}
[Link]@[Link]
Switch
switch (n)
{
case expression1:
// code to be executed if n is equal to expression1;
break;
case expression :
// code to be executed if n is equal to expression1;
break;
default:
// code to be executed if n doesn't match any expression1
}

[Link]@[Link]
Switch statement Flowchart

[Link]@[Link]
While loop

while(condition_statementtrue)
{
Statements to be executed when the condition becomes true and execute
them repeatedly until condition_statement becomes false.
}
E.g.
int x = 2;
while(x>5){
[Link](value of x:+x);
x++;
}
[Link]@[Link]
Do while loop

do
{
statements to be executed at least once without looking at the condition.
The statements will be executed until the condition becomes true.
}
while(condition_statement);

[Link]@[Link]
Comparing while and do-while loops

[Link]@[Link]
For loop

for(initialization; condition; increment/decrement){

statements to be executed until the condition becomes false


}
E.g:
for(int x = 0; x < 10; x++)
{
[Link](value of x:+x);
}

[Link]@[Link]
Break

Break is used in the loops and when executed, the control of the execution will come out of the
loop.

E.g:

for(int i=1;i<50;i++)
{
if(i%11==0)
{
[Link](Before breaking the loop);
break;
}
[Link](Value of i:+i );
}

[Link]@[Link]
Continue

Continue makes the loop to skip the current execution and continues with the next iteration.

E.g:

for(int i=1;i<50;i++)
{
if(i%11==0)
{
[Link](Before breaking the loop);
continue;
}
[Link](Value of i:+i );
}

[Link]@[Link]
What is function/Method?

A function is section of a program that has a name and performs a specific


task.
Function definition:
Return Type A function may return a value
Function Name This is the actual name of the function.
Parameter List A parameter is like a placeholder. When a function is
invoked, you pass a value as a parameter.
Function Body collection of statements that describes what the function
does.

[Link]@[Link]
Function Cont.
parameters

Function
Access Return
name
Modifier type

Method body

return

[Link]@[Link]
What is Class?

Class can be thought of as a template, a prototype or a blueprint of an


object.
It is a fundamental structure in Object oriented programming.

Two types of class members:


Fields (properties or attributes)
Methods
Specify the operations.

[Link]@[Link]
What is Constructor?

Constructor is a method where you place all the initialization, it has the same
name as the class.
When you create an object, you actually invoke the class constructor.

new Operator
Allocated a memory for that object and returns a reference of that memory
location to you.

Dot operator
It allows you to access public properties and public methods of a respective
class.
[Link]@[Link]
Constructor cont.

[Link]@[Link]
What is Object?

An object is an instance of a class.


To create an object the new operator is used.
For example if you want to create an instance of class String, we write the
following code,
String str = new String(Hello World);

Or also equivalent to
String str = Hello World;

[Link]@[Link]
Object cont.

[Link]@[Link] Object
What are Access Modifiers?
Access within class within package outside outside
Modifier package by package
subclass only

Private Yes No No No

Default Yes Yes No No

Protected Yes Yes Yes No

Public Yes Yes Yes Yes

[Link]@[Link]
What is OOP?

object-oriented programming:
A programming paradigm where a software system is represented as a
collection of objects that interact with each other to solve the overall task.

[Link]@[Link]
Four Pillars of OOP

Object-oriented programming is based on these 4 pillar:


Abstraction
Polymorphism
Inheritance
Encapsulation

APIE

[Link]@[Link]
Abstraction

In java, we can have an abstract class without any abstract method. This
allow us to create classes that cannot be instantiated, but can only be
inherited.

Abstract classes cannot be instantiated, means we cant create object to


Abstract class.

We can create subclasses to Abstract classes.

[Link]@[Link]
Polymorphism

Polymorphism is the capability of a method to do different things based on


the object.

[Link]@[Link]
Inheritance

One of the most effective feature of OOP paradigm.

Establish link/connectivity between 2 or more classes.

Permits sharing and accessing properties from one to another class.

To establish this relation java uses extends keyword.

[Link]@[Link]
Encapsulation

Encapsulation is the technique of making the fields in a class private and


providing access to the fields via public methods.

If a field is declared private, it cannot be accessed by outside classes.

Encapsulation is referred to as data hiding.

[Link]@[Link]

You might also like