SlideShare ist ein Scribd-Unternehmen logo
1 von 48
Mobile Website Development
Overview of Java
Facilitated by:
Michael Wakahe
Tawi Commercial
Services Ltd
Jul 2011
Table of Contents
 Introduction
 Data Types and Operators
 Program Control Statements
 Methods, Classes & Objects
 Other Topics
 Exercise
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Introduction
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Introduction
 Originally developed by James Gosling at Sun
Microsystems - 1991
 Derives much of its syntax from C and C++
 Applications are typically compiled to
bytecode (class file) that can run on any Java
Virtual Machine (JVM)
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Introduction
 Is a general-purpose, concurrent, class-based,
object-oriented language
 “Write once, run anywhere"
 Current stable release: Java Standard Edition 6
(1.6.0)
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Introduction
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Introduction
Can be broken down into:
 Java Card
 Micro Edition (ME)
 Standard Edition (SE)
 Enterprise Edition (EE)
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Introduction
/*
This is a simple Java program.
Call this file Example.java. Compile and run in Eclipse.
*/
class Example {
// A Java program begins with a call to main().
public static void main(String args[]) {
System.out.println("Java drives the Web.");
}
}
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Introduction
/*
This demonstrates a variable.
Call this file Example2.java. Compile and run in Eclipse.
*/
class Example2 {
public static void main(String args[]) {
int var1; // this declares a variable
int var2; // this declares another variable
var1 = 1024; // this assigns 1024 to var1
System.out.println("var1 contains " + var1);
var2 = var1 / 2;
System.out.print("var2 contains var1 / 2: ");
System.out.println(var2);
}
}
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Data Types
and
Operators
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Data Types and Operators
‱ Contains 2 general categories of built-in data
types: object-oriented and non-object
oriented.
‱ There are eight primitives
‱ Primitive means these types are not objects
but rather normal binary values
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Data Types and Operators
Type Meaning
boolean Represents true/false values
byte 8-bit integer
char Character
double Double-precision floating point
float Single-precision floating point
int Integer
long Long integer
short Short integer
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Data Types and Operators
‱ Contains 2 general categories of built-in data
types: object-oriented and non-object
oriented.
‱ There are eight primitives
‱ Primitive means these types are not objects
but rather normal binary values
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Data Types and Operators
‱ An operator is a symbol that tells the compiler
to perform a specific mathematical or logical
manipulation.
‱ Java has four general classes of operators:
arithmetic, bitwise, relational, and logical.
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Data Types and Operators
Arithmentic operator examples:
 + implies addition
 / implies division
 % implies modulus
 ++ implies increment
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Data Types and Operators
 Relational refers to the relationships that
values can have with one another
 Examples include:
 == implies Equal to
 != implies Not Equal to
 > implies Greater than
 <= implies Less than or Equal to
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Data Types and Operators
 Logical refers to the ways in which true and
false values can be connected together
 Examples include:
 & implies AND
 | implies OR
 ! implies NOT
 && implies Short-circuit AND
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Data Types and Operators
 The outcome of the relational and logical
operators is a boolean value.
 The Assignment operator: var = expression;
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Data Types and Operators
‱ Approximately 50 keywords are currently
defined in the Java language
‱ Examples: enum, true, false, null, import, do,
break, for, int
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Data Types and Operators
 An identifier is a name given to a method, a
variable, or any other user-defined item
 Identifiers can be from one to several
characters long
 Variable names may start with any letter of
the alphabet, an underscore, or a dollar sign.
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Program
Control
Statements
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Program Control
Statements
‱ The if statement
‱ if(condition) statement;
‱ Example:
if(10 < 11) System.out.println("10 is less than 11");
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Program Control
Statements
 The general form of the if, using blocks of
statements, is:
if(condition)
{
statement sequence
}
else
{
statement sequence
}
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Program Control
Statements
‱ A common programming construct that is based
upon the nested if is the if-else-if ladder.
if(condition)
statement;
else if(condition)
statement;
else if(condition)
statement;
...
else
statement;
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Program Control
Statements
‱ The for Loop:
‱ for(initialization; condition; iteration) statement;
‱ Example
for(count = 0; count < 5; count = count+1)
System.out.println("This is count: " + count);
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Program Control
Statements
‱ The Switch statement:
switch(expression) {
case constant1:
statement sequence
break;
case constant2:
statement sequence
break;
case constant3:
statement sequence
break;
...
default:
statement sequence
}
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Program Control
Statements
int i = 

switch(i) {
case 0:
System.out.println("i is zero");
break;
case 1:
System.out.println("i is one");
break;
case 2:
System.out.println("i is two");
break; break;
default:
System.out.println("i is three or more");
}
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Program Control
Statements
 The general form of the while loop is:
while(condition) statement;
 Example:
// print the alphabet using a while loop
char ch;
ch = 'a';
while(ch <= 'z') {
System.out.print(ch);
ch++;
}
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Program Control
Statements
‱ The general form of the do-while loop is
do {
statements;
} while(condition);
‱ Very similar to while loop
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Methods,
Classes &
Objects
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Classes & Objects
 Java’s basic unit of encapsulation is the class
 A class defines the form of an object
 It specifies both the data and the code that
will operate on that data
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Classes & Objects
 Java uses a class specification to construct
objects
 Objects are instances of a class.
 Thus, a class is essentially a set of plans that
specify how to build an object
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Classes & Objects
‱ The general form of a class definition:
class classname {
// declare instance variables
type var1;
type var2;
// ...
type varN;
// declare methods
type method1(parameters) {
// body of method
}
type method2(parameters) {
// body of method
}
// ...
type methodN(parameters) {
// body of method
}
}
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Classes & Objects
 How objects are declared:
Classname referenceName = new
Classname(arguments);
 The general form of a method is:
ret-type name( parameter-list ) {
// body of method
}
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Classes & Objects
 A constructor initializes an object when it is created.
‱ A simple example that uses a constructor:
// A simple constructor.
class MyClass {
int x;
MyClass() {
x = 10;
}
}
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Other Topics
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Other Topics
‱ Casting: A cast is an instruction to the
compiler to convert one type into another.
‱ A cast has this general form:
(target-type) expression
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Other Topics
‱ Inheritance is the process by which one object
can acquire the properties of another object.
‱ Use of hierarchies.
‱ The inheritance mechanism that makes it
possible for one object to be a specific
instance of a more general case
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Other Topics
 Polymorphism - “one interface, multiple
methods.”
 This means that it is possible to design a
generic interface to a group of related
activities.
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Other Topics
‱ Packages are groups of related classes.
‱ Packages help organize your code and provide
another layer of encapsulation.
‱ An interface defines a set of methods that will
be implemented by a class.
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Other Topics
 An interface does not, itself, implement any
method.
 It is a purely logical construct.
 Packages and interfaces give you greater
control over the organization of your program
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Other Topics
 An exception is an error that occurs at run
time.
 Using Java’s exception handling subsystem you
can, in a structured and controlled manner,
handle run-time errors.
 Use try-catch and Throwable
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Other Topics
 Java has built-in support for multithreaded
programming.
 A multithreaded program contains two or more
parts that can run concurrently.
 Each part of such a program is called a thread,
and each thread defines a separate path of
execution.
 Thus, multithreading is a specialized form of
multitasking.
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Exercise
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Exercise
‱ Program to simulate a School
‱ Attributes of school include:
– Name
– Location
‱ School has Teacher and Students
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Exercise
‱ Teacher has:
– First & Last Name
– Course taught
– Years employed
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
Exercise
‱ Student has:
– First & Last Name
– 5 subjects with grades
– Can get average grade
– Has a fee balace
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.
The End
Michael Wakahe
michael@tawi.mobi
+254 (0)20 239 3052
www.tawi.mobi
Copyright © Tawi Commercial Services Ltd. 2015. All Rights
Reserved.

Weitere Àhnliche Inhalte

Was ist angesagt?

Ap Power Point Chpt7
Ap Power Point Chpt7Ap Power Point Chpt7
Ap Power Point Chpt7
dplunkett
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
Srikanth R Vaka
 

Was ist angesagt? (12)

Core Java Basics
Core Java BasicsCore Java Basics
Core Java Basics
 
Common Programming Paradigms
Common Programming ParadigmsCommon Programming Paradigms
Common Programming Paradigms
 
Ap Power Point Chpt7
Ap Power Point Chpt7Ap Power Point Chpt7
Ap Power Point Chpt7
 
Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++
 
Intro to Object Oriented Programming with Java
Intro to Object Oriented Programming with Java Intro to Object Oriented Programming with Java
Intro to Object Oriented Programming with Java
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Refactoring to SOLID Code
Refactoring to SOLID CodeRefactoring to SOLID Code
Refactoring to SOLID Code
 
Technical interview questions
Technical interview questionsTechnical interview questions
Technical interview questions
 
Mock objectsinaction paulo_caroli_and_sudhindra_rao_agile2009_final
Mock objectsinaction paulo_caroli_and_sudhindra_rao_agile2009_finalMock objectsinaction paulo_caroli_and_sudhindra_rao_agile2009_final
Mock objectsinaction paulo_caroli_and_sudhindra_rao_agile2009_final
 
API Design
API DesignAPI Design
API Design
 
C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2
 
Data weave 2.0 language fundamentals
Data weave 2.0 language fundamentalsData weave 2.0 language fundamentals
Data weave 2.0 language fundamentals
 

Ähnlich wie Overview of Java

Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon RitterLambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
JAXLondon2014
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
Edureka!
 

Ähnlich wie Overview of Java (20)

Final ppt
Final pptFinal ppt
Final ppt
 
Lambdas : Beyond The Basics
Lambdas : Beyond The BasicsLambdas : Beyond The Basics
Lambdas : Beyond The Basics
 
React advance
React advanceReact advance
React advance
 
Testing Java EE Applications Using Arquillian
Testing Java EE Applications Using ArquillianTesting Java EE Applications Using Arquillian
Testing Java EE Applications Using Arquillian
 
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon RitterLambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
 
Lambdas And Streams in JDK8
Lambdas And Streams in JDK8Lambdas And Streams in JDK8
Lambdas And Streams in JDK8
 
Basic Concepts of Programming_withlogo.pdf
Basic Concepts of Programming_withlogo.pdfBasic Concepts of Programming_withlogo.pdf
Basic Concepts of Programming_withlogo.pdf
 
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]
 
Specification-by-Example: A Cucumber Implementation
Specification-by-Example: A Cucumber ImplementationSpecification-by-Example: A Cucumber Implementation
Specification-by-Example: A Cucumber Implementation
 
Functional Programming in Python
Functional Programming in PythonFunctional Programming in Python
Functional Programming in Python
 
What's New in Java 8
What's New in Java 8What's New in Java 8
What's New in Java 8
 
Finally, EE Security API JSR 375
Finally, EE Security API JSR 375Finally, EE Security API JSR 375
Finally, EE Security API JSR 375
 
Technical trainning.pptx
Technical trainning.pptxTechnical trainning.pptx
Technical trainning.pptx
 
Mule soft meetup_charlotte_4__draft_v2.0
Mule soft meetup_charlotte_4__draft_v2.0Mule soft meetup_charlotte_4__draft_v2.0
Mule soft meetup_charlotte_4__draft_v2.0
 
What is DevOps?
What is DevOps?What is DevOps?
What is DevOps?
 
Guide to Java.pptx
Guide to Java.pptxGuide to Java.pptx
Guide to Java.pptx
 
Grails Services
Grails ServicesGrails Services
Grails Services
 
Automated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choiceAutomated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choice
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
 
JavaScript_introduction_upload.pdf
JavaScript_introduction_upload.pdfJavaScript_introduction_upload.pdf
JavaScript_introduction_upload.pdf
 

Mehr von tawi123

Mehr von tawi123 (20)

Tax Compliance Certificate, May 2016 - May 2017
Tax Compliance Certificate, May 2016 -  May 2017Tax Compliance Certificate, May 2016 -  May 2017
Tax Compliance Certificate, May 2016 - May 2017
 
XHTML and CSS
XHTML and CSSXHTML and CSS
XHTML and CSS
 
Survey of WML
Survey of  WMLSurvey of  WML
Survey of WML
 
Server Side Technologies
Server Side TechnologiesServer Side Technologies
Server Side Technologies
 
Software Tools Overview
Software Tools OverviewSoftware Tools Overview
Software Tools Overview
 
Mobile Internet Standards
Mobile Internet StandardsMobile Internet Standards
Mobile Internet Standards
 
Mobile Internet Best Practices
Mobile Internet Best PracticesMobile Internet Best Practices
Mobile Internet Best Practices
 
Introduction to SMS, MMS, Modems & Gateways
Introduction to SMS, MMS, Modems & GatewaysIntroduction to SMS, MMS, Modems & Gateways
Introduction to SMS, MMS, Modems & Gateways
 
Introduction to Mobile Internet
Introduction to Mobile InternetIntroduction to Mobile Internet
Introduction to Mobile Internet
 
Mobile Website Development
Mobile Website DevelopmentMobile Website Development
Mobile Website Development
 
Brief on Device Awareness and Content Adaptation
Brief on Device Awareness and Content AdaptationBrief on Device Awareness and Content Adaptation
Brief on Device Awareness and Content Adaptation
 
Linux, PHP, SMS - USSD Examination
Linux, PHP,  SMS - USSD ExaminationLinux, PHP,  SMS - USSD Examination
Linux, PHP, SMS - USSD Examination
 
Workstation Exercises
Workstation ExercisesWorkstation Exercises
Workstation Exercises
 
Work Injury Benefits Act 2007
Work Injury Benefits Act 2007Work Injury Benefits Act 2007
Work Injury Benefits Act 2007
 
The Kenya Information and Communications Consumer Protection Regulations 2010
The Kenya Information and Communications Consumer Protection Regulations 2010The Kenya Information and Communications Consumer Protection Regulations 2010
The Kenya Information and Communications Consumer Protection Regulations 2010
 
Tax KRA Compliance Certificate
Tax KRA Compliance CertificateTax KRA Compliance Certificate
Tax KRA Compliance Certificate
 
Tawi Staff Handbook 2015
Tawi Staff Handbook 2015Tawi Staff Handbook 2015
Tawi Staff Handbook 2015
 
Tawi SMS-USSD Customer Agreement
Tawi SMS-USSD Customer AgreementTawi SMS-USSD Customer Agreement
Tawi SMS-USSD Customer Agreement
 
Tawi SMS Application Form - SMS Short Code
Tawi SMS Application Form - SMS Short CodeTawi SMS Application Form - SMS Short Code
Tawi SMS Application Form - SMS Short Code
 
Tawi Product Overview
Tawi Product OverviewTawi Product Overview
Tawi Product Overview
 

KĂŒrzlich hochgeladen

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

KĂŒrzlich hochgeladen (20)

Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...
TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...
TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 

Overview of Java

  • 1. Mobile Website Development Overview of Java Facilitated by: Michael Wakahe Tawi Commercial Services Ltd Jul 2011
  • 2. Table of Contents  Introduction  Data Types and Operators  Program Control Statements  Methods, Classes & Objects  Other Topics  Exercise Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 3. Introduction Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 4. Introduction  Originally developed by James Gosling at Sun Microsystems - 1991  Derives much of its syntax from C and C++  Applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 5. Introduction  Is a general-purpose, concurrent, class-based, object-oriented language  “Write once, run anywhere"  Current stable release: Java Standard Edition 6 (1.6.0) Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 6. Introduction Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 7. Introduction Can be broken down into:  Java Card  Micro Edition (ME)  Standard Edition (SE)  Enterprise Edition (EE) Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 8. Introduction /* This is a simple Java program. Call this file Example.java. Compile and run in Eclipse. */ class Example { // A Java program begins with a call to main(). public static void main(String args[]) { System.out.println("Java drives the Web."); } } Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 9. Introduction /* This demonstrates a variable. Call this file Example2.java. Compile and run in Eclipse. */ class Example2 { public static void main(String args[]) { int var1; // this declares a variable int var2; // this declares another variable var1 = 1024; // this assigns 1024 to var1 System.out.println("var1 contains " + var1); var2 = var1 / 2; System.out.print("var2 contains var1 / 2: "); System.out.println(var2); } } Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 10. Data Types and Operators Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 11. Data Types and Operators ‱ Contains 2 general categories of built-in data types: object-oriented and non-object oriented. ‱ There are eight primitives ‱ Primitive means these types are not objects but rather normal binary values Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 12. Data Types and Operators Type Meaning boolean Represents true/false values byte 8-bit integer char Character double Double-precision floating point float Single-precision floating point int Integer long Long integer short Short integer Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 13. Data Types and Operators ‱ Contains 2 general categories of built-in data types: object-oriented and non-object oriented. ‱ There are eight primitives ‱ Primitive means these types are not objects but rather normal binary values Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 14. Data Types and Operators ‱ An operator is a symbol that tells the compiler to perform a specific mathematical or logical manipulation. ‱ Java has four general classes of operators: arithmetic, bitwise, relational, and logical. Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 15. Data Types and Operators Arithmentic operator examples:  + implies addition  / implies division  % implies modulus  ++ implies increment Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 16. Data Types and Operators  Relational refers to the relationships that values can have with one another  Examples include:  == implies Equal to  != implies Not Equal to  > implies Greater than  <= implies Less than or Equal to Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 17. Data Types and Operators  Logical refers to the ways in which true and false values can be connected together  Examples include:  & implies AND  | implies OR  ! implies NOT  && implies Short-circuit AND Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 18. Data Types and Operators  The outcome of the relational and logical operators is a boolean value.  The Assignment operator: var = expression; Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 19. Data Types and Operators ‱ Approximately 50 keywords are currently defined in the Java language ‱ Examples: enum, true, false, null, import, do, break, for, int Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 20. Data Types and Operators  An identifier is a name given to a method, a variable, or any other user-defined item  Identifiers can be from one to several characters long  Variable names may start with any letter of the alphabet, an underscore, or a dollar sign. Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 21. Program Control Statements Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 22. Program Control Statements ‱ The if statement ‱ if(condition) statement; ‱ Example: if(10 < 11) System.out.println("10 is less than 11"); Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 23. Program Control Statements  The general form of the if, using blocks of statements, is: if(condition) { statement sequence } else { statement sequence } Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 24. Program Control Statements ‱ A common programming construct that is based upon the nested if is the if-else-if ladder. if(condition) statement; else if(condition) statement; else if(condition) statement; ... else statement; Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 25. Program Control Statements ‱ The for Loop: ‱ for(initialization; condition; iteration) statement; ‱ Example for(count = 0; count < 5; count = count+1) System.out.println("This is count: " + count); Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 26. Program Control Statements ‱ The Switch statement: switch(expression) { case constant1: statement sequence break; case constant2: statement sequence break; case constant3: statement sequence break; ... default: statement sequence } Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 27. Program Control Statements int i = 
 switch(i) { case 0: System.out.println("i is zero"); break; case 1: System.out.println("i is one"); break; case 2: System.out.println("i is two"); break; break; default: System.out.println("i is three or more"); } Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 28. Program Control Statements  The general form of the while loop is: while(condition) statement;  Example: // print the alphabet using a while loop char ch; ch = 'a'; while(ch <= 'z') { System.out.print(ch); ch++; } Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 29. Program Control Statements ‱ The general form of the do-while loop is do { statements; } while(condition); ‱ Very similar to while loop Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 30. Methods, Classes & Objects Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 31. Classes & Objects  Java’s basic unit of encapsulation is the class  A class defines the form of an object  It specifies both the data and the code that will operate on that data Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 32. Classes & Objects  Java uses a class specification to construct objects  Objects are instances of a class.  Thus, a class is essentially a set of plans that specify how to build an object Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 33. Classes & Objects ‱ The general form of a class definition: class classname { // declare instance variables type var1; type var2; // ... type varN; // declare methods type method1(parameters) { // body of method } type method2(parameters) { // body of method } // ... type methodN(parameters) { // body of method } } Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 34. Classes & Objects  How objects are declared: Classname referenceName = new Classname(arguments);  The general form of a method is: ret-type name( parameter-list ) { // body of method } Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 35. Classes & Objects  A constructor initializes an object when it is created. ‱ A simple example that uses a constructor: // A simple constructor. class MyClass { int x; MyClass() { x = 10; } } Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 36. Other Topics Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 37. Other Topics ‱ Casting: A cast is an instruction to the compiler to convert one type into another. ‱ A cast has this general form: (target-type) expression Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 38. Other Topics ‱ Inheritance is the process by which one object can acquire the properties of another object. ‱ Use of hierarchies. ‱ The inheritance mechanism that makes it possible for one object to be a specific instance of a more general case Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 39. Other Topics  Polymorphism - “one interface, multiple methods.”  This means that it is possible to design a generic interface to a group of related activities. Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 40. Other Topics ‱ Packages are groups of related classes. ‱ Packages help organize your code and provide another layer of encapsulation. ‱ An interface defines a set of methods that will be implemented by a class. Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 41. Other Topics  An interface does not, itself, implement any method.  It is a purely logical construct.  Packages and interfaces give you greater control over the organization of your program Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 42. Other Topics  An exception is an error that occurs at run time.  Using Java’s exception handling subsystem you can, in a structured and controlled manner, handle run-time errors.  Use try-catch and Throwable Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 43. Other Topics  Java has built-in support for multithreaded programming.  A multithreaded program contains two or more parts that can run concurrently.  Each part of such a program is called a thread, and each thread defines a separate path of execution.  Thus, multithreading is a specialized form of multitasking. Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 44. Exercise Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 45. Exercise ‱ Program to simulate a School ‱ Attributes of school include: – Name – Location ‱ School has Teacher and Students Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 46. Exercise ‱ Teacher has: – First & Last Name – Course taught – Years employed Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 47. Exercise ‱ Student has: – First & Last Name – 5 subjects with grades – Can get average grade – Has a fee balace Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.
  • 48. The End Michael Wakahe michael@tawi.mobi +254 (0)20 239 3052 www.tawi.mobi Copyright © Tawi Commercial Services Ltd. 2015. All Rights Reserved.