SlideShare a Scribd company logo
UNIT I
OBJECT ORIENTED PROGRAMMING FUNDAMENTALS
Object Oriented Programming Paradigm - Basic
Concepts of Object Oriented Programming –
Benefits and Applications of OOP – Java Features –
Java Program Structure – Command Line
Arguments – Variables and Data Types – Operators
– Expressions – Arrays - Control Statements –
Selection – Iteration - Jump Statements
OBJECT ORIENTED PROGRAMMING
FUNDAMENTALS
• Object=Data + Methods
Features of OBJECT ORIENTED
PARADIGMS
1. Data
2. Objects
3. Data structures
4. Methods
5. Hidden data
6. Communication
7. Addition of new data
8. Bottom up approach
Basic concepts of OBJECT ORIENTED
PROGRAMMING
I. OBJECTS & CLASSES
II. DATA ABSTRACTION & ENCAPSULATION
III. INHERITANCE
IV. POLYMORPHISM
V. DYNAMIC BINDING
VI. MESSAGE COMMUNICATION
I.OBJECTS & CLASSES
• Object-Basic runtime entity
• Class- Collection of objects of similar type
II.DATA ABSTRACTION &
ENCAPSULATION
• Encapsulation–Wrapping up of data and
methods into single unit(called class).
• Data hiding –Insulation of data from direct
access by program.
• Data abstraction Representing essential
features only.
III.INHERITANCE
• Objects of 1 class acquire the properties of
objects of another class.
IV.POLYMORPHISM
• Ability to take more than one form
V.DYNAMIC BINDING
• Linking of procedure call to code.
• Linking of method call to its corresponding
method definition takes place only during
runtime.
VI.MESSAGE COMMUNICATION
There are 3 steps.
• Class creation
• Object creation
• Establish communication
BENEFITS OF OOP
• Inheritance
• Time saving and high productivity.
• Data hiding
• Multiple objects
• Mapping of objects
• Easy to upgrade
• Communication through messages
• Can manage software complexity easily
APPLICATIONS OF OOP
• Real time systems.
• Simulation & Modelling.
• Object oriented DB
• AI
• Neural networks
JAVA FEATURES
Introduction:-
• Java is an object oriented language developed
by Sun Microsystems.
• Original name was OAK . Later renamed to
JAVA.
• Platform neutral language(platform
independent.)(Java Virtual Machine).
• Java is both compiled and interpreted
language.
Compilation Process
Execution Process
JAVA FEATURES
1. Java is both a compiled and an interpreted language.
2. Platform independent and portable-Write Once Run
Anywhere.
3. Object Oriented.
4. Robust and Secure.
5. Distributed.
6. Automatic Memory Management.
7. Dynamic binding
8. High performance.
9. Multithreading.
Some features in C/C++ are eliminated in java.
They are listed below.
• No Pointers
• No Preprocessor Directives
• No Multiple Inheritance in Classes
• No operator overloading.
• No global variables.
Simple Java Program
class Welcome
{
public static void main(String args[])
{
System.out.println(“Welcome to Java world “);
}
}
JAVA PROGRAM STRUCTURE
Simple Java Program
/* * To change this template, choose Tools | Templates and open the template in the
editor. */
package college;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql;
class sum
{
public static void main(String args[])
{
int i=10,j=25;
k=i+j;
System.out.println(“THE SUM IS “+k);
}
}
Download JDK and install in
Windows10- Use the following
YouTube link.
https://video.search.yahoo.com/search/video?fr
=mcafee&ei=UTF-
8&p=download+jdk&type=E211US1045G0#id=4
&vid=3aa873b105c9f56e6a73b619da6222ba&a
ction=click
Compilation code- javac filename.java
Execution code- java filename
JAVA TOKENS
• In Java every statement is made up of smallest
individual elements called tokens. Tokens in java
include the following:-
1. Keywords
2. Identifiers
3. Literals
4. Operators
5. Separators
1. Keywords
• Keywords cannot be redefined by a
programmer
• Keywords cannot be used as identifier name.
Eg: Abstract, Assert, Boolean, Break, Byte, Case.
• Java language has reserved 50 words as
keywords.
2. Identifiers
• Programmer designed tokens. Used for naming
variables, methods, classes etc.
• An identifier can contain alphanumeric
characters, but it should begin with an alphabet.
• Identifiers are case sensitive.
• Underscore and dollar sign are two special
character allowed.
• Eg:A23C
• Bob@gmail - Wrong
3. Literals
• LITERAL is a program element that represents
an exact (fixed) value of a certain type. Java
language supports the following type of
literals.
1. Integer Literals. (Ex. 123)
2. Floating point Literals. (Ex. 88.223)
3. Character Literals. (Ex. ‘.’ , ‘a’ , ‘n’)
4. String Literals. (Ex. “Hello World”)
5. Boolean Literals. (Ex. True,false)
4. Separators
• Symbols used to indicate where group of code
are divided and arranged.
• ()
• {}
• []
• ;
• ,
• .
5. Operators
• Tells the computer to perform certain
mathematical or logical manipulations on data
and variables. Different types are:-
1. Arithmetic Operators.
2. Unary Operators.
3. Assignment Operators.
4. Equality and Relational Operators.
5. Logical and Conditional Operators.
6. Bitwise and Bit Shift Operators.
7. Special operators
1. Arithmetic Operators
Eg: a+b
a-b
a*b
a/b
a%b
2. Unary Operators
Eg: +b
-b
++b
--b
3. Assignment Operators
Eg:a=b+c;
a=a+1; and a+=1; same meaning.
a+=1 is shorthand assignment operator.
4. Equality and Relational Operators
Eg: a==b;
a!=b;
• Value of relational expression is either true or false.
• It is used in decision statements.
Eg: a<b;
a>b;
a<=b;
a>=b;
5. Logical and Conditional Operators.
• Used to form compound conditions by combining 2 or more
relations.
&& -logical AND
|| -logical OR.
! – logical compliment.
Eg: a>b && x==10;
?: - Conditional ternary opeartor(shorthand for if-then-else
statement).
Eg: x=(a>b)?a:b;
6. Bitwise and Bit Shift Operators
~ Unary bitwise complement
<< Signed left shift
>> Signed right sift
>>> Unsigned right shift
& Bitwise AND
^ Bitwise exclusive OR
| Bitwise inclusive OR
7. Special Operators
1. Instanceof operator
Eg: person instanceof student.
• Checks whether object person belongs to class student or not.
• Returns either true or false
2. Dot operator /member selection operator
• Used to access variables and methods of a class object.
Eg: Person1.age;
Person1.salary();
Where person1 is an object .
Age is a variable
Salary() is a method.
Example:Operators
• public class StringLowerUpperExample{
• public static void main(String args[]){
• String s1="JAVATPOINT HELLO stRIng";
• String s1lower=s1.toLowerCase();
• System.out.println(s1lower);
• String s2="hello string";
• String s1upper=s2.toUpperCase();
• System.out.println(s1upper);
• }}
Operator Precedence Table
Operator Precedence
Operators Precedence
postfix expr++ expr--
unary ++expr --expr +expr -expr ~ !
multiplicative * / %
additive + -
shift << >> >>>
relational < > <= >= instanceof
equality == !=
bitwise AND &
bitwise exclusive OR ^
bitwise inclusive OR |
logical AND &&
logical OR ||
ternary ? :
assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=
EXPRESSIONS
• Java expressions are used to implement some computation.
• Syntax: Variable=Exprerssion;
• Simple Expression : x=a+b;
• Complicated expression : a*(b+c)/(m+n)*f;
In this example,
1. (b+c) or (m+n) executed first since it is written inside
brackets.(From left to right or right to left. Refer operator
precedence table in Unit1Part1.pdf).
2. a*(b+c), or (m+n)*f executes multiplication operation secondly.
3. Finally division operation takes place.
COMMAND LINE ARGUMENTS
• Command line arguments are parameters that are supplied to the
application program at the time of invoking it for execution.
• Eg:- public static void main(String args[]).
• Eg: javac hello.java
java hello 123 abc 12.88
Then,
• args[0] contains 123
• args[1] contains abc
• args[2] contains 12.88
• Wrapper classes are used to convert the string to corresponding
simpler data type.
• ie, static int parseInt(String s)
• For example: int value= Integer.parseInt(“123”)
• Int total=args.length;
• Converts stirng 10 to integer data type.
Fibonacci series
class fib{
public static void main(String args[])
{
int n;
int a=0,b=1,c;
n=Integer.parseInt(args[0]);
for(int i=0;i<n;i++)
{
c=a+b;
System.out.println("The next number is "+c);
a=b;
b=c;
}
}
}
VARIABLES
• Variables refers to names of storage location
which is used to store data vales.
Eg: int i;
int i=3,j=5;
• Can take different values at different times during
execution of the program.
• Similar as identifiers.
• Assignment method
• readline() method.(Type casting)
Variables example- readLine()
import java.io.Console;
class exampleread
{
public static void main(String args[])
{
String str;
Console con = System.console();
if(con == null)
{
System.out.print("No console available");
return;
}
str = con.readLine("Enter your name: ");
con.printf("Here is your name: %sn", str);
}
}
VARIABLES(readLine() & Type casting
using wrapper classes)
import java.io.Console;
class examplereadline
{
try{
public static void main(String args[])
{
int age=0;
Console con = System.console();
age= Integer.parseInt(con.readLine("Enter your age") );
con.printf("Here is your age:%dn", age);
}
}
Catch{
}
}
Scope of variables
• Instance variables - Created when objects are instantiated and
takes different values for each object.
Eg: student s1=new student();
• Each object has its own copy of instance variables.
• Class variables - Available to all methods in a class.
• Local variables – Local to the method inside it is declared.
Scope of variables-Example
// Demonstrate block scope.
class Scope {
public static void main(String args[]) {
int x; // known to all code within main
x = 10;
if(x == 10) { // start new scope
int y = 20; // known only to this block
// x and y both known here.
System.out.println("x and y: " + x + " " + y);
x = y * 2;
}
// y = 100; // Error! y not known here
// x is still known here.
System.out.println("x is " + x);
}
}
CONSTANTS
• Constants refer to values that do not change
during the execution of the program.
• Java supports following types of constants.
• Integer constant. Eg:2021.
• Real/Floating point constant. Eg: 32.567.
• String constant. Eg: “Hello World”.
• Character constant. Eg: ‘a’.
• Final float pi=3.142;
• Apart from these types of constants java also
supports backslash character constants.
BACKSLASH CONSTANT PURPOSE
b Backspace
f Form feed
n New Line
r Carriage return
t Horizontal tab
 Backslash
DATA TYPES
Data types
Integer
char a = 'G';
int i=89;
byte b = 4;
short s = 56;
float f = 4.7333434f;
double d = 4.355453532d;
Data types- Example
class datatypes{
public static void main(String args[]){
char a = 'G';
int i=89;
byte b = 4;
short s = 3;
double d = 4.355453532d;
float f = 4.7333434f;
System.out.println("char: " + a);
System.out.println("integer: " + i);
System.out.println("byte: " + b);
System.out.println("short: " + s);
System.out.println("float: " + f);
System.out.println("double: " + d);
}
}
ARRAYS
• An array is a group of contiguous/related data
items that share a common name.
• Syntax: Data type Arrayname[];
• Eg: int salary[9] or int[] salary;
• 3 steps to create the array.
• 1) Declare the array->Only a reference of array
created.
• 2) Create the memory allocation->
salary=new int[9];
• 3)Putting values to memory location.
Array representation:-
Int a=Arrayname.length; // To find length of the array.
One dimensional Arrays.
Array Literal
In a situation, where the size of the array and variables of
array are already known, array literals can be used.
int[] intArray = new int[]{ 1,2,3,4,5,6,7,8,9,10 };
class Testarray{
public static void main(String args[]){
int a[]=new int[5];//declaration and instantiation
a[0]=10;//initialization
a[1]=20;
a[2]=70;
a[3]=40;
a[4]=50;
//traversing array
for(int i=0;i<a.length;i++)//length is the property of array
System.out.println(a[i]);
}}
Arrays as Parameters
 An entire array can be passed as a parameter to a
method
 Like any other object, the reference to the array is
passed, making the formal and actual parameters aliases
of each other
 Changing an array element within the method changes
the original
 An array element can be passed to a method as well, and
follows the parameter passing rules of that element's
type
class Testarray3{
//creating a method which receives an array as a parameter
static void min(int arr[]){
int min=arr[0];
for(int i=1;i<arr.length;i++)
if(min>arr[i])
min=arr[i];
System.out.println(min);
}
public static void main(String args[]){
int a[]={33,3,4,5};//declaring and initializing an array
min(a);//passing array to method
}}
Two Dimensional Arrays
int[][] intArray = new int[10][20]; //a 2D array
or matrix
Array-Assigning values can be done directly or
using loops.
public static void main(String args[])
{
// declaring and initializing 2D array
int arr[][] = { {2,7,9},{3,6,1},{7,4,2} };
// printing 2D array
for (int i=0; i< 3 ; i++)
{
for (int j=0; j < 3 ; j++)
System.out.print(arr[i][j] + " ");
System.out.println();
}
}
Multi Dimensional Arrays
• int[][][] intArray = new int[10][20][10]; //a 3D
array .
• Known as Jagged Arrays.
• Strings- Character Array or String Objects.
STRINGS
• It is the most common part of many java
programs.
• String represent a sequence of characters.
• The simplest way to represent a sequence of
characters in java is by using a character array.
• Example:
char charArray[ ] = new char[4];
charArray[0] = ‘J’;
charArray[1] = ‘a’;
DECLARATION OF STRING
• Example:
STRING ARRAYS
• Array can be created and used that contain
strings.
• Above statement create following effects:
 In Java, strings are class objects and implemented
using two classes,namely, String and StringBuffer.
 A java string is an instantiated object of the String
class.
 Java string as compared to C strings, are more
reliable and predicable.
 A java string is not a character array and is not
NULL terminated.
STRING METHODS
 String class defines a number of methods that
allow us to accomplish a variety of string
manipulation tasks.
 Eg: 1) s2=s1.toLowercase;
2) s2=s1.toUppercase;
3) s1.compareTo(s2) //To sort array of
strings.
STRING BUFFER CLASS
 StringBuffer is a peer class of String.
 While String creates strings of fixed_length,
StringBuffer creates strings of flexible length that
can be modified in term of both length and content.
 We can insert characters and substrings in the
middle of a string to the end.

More Related Content

What's hot

Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
Sowmya Jyothi
 
Yacc
YaccYacc
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
Vivek chan
 
7 compiler lab
7 compiler lab 7 compiler lab
7 compiler lab
MashaelQ
 
Code generation
Code generationCode generation
Code generation
Aparna Nayak
 
Monadic genetic kernels in Scala
Monadic genetic kernels in ScalaMonadic genetic kernels in Scala
Monadic genetic kernels in Scala
Patrick Nicolas
 
User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2
Shameer Ahmed Koya
 
Compiler Design Tutorial
Compiler Design Tutorial Compiler Design Tutorial
Compiler Design Tutorial
Sarit Chakraborty
 
Compiler unit 2&3
Compiler unit 2&3Compiler unit 2&3
Compiler unit 2&3
BBDITM LUCKNOW
 
Programming in c by pkv
Programming in c by pkvProgramming in c by pkv
Programming in c by pkv
Pramod Vishwakarma
 
C language (Collected By Dushmanta)
C language  (Collected By Dushmanta)C language  (Collected By Dushmanta)
C language (Collected By Dushmanta)Dushmanta Nath
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
Wingston
 
Functions
FunctionsFunctions
Functions
Online
 
C language for Semester Exams for Engineers
C language for Semester Exams for Engineers C language for Semester Exams for Engineers
C language for Semester Exams for Engineers
Appili Vamsi Krishna
 
07 control+structures
07 control+structures07 control+structures
07 control+structures
baran19901990
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
Mansi Tyagi
 
Handout#10
Handout#10Handout#10
Handout#10
Sunita Milind Dol
 
Object-Oriented Programming Using C++
Object-Oriented Programming Using C++Object-Oriented Programming Using C++
Object-Oriented Programming Using C++
Salahaddin University-Erbil
 

What's hot (20)

Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
 
Yacc
YaccYacc
Yacc
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
 
7 compiler lab
7 compiler lab 7 compiler lab
7 compiler lab
 
Code generation
Code generationCode generation
Code generation
 
Monadic genetic kernels in Scala
Monadic genetic kernels in ScalaMonadic genetic kernels in Scala
Monadic genetic kernels in Scala
 
User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2
 
Compiler Design Tutorial
Compiler Design Tutorial Compiler Design Tutorial
Compiler Design Tutorial
 
Compiler unit 2&3
Compiler unit 2&3Compiler unit 2&3
Compiler unit 2&3
 
Programming in c by pkv
Programming in c by pkvProgramming in c by pkv
Programming in c by pkv
 
C language (Collected By Dushmanta)
C language  (Collected By Dushmanta)C language  (Collected By Dushmanta)
C language (Collected By Dushmanta)
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
Lexyacc
LexyaccLexyacc
Lexyacc
 
Functions
FunctionsFunctions
Functions
 
C language for Semester Exams for Engineers
C language for Semester Exams for Engineers C language for Semester Exams for Engineers
C language for Semester Exams for Engineers
 
07 control+structures
07 control+structures07 control+structures
07 control+structures
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 
Handout#10
Handout#10Handout#10
Handout#10
 
Java chapter 3
Java chapter 3Java chapter 3
Java chapter 3
 
Object-Oriented Programming Using C++
Object-Oriented Programming Using C++Object-Oriented Programming Using C++
Object-Oriented Programming Using C++
 

Similar to Programming in java basics

02basics
02basics02basics
02basics
Waheed Warraich
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
VijalJain3
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_reviewEdureka!
 
Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
Akash Pandey
 
Java
Java Java
Spring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffSpring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard Wolff
JAX London
 
Java introduction
Java introductionJava introduction
Java introduction
Samsung Electronics Egypt
 
Java Intro
Java IntroJava Intro
Java Introbackdoor
 
Ifi7184 lesson3
Ifi7184 lesson3Ifi7184 lesson3
Ifi7184 lesson3
Sónia
 
Java programing language unit 1 introduction
Java programing language unit 1 introductionJava programing language unit 1 introduction
Java programing language unit 1 introduction
chnrketan
 
Session 1 of programming
Session 1 of programmingSession 1 of programming
Session 1 of programming
Ramy F. Radwan
 
Java 8
Java 8Java 8
Java 8
Raghda Salah
 
C#2
C#2C#2
c++ UNIT II.pptx
c++ UNIT II.pptxc++ UNIT II.pptx
Chapter 2 java
Chapter 2 javaChapter 2 java
Chapter 2 java
Ahmad sohail Kakar
 
Java 101
Java 101Java 101
Java 101
Manuela Grindei
 
Scala and Spring
Scala and SpringScala and Spring
Scala and Spring
Eberhard Wolff
 
C
CC

Similar to Programming in java basics (20)

02basics
02basics02basics
02basics
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
 
Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
 
Unit 1
Unit 1Unit 1
Unit 1
 
Java
Java Java
Java
 
Spring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffSpring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard Wolff
 
Java introduction
Java introductionJava introduction
Java introduction
 
Java Intro
Java IntroJava Intro
Java Intro
 
Ifi7184 lesson3
Ifi7184 lesson3Ifi7184 lesson3
Ifi7184 lesson3
 
1_JavIntro
1_JavIntro1_JavIntro
1_JavIntro
 
Java programing language unit 1 introduction
Java programing language unit 1 introductionJava programing language unit 1 introduction
Java programing language unit 1 introduction
 
Session 1 of programming
Session 1 of programmingSession 1 of programming
Session 1 of programming
 
Java 8
Java 8Java 8
Java 8
 
C#2
C#2C#2
C#2
 
c++ UNIT II.pptx
c++ UNIT II.pptxc++ UNIT II.pptx
c++ UNIT II.pptx
 
Chapter 2 java
Chapter 2 javaChapter 2 java
Chapter 2 java
 
Java 101
Java 101Java 101
Java 101
 
Scala and Spring
Scala and SpringScala and Spring
Scala and Spring
 
C
CC
C
 

More from LovelitJose

Professional ethics-Unit5
Professional ethics-Unit5Professional ethics-Unit5
Professional ethics-Unit5
LovelitJose
 
Professional ethics-Unit4
Professional ethics-Unit4Professional ethics-Unit4
Professional ethics-Unit4
LovelitJose
 
Professional ethics-Unit3
Professional ethics-Unit3Professional ethics-Unit3
Professional ethics-Unit3
LovelitJose
 
Professional Ethics Unit2
Professional Ethics Unit2Professional Ethics Unit2
Professional Ethics Unit2
LovelitJose
 
Professional ethics PPT unit 1
Professional ethics PPT unit 1Professional ethics PPT unit 1
Professional ethics PPT unit 1
LovelitJose
 
Programming in java - Concepts- Operators- Control statements-Expressions
Programming in java - Concepts- Operators- Control statements-ExpressionsProgramming in java - Concepts- Operators- Control statements-Expressions
Programming in java - Concepts- Operators- Control statements-Expressions
LovelitJose
 

More from LovelitJose (6)

Professional ethics-Unit5
Professional ethics-Unit5Professional ethics-Unit5
Professional ethics-Unit5
 
Professional ethics-Unit4
Professional ethics-Unit4Professional ethics-Unit4
Professional ethics-Unit4
 
Professional ethics-Unit3
Professional ethics-Unit3Professional ethics-Unit3
Professional ethics-Unit3
 
Professional Ethics Unit2
Professional Ethics Unit2Professional Ethics Unit2
Professional Ethics Unit2
 
Professional ethics PPT unit 1
Professional ethics PPT unit 1Professional ethics PPT unit 1
Professional ethics PPT unit 1
 
Programming in java - Concepts- Operators- Control statements-Expressions
Programming in java - Concepts- Operators- Control statements-ExpressionsProgramming in java - Concepts- Operators- Control statements-Expressions
Programming in java - Concepts- Operators- Control statements-Expressions
 

Recently uploaded

ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 

Recently uploaded (20)

ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 

Programming in java basics

  • 1. UNIT I OBJECT ORIENTED PROGRAMMING FUNDAMENTALS Object Oriented Programming Paradigm - Basic Concepts of Object Oriented Programming – Benefits and Applications of OOP – Java Features – Java Program Structure – Command Line Arguments – Variables and Data Types – Operators – Expressions – Arrays - Control Statements – Selection – Iteration - Jump Statements
  • 3. Features of OBJECT ORIENTED PARADIGMS 1. Data 2. Objects 3. Data structures 4. Methods 5. Hidden data 6. Communication 7. Addition of new data 8. Bottom up approach
  • 4. Basic concepts of OBJECT ORIENTED PROGRAMMING I. OBJECTS & CLASSES II. DATA ABSTRACTION & ENCAPSULATION III. INHERITANCE IV. POLYMORPHISM V. DYNAMIC BINDING VI. MESSAGE COMMUNICATION
  • 5. I.OBJECTS & CLASSES • Object-Basic runtime entity • Class- Collection of objects of similar type
  • 6. II.DATA ABSTRACTION & ENCAPSULATION • Encapsulation–Wrapping up of data and methods into single unit(called class). • Data hiding –Insulation of data from direct access by program. • Data abstraction Representing essential features only.
  • 7. III.INHERITANCE • Objects of 1 class acquire the properties of objects of another class.
  • 8. IV.POLYMORPHISM • Ability to take more than one form
  • 9. V.DYNAMIC BINDING • Linking of procedure call to code. • Linking of method call to its corresponding method definition takes place only during runtime.
  • 10. VI.MESSAGE COMMUNICATION There are 3 steps. • Class creation • Object creation • Establish communication
  • 11. BENEFITS OF OOP • Inheritance • Time saving and high productivity. • Data hiding • Multiple objects • Mapping of objects • Easy to upgrade • Communication through messages • Can manage software complexity easily
  • 12. APPLICATIONS OF OOP • Real time systems. • Simulation & Modelling. • Object oriented DB • AI • Neural networks
  • 13. JAVA FEATURES Introduction:- • Java is an object oriented language developed by Sun Microsystems. • Original name was OAK . Later renamed to JAVA. • Platform neutral language(platform independent.)(Java Virtual Machine). • Java is both compiled and interpreted language.
  • 15.
  • 16. JAVA FEATURES 1. Java is both a compiled and an interpreted language. 2. Platform independent and portable-Write Once Run Anywhere. 3. Object Oriented. 4. Robust and Secure. 5. Distributed. 6. Automatic Memory Management. 7. Dynamic binding 8. High performance. 9. Multithreading.
  • 17. Some features in C/C++ are eliminated in java. They are listed below. • No Pointers • No Preprocessor Directives • No Multiple Inheritance in Classes • No operator overloading. • No global variables.
  • 18. Simple Java Program class Welcome { public static void main(String args[]) { System.out.println(“Welcome to Java world “); } }
  • 20. Simple Java Program /* * To change this template, choose Tools | Templates and open the template in the editor. */ package college; import java.io.IOException; import java.io.PrintWriter; import java.sql; class sum { public static void main(String args[]) { int i=10,j=25; k=i+j; System.out.println(“THE SUM IS “+k); } }
  • 21. Download JDK and install in Windows10- Use the following YouTube link. https://video.search.yahoo.com/search/video?fr =mcafee&ei=UTF- 8&p=download+jdk&type=E211US1045G0#id=4 &vid=3aa873b105c9f56e6a73b619da6222ba&a ction=click Compilation code- javac filename.java Execution code- java filename
  • 22. JAVA TOKENS • In Java every statement is made up of smallest individual elements called tokens. Tokens in java include the following:- 1. Keywords 2. Identifiers 3. Literals 4. Operators 5. Separators
  • 23. 1. Keywords • Keywords cannot be redefined by a programmer • Keywords cannot be used as identifier name. Eg: Abstract, Assert, Boolean, Break, Byte, Case. • Java language has reserved 50 words as keywords.
  • 24. 2. Identifiers • Programmer designed tokens. Used for naming variables, methods, classes etc. • An identifier can contain alphanumeric characters, but it should begin with an alphabet. • Identifiers are case sensitive. • Underscore and dollar sign are two special character allowed. • Eg:A23C • Bob@gmail - Wrong
  • 25. 3. Literals • LITERAL is a program element that represents an exact (fixed) value of a certain type. Java language supports the following type of literals. 1. Integer Literals. (Ex. 123) 2. Floating point Literals. (Ex. 88.223) 3. Character Literals. (Ex. ‘.’ , ‘a’ , ‘n’) 4. String Literals. (Ex. “Hello World”) 5. Boolean Literals. (Ex. True,false)
  • 26. 4. Separators • Symbols used to indicate where group of code are divided and arranged. • () • {} • [] • ; • , • .
  • 27. 5. Operators • Tells the computer to perform certain mathematical or logical manipulations on data and variables. Different types are:- 1. Arithmetic Operators. 2. Unary Operators. 3. Assignment Operators. 4. Equality and Relational Operators. 5. Logical and Conditional Operators. 6. Bitwise and Bit Shift Operators. 7. Special operators
  • 28. 1. Arithmetic Operators Eg: a+b a-b a*b a/b a%b 2. Unary Operators Eg: +b -b ++b --b
  • 29. 3. Assignment Operators Eg:a=b+c; a=a+1; and a+=1; same meaning. a+=1 is shorthand assignment operator. 4. Equality and Relational Operators Eg: a==b; a!=b; • Value of relational expression is either true or false. • It is used in decision statements. Eg: a<b; a>b; a<=b; a>=b;
  • 30. 5. Logical and Conditional Operators. • Used to form compound conditions by combining 2 or more relations. && -logical AND || -logical OR. ! – logical compliment. Eg: a>b && x==10; ?: - Conditional ternary opeartor(shorthand for if-then-else statement). Eg: x=(a>b)?a:b;
  • 31. 6. Bitwise and Bit Shift Operators ~ Unary bitwise complement << Signed left shift >> Signed right sift >>> Unsigned right shift & Bitwise AND ^ Bitwise exclusive OR | Bitwise inclusive OR
  • 32. 7. Special Operators 1. Instanceof operator Eg: person instanceof student. • Checks whether object person belongs to class student or not. • Returns either true or false 2. Dot operator /member selection operator • Used to access variables and methods of a class object. Eg: Person1.age; Person1.salary(); Where person1 is an object . Age is a variable Salary() is a method.
  • 33. Example:Operators • public class StringLowerUpperExample{ • public static void main(String args[]){ • String s1="JAVATPOINT HELLO stRIng"; • String s1lower=s1.toLowerCase(); • System.out.println(s1lower); • String s2="hello string"; • String s1upper=s2.toUpperCase(); • System.out.println(s1upper); • }}
  • 34. Operator Precedence Table Operator Precedence Operators Precedence postfix expr++ expr-- unary ++expr --expr +expr -expr ~ ! multiplicative * / % additive + - shift << >> >>> relational < > <= >= instanceof equality == != bitwise AND & bitwise exclusive OR ^ bitwise inclusive OR | logical AND && logical OR || ternary ? : assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=
  • 35. EXPRESSIONS • Java expressions are used to implement some computation. • Syntax: Variable=Exprerssion; • Simple Expression : x=a+b; • Complicated expression : a*(b+c)/(m+n)*f; In this example, 1. (b+c) or (m+n) executed first since it is written inside brackets.(From left to right or right to left. Refer operator precedence table in Unit1Part1.pdf). 2. a*(b+c), or (m+n)*f executes multiplication operation secondly. 3. Finally division operation takes place.
  • 36. COMMAND LINE ARGUMENTS • Command line arguments are parameters that are supplied to the application program at the time of invoking it for execution. • Eg:- public static void main(String args[]). • Eg: javac hello.java java hello 123 abc 12.88 Then, • args[0] contains 123 • args[1] contains abc • args[2] contains 12.88 • Wrapper classes are used to convert the string to corresponding simpler data type. • ie, static int parseInt(String s) • For example: int value= Integer.parseInt(“123”) • Int total=args.length; • Converts stirng 10 to integer data type.
  • 37. Fibonacci series class fib{ public static void main(String args[]) { int n; int a=0,b=1,c; n=Integer.parseInt(args[0]); for(int i=0;i<n;i++) { c=a+b; System.out.println("The next number is "+c); a=b; b=c; } } }
  • 38. VARIABLES • Variables refers to names of storage location which is used to store data vales. Eg: int i; int i=3,j=5; • Can take different values at different times during execution of the program. • Similar as identifiers. • Assignment method • readline() method.(Type casting)
  • 39. Variables example- readLine() import java.io.Console; class exampleread { public static void main(String args[]) { String str; Console con = System.console(); if(con == null) { System.out.print("No console available"); return; } str = con.readLine("Enter your name: "); con.printf("Here is your name: %sn", str); } }
  • 40. VARIABLES(readLine() & Type casting using wrapper classes) import java.io.Console; class examplereadline { try{ public static void main(String args[]) { int age=0; Console con = System.console(); age= Integer.parseInt(con.readLine("Enter your age") ); con.printf("Here is your age:%dn", age); } } Catch{ } }
  • 41. Scope of variables • Instance variables - Created when objects are instantiated and takes different values for each object. Eg: student s1=new student(); • Each object has its own copy of instance variables. • Class variables - Available to all methods in a class. • Local variables – Local to the method inside it is declared.
  • 42. Scope of variables-Example // Demonstrate block scope. class Scope { public static void main(String args[]) { int x; // known to all code within main x = 10; if(x == 10) { // start new scope int y = 20; // known only to this block // x and y both known here. System.out.println("x and y: " + x + " " + y); x = y * 2; } // y = 100; // Error! y not known here // x is still known here. System.out.println("x is " + x); } }
  • 43. CONSTANTS • Constants refer to values that do not change during the execution of the program. • Java supports following types of constants.
  • 44. • Integer constant. Eg:2021. • Real/Floating point constant. Eg: 32.567. • String constant. Eg: “Hello World”. • Character constant. Eg: ‘a’. • Final float pi=3.142; • Apart from these types of constants java also supports backslash character constants. BACKSLASH CONSTANT PURPOSE b Backspace f Form feed n New Line r Carriage return t Horizontal tab Backslash
  • 46. Data types Integer char a = 'G'; int i=89; byte b = 4; short s = 56; float f = 4.7333434f; double d = 4.355453532d;
  • 47. Data types- Example class datatypes{ public static void main(String args[]){ char a = 'G'; int i=89; byte b = 4; short s = 3; double d = 4.355453532d; float f = 4.7333434f; System.out.println("char: " + a); System.out.println("integer: " + i); System.out.println("byte: " + b); System.out.println("short: " + s); System.out.println("float: " + f); System.out.println("double: " + d); } }
  • 48. ARRAYS • An array is a group of contiguous/related data items that share a common name. • Syntax: Data type Arrayname[]; • Eg: int salary[9] or int[] salary; • 3 steps to create the array. • 1) Declare the array->Only a reference of array created. • 2) Create the memory allocation-> salary=new int[9]; • 3)Putting values to memory location.
  • 49. Array representation:- Int a=Arrayname.length; // To find length of the array. One dimensional Arrays. Array Literal In a situation, where the size of the array and variables of array are already known, array literals can be used. int[] intArray = new int[]{ 1,2,3,4,5,6,7,8,9,10 };
  • 50. class Testarray{ public static void main(String args[]){ int a[]=new int[5];//declaration and instantiation a[0]=10;//initialization a[1]=20; a[2]=70; a[3]=40; a[4]=50; //traversing array for(int i=0;i<a.length;i++)//length is the property of array System.out.println(a[i]); }}
  • 51. Arrays as Parameters  An entire array can be passed as a parameter to a method  Like any other object, the reference to the array is passed, making the formal and actual parameters aliases of each other  Changing an array element within the method changes the original  An array element can be passed to a method as well, and follows the parameter passing rules of that element's type
  • 52. class Testarray3{ //creating a method which receives an array as a parameter static void min(int arr[]){ int min=arr[0]; for(int i=1;i<arr.length;i++) if(min>arr[i]) min=arr[i]; System.out.println(min); } public static void main(String args[]){ int a[]={33,3,4,5};//declaring and initializing an array min(a);//passing array to method }}
  • 53. Two Dimensional Arrays int[][] intArray = new int[10][20]; //a 2D array or matrix
  • 54. Array-Assigning values can be done directly or using loops. public static void main(String args[]) { // declaring and initializing 2D array int arr[][] = { {2,7,9},{3,6,1},{7,4,2} }; // printing 2D array for (int i=0; i< 3 ; i++) { for (int j=0; j < 3 ; j++) System.out.print(arr[i][j] + " "); System.out.println(); } }
  • 55. Multi Dimensional Arrays • int[][][] intArray = new int[10][20][10]; //a 3D array . • Known as Jagged Arrays. • Strings- Character Array or String Objects.
  • 56. STRINGS • It is the most common part of many java programs. • String represent a sequence of characters. • The simplest way to represent a sequence of characters in java is by using a character array. • Example: char charArray[ ] = new char[4]; charArray[0] = ‘J’; charArray[1] = ‘a’;
  • 58. STRING ARRAYS • Array can be created and used that contain strings. • Above statement create following effects:
  • 59.  In Java, strings are class objects and implemented using two classes,namely, String and StringBuffer.  A java string is an instantiated object of the String class.  Java string as compared to C strings, are more reliable and predicable.  A java string is not a character array and is not NULL terminated.
  • 60. STRING METHODS  String class defines a number of methods that allow us to accomplish a variety of string manipulation tasks.  Eg: 1) s2=s1.toLowercase; 2) s2=s1.toUppercase; 3) s1.compareTo(s2) //To sort array of strings.
  • 61. STRING BUFFER CLASS  StringBuffer is a peer class of String.  While String creates strings of fixed_length, StringBuffer creates strings of flexible length that can be modified in term of both length and content.  We can insert characters and substrings in the middle of a string to the end.