SlideShare a Scribd company logo
1 of 95
Download to read offline
JAVA
F O R
ANDROID
DEVELOPERS
A LY O S A M A
Instructor
Aly Osama
Software Engineer-
Ain Shams University
CONTENTS
• Introduction
• Code structure in Java
• Classes and Objects
• StaticVariables
• Components of the Java Programming Language
– Inheritance
– Polymorphism
– Interfaces
• JAVA GUI
• Java AWT Event Handling
• Multithreading in Java
• Network Programming
INTRODUCTION
THE WAY JAVA WORKS
• The goal is to write one application (in this example an interactive party invitation) and
have it work on whatever device your friends have.
INSTALLATION JAVA PLATFORM (JDK)
• http://www.oracle.com/technetwork/java/javase/downloads/index.html
LOOK HOW EASY IT IS TO WRITE JAVA
LOOK HOW EASY IT IS TO WRITE JAVA
CODE
STRUCTURE IN
JAVA
CODE
STRUCTURE
IN JAVA
Source file
Class file
Method 1 Method 2
CODE
STRUCTURE
IN JAVA
public class Dog {
}
Class
public class Dog {
void bark(){
}
}
Method
public class Dog {
void bark () {
statement1;
statement2;
}
}
statements
ANATOMY OF A CLASS
WRITING A CLASS WITH A MAIN
public class MyFirstApp {
public static void main (String[] args) {
System.out.println("I Rule!");
System.out.println("TheWorld!");
}
}
PRIMITIVE DATA TYPES
Category Types Size (bits) Minimum Value Maximum Value Precision Example
Integer
byte 8 -128 127 From +127 to -128 byte b = 65;
char 16 0 216-1 All Unicode characters
char c = 'A';
char c = 65;
short 16 -215 215-1 From +32,767 to -32,768 short s = 65;
int 32 -231 231-1 From +2,147,483,647 to -2,147,483,648 int i = 65;
long 64 -263 263-1
From +9,223,372,036,854,775,807 to -
9,223,372,036,854,775,808 long l = 65L;
Floating-point
float 32 2-149 (2-2-23)·2127 From 3.402,823,5 E+38 to 1.4 E-45 float f = 65f;
double 64 2-1074 (2-2-52)·21023 From 1.797,693,134,862,315,7 E+308 to
4.9 E-324 double d = 65.55;
Other
boolean 1 -- -- false, true boolean b = true;
void -- -- -- -- --
STATEMENTS
int x = 3;
String name = "Dirk";
x = x * 17;
System.out.print("x is " + x);
double d = Math.random();
// this is a comment
CONDITION
if (x == 10) {
System.out.println("x must be 10");
} else {
System.out.println("x isn't 10");
}
if ((x < 3) && (name.equals("Dirk"))) {
System.out.println("Gently");
}
if ((x < 3) || (name.equals("Dirk"))) {
System.out.println("Gently");
}
LOOPING
while (x > 12) {
x = x - 1;
System.out.println("x is " + x);
}
for (x = 0; x < 10; x = x + 1) {
System.out.println("x is " + x);
}
METHODS
public class ExampleMinNumber{
public static void main(String[] args) {
int a = 11;
int b = 6;
int c = minFunction(a, b);
System.out.println("MinimumValue=" + c);
}
/** returns the minimum of two numbers */
public static int minFunction(int n1, int n2) {
int min;
if (n1 > n2)
min = n2;
else min = n1;
return min;
}
}
ARRAYS
double[] myList;
myList=new double[10];
double[] myList=new double[10];
myList[5]=34.33;
ARRAYS
//Arrays to Methods
public static void printArray(int[] array) {
for (int i = 0; i < array.length; i++) {
System.out.print(array[i] + " ");
}
}
//For each
for (double element: myList) {
System.out.println(element);
}
Time to
CODE !
EXERCISE 1
Write two methods:
a) First computes area of circle ( take
radius as parameter )
b) Second computes sum of area of circles
( array of double of radius )
CLASSES AND
OBJECTS
CLASSES AND OBJECTS
CLASSES AND OBJECTS
CLASSES AND OBJECTS
THINKING
ABOUT
OBJECTS
When you design a class, think about the
objects that will be created from that
class type.Think about
• things the object knows
• things the object does
THINKING ABOUT OBJECTS
WHAT’S THE DIFFERENCE BETWEEN A
CLASS AND AN OBJECT?
• A class is not an object (but it’s used to construct them)
• A class is a blueprint for an object.
ENCAPSULATION
Public
Private - self class
Protected - self package
CLASS
GOODDOG
GOODDOG
TEST DRIVE
CONSTRUCTORS
Each time a new object is created, at least one
constructor will be invoked.
The main rule of constructors is that they should have
the same name as the class.A class can have more
than one constructor.
Time to
CODE !
EXERCISE 2
STATIC
VARIABLES
STATIC VARIABLES
• Static variables are shared.
• All instances of the same class share a
single copy of the static variables.
• Instance variables : 1 per instance
• Static variables : 1 per class
STATIC VARIABLES
COMPONENTS OF
THE JAVA
PROGRAMMING
LANGUAGE
COMPONENTS OF THE JAVA
PROGRAMMING LANGUAGE
• The language itself is a collection of keywords and symbols that we put
together to express how we want our code to run.
Data types
 Int, float, Boolean, char, String.
Variables
 Container used to hold data.
Methods
 section of code that we can call from elsewhere in our code, will perform some action or return some
kind of result that we can use.
COMPONENTS OF THE JAVA
PROGRAMMING LANGUAGE
Comments
 lines of code that don’t have any effect on how the program runs.They are purely informational, meant to
help us understand how the code works or is organized.
Classes and Objects
A class is meant to define an object and how it works. Classes define things about objects as
properties, or member variables of the class.And abilities of the object are defined as methods.
Access Modifiers
For classes, member variables, and methods, we usually want to specify who can access them.
Keywords public, private, and protected are access modifiers that control who can access the
class, variable, or method.
INHERITANCE
A N OT H E R I M P O RTA N T
J AVA C O N C E P T S
YO U ’ L L RU N I N TO A
L OT:
INHERITANCE
inheritance means that Java classes or objects can be
organized into hierarchies with lower, more specific,
classes in the hierarchy inheriting behavior and traits from
higher, more generic, classes.
Super Class
Sub Class
EXTENDS KEYWORD
• Extends is the keyword used to inherit the properties of a class. Below given is the syntax of
extends keyword.
class Super {
.....
}
class Sub extends Super{
....
}
Calculation
My_Calculation
Time to
CODE !
EXERCISE 3
Example using Inheritance
INTERFACES
A N OT H E R I M P O RTA N T
J AVA C O N C E P T S YO U ’ L L
RU N I N TO A L OT:
INTERFACES
An interface is a reference type in Java, it is
similar to class, it is a collection of abstract
methods.
A class implements an interface, thereby
inheriting the abstract methods of the
interface.
DECLARING INTERFACE
/* File name : NameOfInterface.java */
import java.lang.*;
//Any number of import statements
public interface NameOfInterface
{
//Any number of final, static fields
//Any number of abstract method declarations
}
EXERCISE 4
Example using Interfaces
POLYMORPHISM
A N OT H E R I M P O RTA N T
J AVA C O N C E P T S YO U ’ L L
RU N I N TO A L OT:
POLYMORPHISM
Polymorphism is the ability of an object to take on many
forms.The most common use of polymorphism in OOP
occurs when a parent class reference is used to refer to a
child class object.
Quack!
Animal Animal
Woof!
Animal
Meow!
Speak()
POLYMORPHISM EXAMPLE
public interfaceVegetarian{}
public class Animal{}
public class Deer extends Animal implementsVegetarian{}
• Following are true for the above example:
– A Deer IS-A Animal
– A Deer IS-AVegetarian
– A Deer IS-A Deer
– A Deer IS-A Object
Deer d = new Deer();
Animal a = d;
Vegetarian v = d;
Object o = d;
A N OT H E R I M P O RTA N T
J AVA C O N C E P T S YO U ’ L L
RU N I N TO A L OT:
OVERRIDING
The benefit of overriding is: ability to define a behavior
that's specific to the subclass type which means a subclass
can implement a parent class method based on its
requirement.
Quack!
Animal Animal
Woof!
Animal
Meow!
Speak()
Time to
CODE !
EXERCISE 5
Example using Polymorphism
Animal
A( )
Duck Dog Cat
C( ),A( )D( ),A( )K( ),A( )
Time to
CODE !
JAVA GUI
JAVA GRAPHICS APIS
• Java Graphics APIs - AWT and Swing - provide a huge set of reusable GUI components, such as
button, text field, label, choice, panel and frame for building GUI applications.You can simply
reuse these classes rather than re-invent the wheels. I shall start with the AWT classes before
moving into Swing to give you a complete picture. I have to stress that AWT component
classes are now obsoleted by Swing's counterparts.
AWT COMPONENT CLASSES
MORE ABOUT GUI
• GUI Programming
https://www.ntu.edu.sg/home/ehchua/programming/java/J4a_GUI.html
• NetbeansTutorial
https://netbeans.org/kb/docs/java/gui-functionality.html
• Main documentation:
https://docs.oracle.com/javase/tutorial/uiswing/
Time to
CODE !
EXERCISE 6
Example using GUI
JAVA AWT EVENT
HANDLING
JAVA AWT EVENT HANDLING
• Java provides a rich set of libraries to create Graphical User Interface in platform independent
way. In this session we'll look in AWT (AbstractWindowToolkit), especially Event Handling.
• Event is a change in the state of an object. Events are generated as result of user interaction
with the graphical user interface components. For example, clicking on a button, moving the
mouse, entering a character through keyboard, selecting an item from list, scrolling the page are
the activities that causes an event to happen.
• Event Handling is the mechanism that controls the event and decides what should happen if an
event occurs.This mechanism have the code which is known as event handler that is
executed when an event occurs. Java Uses the Delegation Event Model to handle the
events.This model defines the standard mechanism to generate and handle the events.
T H E
DELEGATION
EVENT
MODEL
H A S T H E F O L L OW I N G
K E Y PA RT I C I PA N T S
N A M E LY
• Source - The source is an object on which event occurs.
Source is responsible for providing information of the
occurred event to it's handler.
• Listener - It is also known as event handler. Listener is
responsible for generating response to an event. Listener
waits until it receives an event. Once the event is received ,
the listener process the event an then returns.
T H E
EVENTS
C A N B E B ROA D LY
C L A S S I F I E D I N TO T W O
C AT E G O R I E S :
• Foreground Events -Those events which require the
direct interaction of user.They are generated as
consequences of a person interacting with the graphical
components in Graphical User Interface. For example, clicking
on a button, moving the mouse, entering a character through
keyboard, selecting an item from list, scrolling the page etc.
• Background Events - Those events that require the
interaction of end user are known as background events.
Operating system interrupts, hardware or software failure,
timer expires, an operation completion are the example of
background events.
Time to
CODE !
EXERCISE 7
MULTITHREADING
IN JAVA
MULTITHREADING
• A multi-threaded program contains
two or more parts that can run
concurrently and each part can handle
different task at the same time making
optimal use of the available resources
specially when your computer has
multiple CPUs.
LIFE CYCLE
OF A
THREAD
CREATE THREAD BY IMPLEMENTING
RUNNABLE INTERFACE
• Step 1 you need to implement a run() method provided by Runnable interface.
• Step 2 you will instantiate a Thread object using the following constructor:
• Step 3 OnceThread object is created, you can start it by calling start( ) method, which
executes a call to run( ) method.
public void run( )
Thread(Runnable threadObj, String threadName);
void start( );
Time to
CODE !
EXERCISE 9
NETWORK
PROGRAMMING
JAVA NETWORKING
• The term network programming refers
to writing programs that execute across
multiple devices (computers), in which the
devices are all connected to each other
using a network.
T H E J AVA . N E T
PA C K A G E P ROV I D E S
S U P P O RT F O R T H E
T W O C O M M O N
NETWORK
PROTOCOLS
• TCP:Transmission Control Protocol, which allows for
reliable communication between two applications.TCP is
typically used over the Internet Protocol, which is referred to
asTCP/IP.
• UDP: User Datagram Protocol, a connection-less protocol
that allows for packets of data to be transmitted between
applications.
SOCKET PROGRAMMING
• Sockets provide the communication mechanism between two computers usingTCP.A client program
creates a socket on its end of the communication and attempts to connect that socket to a server.
Time to
CODE !
EXERCISE 10
Tasks
SIMPLE TASK
• Design a class named Person and its two subclasses named Student and Employee.
• Make Faculty member and Staff subclasses of Employee.
• A person has a name, address, phone number, and email address.
• A student has a class status (freshman, sophomore, junior, or senior).
• Define the status as a constant.
• An employee has an office, salary, and date hired.
• Define a class named MyDate that contains the fields year, month, and day.
• A faculty member has office hours and a rank.
• A staff member has a title.
• Override the toString method in each class to display the class name and the person’s name.
SIMPLE TASK
• Deliverables:
– Optional: Draw the UML diagram for the classes.
– Implement the classes.
– Write a test program that creates a Person, Student, Employee, Faculty, and Staff, and
invokes their toString() methods.
– Build GUI to Add Employee andView all Employees
– Bonus: Save and load employees data to/from File
TUTORIALS
TUTORIALS
• Text :
http://www.tutorialspoint.com/java
• Courses
https://www.udacity.com/course/intro-to-java-programming--cs046
https://www.udemy.com/java-programming-basics/
• YouTube Videos – Recommended -
https://www.youtube.com/playlist?list=PLFE2CE09D83EE3E28
https://www.youtube.com/playlist?list=PL27BCE863B6A864E3
For any help feel free to contact me!
Aly Osama
alyosama@gmail.com
https://eg.linkedin.com/in/alyosama
THANK YOU!

More Related Content

What's hot

Week10 packages using objects in objects
Week10 packages using objects in objectsWeek10 packages using objects in objects
Week10 packages using objects in objectskjkleindorfer
 
java drag and drop and data transfer
java drag and drop and data transferjava drag and drop and data transfer
java drag and drop and data transferAnkit Desai
 
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...Jorge Hidalgo
 
Lecture - 1 introduction to java
Lecture - 1 introduction to javaLecture - 1 introduction to java
Lecture - 1 introduction to javamanish kumar
 
Let's start with Java- Basic Concepts
Let's start with Java- Basic ConceptsLet's start with Java- Basic Concepts
Let's start with Java- Basic ConceptsAashish Jain
 
Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Kernel Training
 
Logic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing ApplicationsLogic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing Applicationskjkleindorfer
 
Java interview questions and answers for cognizant By Data Council Pune
Java interview questions and answers for cognizant By Data Council PuneJava interview questions and answers for cognizant By Data Council Pune
Java interview questions and answers for cognizant By Data Council PunePankaj kshirsagar
 
Hibernate introduction
Hibernate introductionHibernate introduction
Hibernate introductionSagar Verma
 
The Art of Metaprogramming in Java
The Art of Metaprogramming in Java  The Art of Metaprogramming in Java
The Art of Metaprogramming in Java Abdelmonaim Remani
 
Packages and Interfaces
Packages and InterfacesPackages and Interfaces
Packages and InterfacesAkashDas112
 
Selenium web driver | java
Selenium web driver | javaSelenium web driver | java
Selenium web driver | javaRajesh Kumar
 
Packages and inbuilt classes of java
Packages and inbuilt classes of javaPackages and inbuilt classes of java
Packages and inbuilt classes of javakamal kotecha
 

What's hot (19)

Week10 packages using objects in objects
Week10 packages using objects in objectsWeek10 packages using objects in objects
Week10 packages using objects in objects
 
java drag and drop and data transfer
java drag and drop and data transferjava drag and drop and data transfer
java drag and drop and data transfer
 
Class 1
Class 1Class 1
Class 1
 
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
 
Lecture - 1 introduction to java
Lecture - 1 introduction to javaLecture - 1 introduction to java
Lecture - 1 introduction to java
 
Let's start with Java- Basic Concepts
Let's start with Java- Basic ConceptsLet's start with Java- Basic Concepts
Let's start with Java- Basic Concepts
 
1 .java basic
1 .java basic1 .java basic
1 .java basic
 
Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Core Java introduction | Basics | free course
Core Java introduction | Basics | free course
 
Class 1 blog
Class 1 blogClass 1 blog
Class 1 blog
 
Hello java
Hello java  Hello java
Hello java
 
Hello Java-First Level
Hello Java-First LevelHello Java-First Level
Hello Java-First Level
 
Logic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing ApplicationsLogic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing Applications
 
Java interview questions and answers for cognizant By Data Council Pune
Java interview questions and answers for cognizant By Data Council PuneJava interview questions and answers for cognizant By Data Council Pune
Java interview questions and answers for cognizant By Data Council Pune
 
Hibernate introduction
Hibernate introductionHibernate introduction
Hibernate introduction
 
Java API, Exceptions and IO
Java API, Exceptions and IOJava API, Exceptions and IO
Java API, Exceptions and IO
 
The Art of Metaprogramming in Java
The Art of Metaprogramming in Java  The Art of Metaprogramming in Java
The Art of Metaprogramming in Java
 
Packages and Interfaces
Packages and InterfacesPackages and Interfaces
Packages and Interfaces
 
Selenium web driver | java
Selenium web driver | javaSelenium web driver | java
Selenium web driver | java
 
Packages and inbuilt classes of java
Packages and inbuilt classes of javaPackages and inbuilt classes of java
Packages and inbuilt classes of java
 

Viewers also liked

Pattern recognition Tutorial 2
Pattern recognition Tutorial 2Pattern recognition Tutorial 2
Pattern recognition Tutorial 2Aly Abdelkareem
 
Android Development Workshop
Android Development WorkshopAndroid Development Workshop
Android Development WorkshopPeter Robinett
 
Fundamental of android
Fundamental of androidFundamental of android
Fundamental of androidAdarsh Patel
 
Android Udacity Study group 1
Android Udacity Study group 1Android Udacity Study group 1
Android Udacity Study group 1Aly Abdelkareem
 
Workshop on android ui
Workshop on android uiWorkshop on android ui
Workshop on android uiAdarsh Patel
 
Android Development
Android DevelopmentAndroid Development
Android DevelopmentDaksh Semwal
 
Optimizing apps for better performance extended
Optimizing apps for better performance extended Optimizing apps for better performance extended
Optimizing apps for better performance extended Elif Boncuk
 
Workhsop on Logic Building for Programming
Workhsop on Logic Building for ProgrammingWorkhsop on Logic Building for Programming
Workhsop on Logic Building for ProgrammingAdarsh Patel
 
Optimizing Apps for Better Performance
Optimizing Apps for Better PerformanceOptimizing Apps for Better Performance
Optimizing Apps for Better PerformanceElif Boncuk
 
Project Analysis - How to Start Project Develoment
Project Analysis - How to Start Project DevelomentProject Analysis - How to Start Project Develoment
Project Analysis - How to Start Project DevelomentAdarsh Patel
 
Workshop on Search Engine Optimization
Workshop on Search Engine OptimizationWorkshop on Search Engine Optimization
Workshop on Search Engine OptimizationAdarsh Patel
 
Hack'n Break Android Workshop
Hack'n Break Android WorkshopHack'n Break Android Workshop
Hack'n Break Android WorkshopElif Boncuk
 
Lecture 04. Mobile App Design
Lecture 04. Mobile App DesignLecture 04. Mobile App Design
Lecture 04. Mobile App DesignMaksym Davydov
 
Overview of DroidCon UK 2015
Overview of DroidCon UK 2015 Overview of DroidCon UK 2015
Overview of DroidCon UK 2015 Elif Boncuk
 

Viewers also liked (20)

Pattern recognition Tutorial 2
Pattern recognition Tutorial 2Pattern recognition Tutorial 2
Pattern recognition Tutorial 2
 
Android Development Workshop
Android Development WorkshopAndroid Development Workshop
Android Development Workshop
 
Fundamental of android
Fundamental of androidFundamental of android
Fundamental of android
 
Android Udacity Study group 1
Android Udacity Study group 1Android Udacity Study group 1
Android Udacity Study group 1
 
Workshop on android ui
Workshop on android uiWorkshop on android ui
Workshop on android ui
 
L02 Software Design
L02 Software DesignL02 Software Design
L02 Software Design
 
A2
A2A2
A2
 
Android Development
Android DevelopmentAndroid Development
Android Development
 
project center in coimbatore
project center in coimbatoreproject center in coimbatore
project center in coimbatore
 
Java cheat sheet
Java cheat sheet Java cheat sheet
Java cheat sheet
 
Optimizing apps for better performance extended
Optimizing apps for better performance extended Optimizing apps for better performance extended
Optimizing apps for better performance extended
 
Workhsop on Logic Building for Programming
Workhsop on Logic Building for ProgrammingWorkhsop on Logic Building for Programming
Workhsop on Logic Building for Programming
 
App indexing api
App indexing apiApp indexing api
App indexing api
 
Optimizing Apps for Better Performance
Optimizing Apps for Better PerformanceOptimizing Apps for Better Performance
Optimizing Apps for Better Performance
 
Project Analysis - How to Start Project Develoment
Project Analysis - How to Start Project DevelomentProject Analysis - How to Start Project Develoment
Project Analysis - How to Start Project Develoment
 
Workshop on Search Engine Optimization
Workshop on Search Engine OptimizationWorkshop on Search Engine Optimization
Workshop on Search Engine Optimization
 
Hack'n Break Android Workshop
Hack'n Break Android WorkshopHack'n Break Android Workshop
Hack'n Break Android Workshop
 
Lecture 04. Mobile App Design
Lecture 04. Mobile App DesignLecture 04. Mobile App Design
Lecture 04. Mobile App Design
 
Android development session 3 - layout
Android development   session 3 - layoutAndroid development   session 3 - layout
Android development session 3 - layout
 
Overview of DroidCon UK 2015
Overview of DroidCon UK 2015 Overview of DroidCon UK 2015
Overview of DroidCon UK 2015
 

Similar to Java for android developers

Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptxVijalJain3
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javaSujit Majety
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2Rakesh Madugula
 
Modern_2.pptx for java
Modern_2.pptx for java Modern_2.pptx for java
Modern_2.pptx for java MayaTofik
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for seleniumapoorvams
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)Khaled Anaqwa
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to JavaSMIJava
 
Knowledge of Javascript
Knowledge of JavascriptKnowledge of Javascript
Knowledge of JavascriptSamuel Abraham
 
Introduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologiesIntroduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologiesTabassumMaktum
 
java traning report_Summer.docx
java traning report_Summer.docxjava traning report_Summer.docx
java traning report_Summer.docxGauravSharma164138
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptxRaazIndia
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxKunalYadav65140
 

Similar to Java for android developers (20)

Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
Java
JavaJava
Java
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
ANDROID FDP PPT
ANDROID FDP PPTANDROID FDP PPT
ANDROID FDP PPT
 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
Modern_2.pptx for java
Modern_2.pptx for java Modern_2.pptx for java
Modern_2.pptx for java
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to Java
 
Core_Java_Interview.pdf
Core_Java_Interview.pdfCore_Java_Interview.pdf
Core_Java_Interview.pdf
 
Knowledge of Javascript
Knowledge of JavascriptKnowledge of Javascript
Knowledge of Javascript
 
Introduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologiesIntroduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologies
 
Java 101
Java 101Java 101
Java 101
 
Java
JavaJava
Java
 
java traning report_Summer.docx
java traning report_Summer.docxjava traning report_Summer.docx
java traning report_Summer.docx
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptx
 

More from Aly Abdelkareem

An Inductive inference Machine
An Inductive inference MachineAn Inductive inference Machine
An Inductive inference MachineAly Abdelkareem
 
Digital Image Processing - Frequency Filters
Digital Image Processing - Frequency FiltersDigital Image Processing - Frequency Filters
Digital Image Processing - Frequency FiltersAly Abdelkareem
 
Deep learning: Overfitting , underfitting, and regularization
Deep learning: Overfitting , underfitting, and regularizationDeep learning: Overfitting , underfitting, and regularization
Deep learning: Overfitting , underfitting, and regularizationAly Abdelkareem
 
Practical Digital Image Processing 5
Practical Digital Image Processing 5Practical Digital Image Processing 5
Practical Digital Image Processing 5Aly Abdelkareem
 
Practical Digital Image Processing 4
Practical Digital Image Processing 4Practical Digital Image Processing 4
Practical Digital Image Processing 4Aly Abdelkareem
 
Practical Digital Image Processing 3
 Practical Digital Image Processing 3 Practical Digital Image Processing 3
Practical Digital Image Processing 3Aly Abdelkareem
 
Pattern recognition 4 - MLE
Pattern recognition 4 - MLEPattern recognition 4 - MLE
Pattern recognition 4 - MLEAly Abdelkareem
 
Practical Digital Image Processing 2
Practical Digital Image Processing 2Practical Digital Image Processing 2
Practical Digital Image Processing 2Aly Abdelkareem
 
Practical Digital Image Processing 1
Practical Digital Image Processing 1Practical Digital Image Processing 1
Practical Digital Image Processing 1Aly Abdelkareem
 
Machine Learning for Everyone
Machine Learning for EveryoneMachine Learning for Everyone
Machine Learning for EveryoneAly Abdelkareem
 
How to use deep learning on biological data
How to use deep learning on biological dataHow to use deep learning on biological data
How to use deep learning on biological dataAly Abdelkareem
 
Deep Learning using Keras
Deep Learning using KerasDeep Learning using Keras
Deep Learning using KerasAly Abdelkareem
 
Object extraction from satellite imagery using deep learning
Object extraction from satellite imagery using deep learningObject extraction from satellite imagery using deep learning
Object extraction from satellite imagery using deep learningAly Abdelkareem
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android DevelopmentAly Abdelkareem
 

More from Aly Abdelkareem (14)

An Inductive inference Machine
An Inductive inference MachineAn Inductive inference Machine
An Inductive inference Machine
 
Digital Image Processing - Frequency Filters
Digital Image Processing - Frequency FiltersDigital Image Processing - Frequency Filters
Digital Image Processing - Frequency Filters
 
Deep learning: Overfitting , underfitting, and regularization
Deep learning: Overfitting , underfitting, and regularizationDeep learning: Overfitting , underfitting, and regularization
Deep learning: Overfitting , underfitting, and regularization
 
Practical Digital Image Processing 5
Practical Digital Image Processing 5Practical Digital Image Processing 5
Practical Digital Image Processing 5
 
Practical Digital Image Processing 4
Practical Digital Image Processing 4Practical Digital Image Processing 4
Practical Digital Image Processing 4
 
Practical Digital Image Processing 3
 Practical Digital Image Processing 3 Practical Digital Image Processing 3
Practical Digital Image Processing 3
 
Pattern recognition 4 - MLE
Pattern recognition 4 - MLEPattern recognition 4 - MLE
Pattern recognition 4 - MLE
 
Practical Digital Image Processing 2
Practical Digital Image Processing 2Practical Digital Image Processing 2
Practical Digital Image Processing 2
 
Practical Digital Image Processing 1
Practical Digital Image Processing 1Practical Digital Image Processing 1
Practical Digital Image Processing 1
 
Machine Learning for Everyone
Machine Learning for EveryoneMachine Learning for Everyone
Machine Learning for Everyone
 
How to use deep learning on biological data
How to use deep learning on biological dataHow to use deep learning on biological data
How to use deep learning on biological data
 
Deep Learning using Keras
Deep Learning using KerasDeep Learning using Keras
Deep Learning using Keras
 
Object extraction from satellite imagery using deep learning
Object extraction from satellite imagery using deep learningObject extraction from satellite imagery using deep learning
Object extraction from satellite imagery using deep learning
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 

Recently uploaded

VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profileakrivarotava
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Anthony Dahanne
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 

Recently uploaded (20)

VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profile
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 

Java for android developers

  • 2.
  • 4. CONTENTS • Introduction • Code structure in Java • Classes and Objects • StaticVariables • Components of the Java Programming Language – Inheritance – Polymorphism – Interfaces • JAVA GUI • Java AWT Event Handling • Multithreading in Java • Network Programming
  • 6. THE WAY JAVA WORKS • The goal is to write one application (in this example an interactive party invitation) and have it work on whatever device your friends have.
  • 7. INSTALLATION JAVA PLATFORM (JDK) • http://www.oracle.com/technetwork/java/javase/downloads/index.html
  • 8. LOOK HOW EASY IT IS TO WRITE JAVA
  • 9. LOOK HOW EASY IT IS TO WRITE JAVA
  • 12. CODE STRUCTURE IN JAVA public class Dog { } Class public class Dog { void bark(){ } } Method public class Dog { void bark () { statement1; statement2; } } statements
  • 13. ANATOMY OF A CLASS
  • 14. WRITING A CLASS WITH A MAIN public class MyFirstApp { public static void main (String[] args) { System.out.println("I Rule!"); System.out.println("TheWorld!"); } }
  • 15. PRIMITIVE DATA TYPES Category Types Size (bits) Minimum Value Maximum Value Precision Example Integer byte 8 -128 127 From +127 to -128 byte b = 65; char 16 0 216-1 All Unicode characters char c = 'A'; char c = 65; short 16 -215 215-1 From +32,767 to -32,768 short s = 65; int 32 -231 231-1 From +2,147,483,647 to -2,147,483,648 int i = 65; long 64 -263 263-1 From +9,223,372,036,854,775,807 to - 9,223,372,036,854,775,808 long l = 65L; Floating-point float 32 2-149 (2-2-23)·2127 From 3.402,823,5 E+38 to 1.4 E-45 float f = 65f; double 64 2-1074 (2-2-52)·21023 From 1.797,693,134,862,315,7 E+308 to 4.9 E-324 double d = 65.55; Other boolean 1 -- -- false, true boolean b = true; void -- -- -- -- --
  • 16. STATEMENTS int x = 3; String name = "Dirk"; x = x * 17; System.out.print("x is " + x); double d = Math.random(); // this is a comment
  • 17. CONDITION if (x == 10) { System.out.println("x must be 10"); } else { System.out.println("x isn't 10"); } if ((x < 3) && (name.equals("Dirk"))) { System.out.println("Gently"); } if ((x < 3) || (name.equals("Dirk"))) { System.out.println("Gently"); }
  • 18. LOOPING while (x > 12) { x = x - 1; System.out.println("x is " + x); } for (x = 0; x < 10; x = x + 1) { System.out.println("x is " + x); }
  • 19. METHODS public class ExampleMinNumber{ public static void main(String[] args) { int a = 11; int b = 6; int c = minFunction(a, b); System.out.println("MinimumValue=" + c); } /** returns the minimum of two numbers */ public static int minFunction(int n1, int n2) { int min; if (n1 > n2) min = n2; else min = n1; return min; } }
  • 20. ARRAYS double[] myList; myList=new double[10]; double[] myList=new double[10]; myList[5]=34.33;
  • 21. ARRAYS //Arrays to Methods public static void printArray(int[] array) { for (int i = 0; i < array.length; i++) { System.out.print(array[i] + " "); } } //For each for (double element: myList) { System.out.println(element); }
  • 23. EXERCISE 1 Write two methods: a) First computes area of circle ( take radius as parameter ) b) Second computes sum of area of circles ( array of double of radius )
  • 28. THINKING ABOUT OBJECTS When you design a class, think about the objects that will be created from that class type.Think about • things the object knows • things the object does
  • 30. WHAT’S THE DIFFERENCE BETWEEN A CLASS AND AN OBJECT? • A class is not an object (but it’s used to construct them) • A class is a blueprint for an object.
  • 31. ENCAPSULATION Public Private - self class Protected - self package
  • 34. CONSTRUCTORS Each time a new object is created, at least one constructor will be invoked. The main rule of constructors is that they should have the same name as the class.A class can have more than one constructor.
  • 38. STATIC VARIABLES • Static variables are shared. • All instances of the same class share a single copy of the static variables. • Instance variables : 1 per instance • Static variables : 1 per class
  • 41. COMPONENTS OF THE JAVA PROGRAMMING LANGUAGE • The language itself is a collection of keywords and symbols that we put together to express how we want our code to run. Data types  Int, float, Boolean, char, String. Variables  Container used to hold data. Methods  section of code that we can call from elsewhere in our code, will perform some action or return some kind of result that we can use.
  • 42. COMPONENTS OF THE JAVA PROGRAMMING LANGUAGE Comments  lines of code that don’t have any effect on how the program runs.They are purely informational, meant to help us understand how the code works or is organized. Classes and Objects A class is meant to define an object and how it works. Classes define things about objects as properties, or member variables of the class.And abilities of the object are defined as methods. Access Modifiers For classes, member variables, and methods, we usually want to specify who can access them. Keywords public, private, and protected are access modifiers that control who can access the class, variable, or method.
  • 44. A N OT H E R I M P O RTA N T J AVA C O N C E P T S YO U ’ L L RU N I N TO A L OT: INHERITANCE inheritance means that Java classes or objects can be organized into hierarchies with lower, more specific, classes in the hierarchy inheriting behavior and traits from higher, more generic, classes. Super Class Sub Class
  • 45. EXTENDS KEYWORD • Extends is the keyword used to inherit the properties of a class. Below given is the syntax of extends keyword. class Super { ..... } class Sub extends Super{ .... }
  • 50. A N OT H E R I M P O RTA N T J AVA C O N C E P T S YO U ’ L L RU N I N TO A L OT: INTERFACES An interface is a reference type in Java, it is similar to class, it is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.
  • 51. DECLARING INTERFACE /* File name : NameOfInterface.java */ import java.lang.*; //Any number of import statements public interface NameOfInterface { //Any number of final, static fields //Any number of abstract method declarations }
  • 54. A N OT H E R I M P O RTA N T J AVA C O N C E P T S YO U ’ L L RU N I N TO A L OT: POLYMORPHISM Polymorphism is the ability of an object to take on many forms.The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. Quack! Animal Animal Woof! Animal Meow! Speak()
  • 55. POLYMORPHISM EXAMPLE public interfaceVegetarian{} public class Animal{} public class Deer extends Animal implementsVegetarian{} • Following are true for the above example: – A Deer IS-A Animal – A Deer IS-AVegetarian – A Deer IS-A Deer – A Deer IS-A Object Deer d = new Deer(); Animal a = d; Vegetarian v = d; Object o = d;
  • 56. A N OT H E R I M P O RTA N T J AVA C O N C E P T S YO U ’ L L RU N I N TO A L OT: OVERRIDING The benefit of overriding is: ability to define a behavior that's specific to the subclass type which means a subclass can implement a parent class method based on its requirement. Quack! Animal Animal Woof! Animal Meow! Speak()
  • 57.
  • 59. EXERCISE 5 Example using Polymorphism Animal A( ) Duck Dog Cat C( ),A( )D( ),A( )K( ),A( )
  • 62. JAVA GRAPHICS APIS • Java Graphics APIs - AWT and Swing - provide a huge set of reusable GUI components, such as button, text field, label, choice, panel and frame for building GUI applications.You can simply reuse these classes rather than re-invent the wheels. I shall start with the AWT classes before moving into Swing to give you a complete picture. I have to stress that AWT component classes are now obsoleted by Swing's counterparts.
  • 63.
  • 65.
  • 66. MORE ABOUT GUI • GUI Programming https://www.ntu.edu.sg/home/ehchua/programming/java/J4a_GUI.html • NetbeansTutorial https://netbeans.org/kb/docs/java/gui-functionality.html • Main documentation: https://docs.oracle.com/javase/tutorial/uiswing/
  • 70. JAVA AWT EVENT HANDLING • Java provides a rich set of libraries to create Graphical User Interface in platform independent way. In this session we'll look in AWT (AbstractWindowToolkit), especially Event Handling. • Event is a change in the state of an object. Events are generated as result of user interaction with the graphical user interface components. For example, clicking on a button, moving the mouse, entering a character through keyboard, selecting an item from list, scrolling the page are the activities that causes an event to happen. • Event Handling is the mechanism that controls the event and decides what should happen if an event occurs.This mechanism have the code which is known as event handler that is executed when an event occurs. Java Uses the Delegation Event Model to handle the events.This model defines the standard mechanism to generate and handle the events.
  • 71. T H E DELEGATION EVENT MODEL H A S T H E F O L L OW I N G K E Y PA RT I C I PA N T S N A M E LY • Source - The source is an object on which event occurs. Source is responsible for providing information of the occurred event to it's handler. • Listener - It is also known as event handler. Listener is responsible for generating response to an event. Listener waits until it receives an event. Once the event is received , the listener process the event an then returns.
  • 72. T H E EVENTS C A N B E B ROA D LY C L A S S I F I E D I N TO T W O C AT E G O R I E S : • Foreground Events -Those events which require the direct interaction of user.They are generated as consequences of a person interacting with the graphical components in Graphical User Interface. For example, clicking on a button, moving the mouse, entering a character through keyboard, selecting an item from list, scrolling the page etc. • Background Events - Those events that require the interaction of end user are known as background events. Operating system interrupts, hardware or software failure, timer expires, an operation completion are the example of background events.
  • 73.
  • 74.
  • 78. MULTITHREADING • A multi-threaded program contains two or more parts that can run concurrently and each part can handle different task at the same time making optimal use of the available resources specially when your computer has multiple CPUs.
  • 80. CREATE THREAD BY IMPLEMENTING RUNNABLE INTERFACE • Step 1 you need to implement a run() method provided by Runnable interface. • Step 2 you will instantiate a Thread object using the following constructor: • Step 3 OnceThread object is created, you can start it by calling start( ) method, which executes a call to run( ) method. public void run( ) Thread(Runnable threadObj, String threadName); void start( );
  • 84. JAVA NETWORKING • The term network programming refers to writing programs that execute across multiple devices (computers), in which the devices are all connected to each other using a network.
  • 85. T H E J AVA . N E T PA C K A G E P ROV I D E S S U P P O RT F O R T H E T W O C O M M O N NETWORK PROTOCOLS • TCP:Transmission Control Protocol, which allows for reliable communication between two applications.TCP is typically used over the Internet Protocol, which is referred to asTCP/IP. • UDP: User Datagram Protocol, a connection-less protocol that allows for packets of data to be transmitted between applications.
  • 86. SOCKET PROGRAMMING • Sockets provide the communication mechanism between two computers usingTCP.A client program creates a socket on its end of the communication and attempts to connect that socket to a server.
  • 89. Tasks
  • 90. SIMPLE TASK • Design a class named Person and its two subclasses named Student and Employee. • Make Faculty member and Staff subclasses of Employee. • A person has a name, address, phone number, and email address. • A student has a class status (freshman, sophomore, junior, or senior). • Define the status as a constant. • An employee has an office, salary, and date hired. • Define a class named MyDate that contains the fields year, month, and day. • A faculty member has office hours and a rank. • A staff member has a title. • Override the toString method in each class to display the class name and the person’s name.
  • 91. SIMPLE TASK • Deliverables: – Optional: Draw the UML diagram for the classes. – Implement the classes. – Write a test program that creates a Person, Student, Employee, Faculty, and Staff, and invokes their toString() methods. – Build GUI to Add Employee andView all Employees – Bonus: Save and load employees data to/from File
  • 93. TUTORIALS • Text : http://www.tutorialspoint.com/java • Courses https://www.udacity.com/course/intro-to-java-programming--cs046 https://www.udemy.com/java-programming-basics/ • YouTube Videos – Recommended - https://www.youtube.com/playlist?list=PLFE2CE09D83EE3E28 https://www.youtube.com/playlist?list=PL27BCE863B6A864E3
  • 94. For any help feel free to contact me! Aly Osama alyosama@gmail.com https://eg.linkedin.com/in/alyosama