SlideShare a Scribd company logo
1 of 36
Learn Java in 2 days
By Ahmed Ali Ali © 2013
Email : ahmed14ghaly@gmail.com
a14a2a1992a@yahoo.com

By Ahmed Ali Ali © 2013

1
Agenda
First day

Second day (soon)

•Introduction
•Class

•File

Declarations & Modifiers

•Wrapper

Classes

•Handling

I/O

•inner

class

Exceptions

•Threads
•Collections

•immutable
•StringBuffer, and
•Tokenizing
•Quiz

StringBuilder

•Utility

Classes: Collections and Arrays

•Generics
•Quiz

By Ahmed Ali Ali © 2013

2
Introduction
•

Java is an object-oriented programming language .

•

Java was started as a project called "Oak" by James Gosling in June1991. Gosling's
goals were to implement a virtual machine and a language that had a familiar Clike notation but with greater uniformity and simplicity than C/C++. The first

public implementation was Java 1.0 in 1995
• The

language itself borrows much syntax from C and C++ but has a

simpler object model and fewer low-level facilities.
•

Java Is Easy to Learn

By Ahmed Ali Ali © 2013

3
Complete List of Java Keywords

By Ahmed Ali Ali © 2013

4
My First Java Program

By Ahmed Ali Ali © 2013

5
Class Declarations
•

Source File Declaration Rules

o only one public class per source code file.
o A file can have more than one nonpublic class.

o If there is a public class in a file, the name of the file must match the name of the
public class.
o If the class is part of a package, the package statement must be the first line in
the source code file, before any import statements that may be present
o import and package statements apply to all classes within a source code file.

By Ahmed Ali Ali © 2013

6
Class Access(Class Modifiers)
• What

•

does it mean to access a class?

Class Modifiers
o Public Access
o Default Access

•

package cert;
Public class Beverage { }
package cert;
class Beverage { }

Other (Non access) Class Modifiers
o Final Classes

package cert;
Final class Beverage { }

o Abstract Classes

package cert;
Abstract class Beverage { }

By Ahmed Ali Ali © 2013

7
Declare Interfaces
• An

interface must be declared with the keyword interface.

• All

interface methods are implicitly public and abstract. In other words, you do not need to actually
type the public or abstract .

•

Interface methods must not be static.

•

Because interface methods are abstract, they cannot be marked final,

• All

variables defined in an interface must be public, static, and final.

• An

interface can extend one or more other interfaces.

• An

interface cannot implement another interface or class.
By Ahmed Ali Ali © 2013

8
Declare Class Members
•We've

looked at what it means to use a modifier in a class declaration, and now
we'll look at what it means to modify a method or variable declaration.
• Access

o
o
o
o
•

Modifiers

public
protected
default
private

Nonaccess Member Modifiers

o Final and abstract
o Synchronized methods
By Ahmed Ali Ali © 2013

9
Determining Access to Class
Member

By Ahmed Ali Ali © 2013

10
Develop Constructors
• The

•

constructor name must match the name of the class.

If you don't type a constructor into your class code, a default constructor will be
automatically generated by the compiler.

•

Constructors must not have a return type.

•

Constructors can use any access modifier,

•

Every class, including abstract classes, MUST have a constructor.

•

constructors are invoked at runtime when you say new on some class.
By Ahmed Ali Ali © 2013

11
Variable Declarations
•

There are two types of variables in Java:

o Primitives : A primitive can be one of eight types: char, boolean, byte,
short, int, long, double, or float. Once a primitive has been declared, its
primitive type can never change, although in most cases its value can
change.
o Reference variables : A reference variable is used to refer to (or
access) an object. A reference variable is declared to be of a specific
type and that type can never be changed.
•

Note :

o It is legal to declare a local variable with the same name as an instance
variable; this is called "shadowing."
By Ahmed Ali Ali © 2013

12
Variable Scope

By Ahmed Ali Ali © 2013

13
if and switch Statements
• The

•

only legal expression in an if statement is a boolean expression.

Curly braces are optional for if blocks that have only
one conditional statement.

•

switch statements can evaluate only to enums or the
byte, short, int, and char data types.You can't say,

By Ahmed Ali Ali © 2013

14
Ternary (Conditional Operator)
Returns one of two values based on whether a boolean expression is true or
false.
•

•

Returns the value after the ? if the expression is true.

•

Returns the value after the : if the expression is false.
x = (boolean expression) ? value to assign if true : value to assign if false

By Ahmed Ali Ali © 2013

15
String Concatenation Operator
•

If either operand is a String, the + operator concatenates the operands.

•

If both operands are numeric, the + operator adds the operands.

By Ahmed Ali Ali © 2013

16
Overloading & Overriding
• Abstract

methods must be overridden by the first concrete (subclass).

•

final methods cannot be overridden.

•

Only inherited methods may be overridden, and remember that private methods
are not inherited.

•A

subclass uses super. overriddenMethodName() to call the superclass version of

an overridden method.
•

Object type (not the reference variable's type), determines which overridden
method is used at runtime.
By Ahmed Ali Ali © 2013

17
Overloading & Overriding (cont’)
•

Methods from a superclass can be overloaded in a subclass.

•

constructors can be overloaded but not overridden.

•

Overloading means reusing a method name, but with different arguments.

•

Overloaded methods.
o Must have different argument lists
o May have different return types, if argument lists are also different
o May have different access modifiers
o May throw different exceptions

•

Polymorphism applies to overriding, not to overloading.

•

Reference type determines which overloaded method will be used at
compile time.

By Ahmed Ali Ali © 2013

18
Stack and Heap—Quick Review
•

understanding the basics of the stack and the heap makes it far easier to
understand topics like argument passing, threads, exceptions,

•

Instance variables and objects live on the heap.

•

Local variables live on the stack.

By Ahmed Ali Ali © 2013

19
Wrapper Classes
•What’s consept of Wrapper Class ?
•The wrapper classes correlate to the primitive types
•The three most important method families are
o xxxValue() Takes no arguments, returns a primitive
o parseXxx() Takes a String, returns a primitive
o valueOf() Takes a String, returns a wrapped object

By Ahmed Ali Ali © 2013

20
Handling Exceptions
• The

term "exception" means "exceptional condition" and is an occurrence that

alters the normal program flow.
•

Exception handling allows developers to detect errors easily without writing
special code to test return values.

•A

bunch of things can lead to exceptions, including hardware failures, resource

exhaustion, and good old bugs.
When an exceptional event occurs in Java, an exception is said to be "thrown." The
code that's responsible for doing something about the exception is called an
"exception handler," and it "catches" the thrown exception.

By Ahmed Ali Ali © 2013

21
Handling Exceptions (cont’)

Example :

By Ahmed Ali Ali © 2013

22
Assertion Mechanism
•

the assertion mechanism, added to the language with version 1.4, gives you
a way to do testing and debugging checks on conditions you expect to smoke out
while developing,

•

writing code with assert statement will help you to be better programmer
and improve quality of code, yes this is true based on my experience when we
write code using assert statement we think through hard, we think about possible
input to a function, we think about boundary condition which eventually result in
better discipline and quality code.

"If" is a conditional operator with a specific loop syntax. It can be followed with the
loop continuation syntax "else". The "Assert" keyword will throw a run-time error if
the condition of the loop returns 'false' and is used for conditional validation(parameter checking).
Assertions are mainly used to debug code and are generally removed in a live product. Both "If" &
"Assert" evaluate a Boolean condition.

•

By Ahmed Ali Ali © 2013

23
Assertion Mechanism
Use assertions for internal logic checks within your code, and normal exceptions for
error conditions outside your immediate code's control.
Really simple:
private void doStuff() {
assert (y > x);
// more code assuming y
//is greater than x
}
Simple:
private void doStuff() {
assert (y > x): "y is " + y + " x is " + x;
// more code assuming y is greater than x
}

By Ahmed Ali Ali © 2013

24
immutable
•

an immutable object is an object whose state cannot be modified after it is

created
•Strings

Are Immutable Objects

By Ahmed Ali Ali © 2013

25
StringBuffer, and StringBuilder
•

The java.lang.StringBuffer and java.lang.StringBuilder classes should

be used when you have to make a lot of modifications to strings of
characters

•

StringBuilder is not thread safe. In other words, its
methods are not synchronized.

•

StringBuilder runs faster.

By Ahmed Ali Ali © 2013

26
Dates, Numbers, and Currency
•

Here are the date related classes you'll need to understand.

o java.util.Date
o java.util.Calendar

o java.text.DateFormat
o java.text.NumberFormat
o java.util.Locale
By Ahmed Ali Ali © 2013

27
Dates, Numbers, and Currency
(cont’)

By Ahmed Ali Ali © 2013

28
Dates, Numbers, and Currency
(cont’)

By Ahmed Ali Ali © 2013

29
A Search Tutorial
• To

find specific pieces of data in large data sources, Java provides several
mechanisms that use the concepts of regular expressions (Regex).

Simple Searches
we'd like to search through the following source String (abaaaba)
for all occurrences (or matches) of the expression (ab) .

• What

the result if we search on (aba) inside the String (abababa) ?
By Ahmed Ali Ali © 2013

30
A Search Tutorial (cont’)
[abc] Searches only for a's, b's or c's

[a-f] Searches only for a, b, c, d, e, or f characters
d A digit
s A whitespace character
w A word character (letters, digits, or "_" (underscore))
the quantifier that represents "one or more" is the "+" (Ex. d+)
Example :
source: "a 1 56 _Z"
index: 012345678

pattern: w
In this case will return positions 0, 2, 4, 5, 7, and 8.
By Ahmed Ali Ali © 2013

31
Tokenizing
• Tokenizing

is the process of taking big pieces of source data, breaking

them into little pieces, and storing the little pieces in variables.
Tokens and Delimiters
source: "ab,cd5b,6x,z4"
If we say that our delimiter is a comma, then our four tokens would be
ab
cd5b

6x
z4
By Ahmed Ali Ali © 2013

32
Tokenizing (cont’)
Tokenizing with String.split()

By Ahmed Ali Ali © 2013

33
Quiz

By Ahmed Ali Ali © 2013

34
Questions
By Ahmed Ali Ali © 2013

35
Thanks
By Ahmed Ali Ali © 2013

36

More Related Content

What's hot

Introduction to method overloading & method overriding in java hdm
Introduction to method overloading & method overriding  in java  hdmIntroduction to method overloading & method overriding  in java  hdm
Introduction to method overloading & method overriding in java hdmHarshal Misalkar
 
Visibility control in java
Visibility control in javaVisibility control in java
Visibility control in javaTech_MX
 
Regex - Regular Expression Basics
Regex - Regular Expression BasicsRegex - Regular Expression Basics
Regex - Regular Expression BasicsEterna Han Tsai
 
Regular Expressions in Java
Regular Expressions in JavaRegular Expressions in Java
Regular Expressions in JavaOblivionWalker
 
Abstraction java
Abstraction javaAbstraction java
Abstraction javaMahinImran
 
Seventh session functional and non functional requrements & usecase example
Seventh session functional and non functional requrements & usecase exampleSeventh session functional and non functional requrements & usecase example
Seventh session functional and non functional requrements & usecase exampleAliMohammad155
 
Java: Regular Expression
Java: Regular ExpressionJava: Regular Expression
Java: Regular ExpressionMasudul Haque
 
Lecture 3 RE NFA DFA
Lecture 3   RE NFA DFA Lecture 3   RE NFA DFA
Lecture 3 RE NFA DFA Rebaz Najeeb
 
Enumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | EdurekaEnumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | EdurekaEdureka!
 
Java Development Kit (jdk)
Java Development Kit (jdk)Java Development Kit (jdk)
Java Development Kit (jdk)Jadavsejal
 
Pumping lemma for regular language
Pumping lemma for regular languagePumping lemma for regular language
Pumping lemma for regular languagesadique_ghitm
 
Nondeterministic Finite Automata
Nondeterministic Finite AutomataNondeterministic Finite Automata
Nondeterministic Finite AutomataAdel Al-Ofairi
 
Reflection in java
Reflection in javaReflection in java
Reflection in javaupen.rockin
 
Multiple inheritance in java3 (1).pptx
Multiple inheritance in java3 (1).pptxMultiple inheritance in java3 (1).pptx
Multiple inheritance in java3 (1).pptxRkGupta83
 
Method Overloading In Java
Method Overloading In JavaMethod Overloading In Java
Method Overloading In JavaCharthaGaglani
 
Constructor in java
Constructor in javaConstructor in java
Constructor in javaHitesh Kumar
 

What's hot (20)

Introduction to method overloading & method overriding in java hdm
Introduction to method overloading & method overriding  in java  hdmIntroduction to method overloading & method overriding  in java  hdm
Introduction to method overloading & method overriding in java hdm
 
Visibility control in java
Visibility control in javaVisibility control in java
Visibility control in java
 
Regex - Regular Expression Basics
Regex - Regular Expression BasicsRegex - Regular Expression Basics
Regex - Regular Expression Basics
 
Regular Expressions in Java
Regular Expressions in JavaRegular Expressions in Java
Regular Expressions in Java
 
Abstraction java
Abstraction javaAbstraction java
Abstraction java
 
Seventh session functional and non functional requrements & usecase example
Seventh session functional and non functional requrements & usecase exampleSeventh session functional and non functional requrements & usecase example
Seventh session functional and non functional requrements & usecase example
 
Java: Regular Expression
Java: Regular ExpressionJava: Regular Expression
Java: Regular Expression
 
Lecture 3 RE NFA DFA
Lecture 3   RE NFA DFA Lecture 3   RE NFA DFA
Lecture 3 RE NFA DFA
 
Enumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | EdurekaEnumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | Edureka
 
Java Development Kit (jdk)
Java Development Kit (jdk)Java Development Kit (jdk)
Java Development Kit (jdk)
 
Java Class Loader
Java Class LoaderJava Class Loader
Java Class Loader
 
Pumping lemma for regular language
Pumping lemma for regular languagePumping lemma for regular language
Pumping lemma for regular language
 
Nondeterministic Finite Automata
Nondeterministic Finite AutomataNondeterministic Finite Automata
Nondeterministic Finite Automata
 
Semaphore
SemaphoreSemaphore
Semaphore
 
Regular Expressions To Finite Automata
Regular Expressions To Finite AutomataRegular Expressions To Finite Automata
Regular Expressions To Finite Automata
 
Reflection in java
Reflection in javaReflection in java
Reflection in java
 
Multiple inheritance in java3 (1).pptx
Multiple inheritance in java3 (1).pptxMultiple inheritance in java3 (1).pptx
Multiple inheritance in java3 (1).pptx
 
Method Overloading In Java
Method Overloading In JavaMethod Overloading In Java
Method Overloading In Java
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 

Similar to Learn Java in 2 days

Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean CodingMetin Ogurlu
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8Heartin Jacob
 
FRONTEND BOOTCAMP Session 2.pptx
FRONTEND BOOTCAMP Session 2.pptxFRONTEND BOOTCAMP Session 2.pptx
FRONTEND BOOTCAMP Session 2.pptxEhtesham46
 
Java+8-New+Features.pdf
Java+8-New+Features.pdfJava+8-New+Features.pdf
Java+8-New+Features.pdfgurukanth4
 
Core Java Basics
Core Java BasicsCore Java Basics
Core Java BasicsFayis-QA
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave ImplicitMartin Odersky
 
2CPP09 - Encapsulation
2CPP09 - Encapsulation2CPP09 - Encapsulation
2CPP09 - EncapsulationMichael Heron
 
SOLID Design Principles for Test Automaion
SOLID Design Principles for Test AutomaionSOLID Design Principles for Test Automaion
SOLID Design Principles for Test AutomaionKnoldus Inc.
 
Code reviews
Code reviewsCode reviews
Code reviewsRoger Xia
 
Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1Sherihan Anver
 
Angularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetupAngularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetupGoutam Dey
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_reviewEdureka!
 
2CPP11 - Method Overloading
2CPP11 - Method Overloading2CPP11 - Method Overloading
2CPP11 - Method OverloadingMichael Heron
 

Similar to Learn Java in 2 days (20)

Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
 
Core java
Core javaCore java
Core java
 
Core java
Core javaCore java
Core java
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8
 
FRONTEND BOOTCAMP Session 2.pptx
FRONTEND BOOTCAMP Session 2.pptxFRONTEND BOOTCAMP Session 2.pptx
FRONTEND BOOTCAMP Session 2.pptx
 
Java+8-New+Features.pdf
Java+8-New+Features.pdfJava+8-New+Features.pdf
Java+8-New+Features.pdf
 
Core Java Basics
Core Java BasicsCore Java Basics
Core Java Basics
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 
2CPP09 - Encapsulation
2CPP09 - Encapsulation2CPP09 - Encapsulation
2CPP09 - Encapsulation
 
DAA Unit 1.pdf
DAA Unit 1.pdfDAA Unit 1.pdf
DAA Unit 1.pdf
 
SOLID Design Principles for Test Automaion
SOLID Design Principles for Test AutomaionSOLID Design Principles for Test Automaion
SOLID Design Principles for Test Automaion
 
Code reviews
Code reviewsCode reviews
Code reviews
 
Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
Angularjs
AngularjsAngularjs
Angularjs
 
Angularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetupAngularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetup
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
 
2CPP11 - Method Overloading
2CPP11 - Method Overloading2CPP11 - Method Overloading
2CPP11 - Method Overloading
 
java.pptx
java.pptxjava.pptx
java.pptx
 

Recently uploaded

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
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.docxRamakrishna Reddy Bijjam
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
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.pdfPoh-Sun Goh
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
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Ữ Â...Nguyen Thanh Tu Collection
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 

Recently uploaded (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
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
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
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
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
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Ữ Â...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 

Learn Java in 2 days

  • 1. Learn Java in 2 days By Ahmed Ali Ali © 2013 Email : ahmed14ghaly@gmail.com a14a2a1992a@yahoo.com By Ahmed Ali Ali © 2013 1
  • 2. Agenda First day Second day (soon) •Introduction •Class •File Declarations & Modifiers •Wrapper Classes •Handling I/O •inner class Exceptions •Threads •Collections •immutable •StringBuffer, and •Tokenizing •Quiz StringBuilder •Utility Classes: Collections and Arrays •Generics •Quiz By Ahmed Ali Ali © 2013 2
  • 3. Introduction • Java is an object-oriented programming language . • Java was started as a project called "Oak" by James Gosling in June1991. Gosling's goals were to implement a virtual machine and a language that had a familiar Clike notation but with greater uniformity and simplicity than C/C++. The first public implementation was Java 1.0 in 1995 • The language itself borrows much syntax from C and C++ but has a simpler object model and fewer low-level facilities. • Java Is Easy to Learn By Ahmed Ali Ali © 2013 3
  • 4. Complete List of Java Keywords By Ahmed Ali Ali © 2013 4
  • 5. My First Java Program By Ahmed Ali Ali © 2013 5
  • 6. Class Declarations • Source File Declaration Rules o only one public class per source code file. o A file can have more than one nonpublic class. o If there is a public class in a file, the name of the file must match the name of the public class. o If the class is part of a package, the package statement must be the first line in the source code file, before any import statements that may be present o import and package statements apply to all classes within a source code file. By Ahmed Ali Ali © 2013 6
  • 7. Class Access(Class Modifiers) • What • does it mean to access a class? Class Modifiers o Public Access o Default Access • package cert; Public class Beverage { } package cert; class Beverage { } Other (Non access) Class Modifiers o Final Classes package cert; Final class Beverage { } o Abstract Classes package cert; Abstract class Beverage { } By Ahmed Ali Ali © 2013 7
  • 8. Declare Interfaces • An interface must be declared with the keyword interface. • All interface methods are implicitly public and abstract. In other words, you do not need to actually type the public or abstract . • Interface methods must not be static. • Because interface methods are abstract, they cannot be marked final, • All variables defined in an interface must be public, static, and final. • An interface can extend one or more other interfaces. • An interface cannot implement another interface or class. By Ahmed Ali Ali © 2013 8
  • 9. Declare Class Members •We've looked at what it means to use a modifier in a class declaration, and now we'll look at what it means to modify a method or variable declaration. • Access o o o o • Modifiers public protected default private Nonaccess Member Modifiers o Final and abstract o Synchronized methods By Ahmed Ali Ali © 2013 9
  • 10. Determining Access to Class Member By Ahmed Ali Ali © 2013 10
  • 11. Develop Constructors • The • constructor name must match the name of the class. If you don't type a constructor into your class code, a default constructor will be automatically generated by the compiler. • Constructors must not have a return type. • Constructors can use any access modifier, • Every class, including abstract classes, MUST have a constructor. • constructors are invoked at runtime when you say new on some class. By Ahmed Ali Ali © 2013 11
  • 12. Variable Declarations • There are two types of variables in Java: o Primitives : A primitive can be one of eight types: char, boolean, byte, short, int, long, double, or float. Once a primitive has been declared, its primitive type can never change, although in most cases its value can change. o Reference variables : A reference variable is used to refer to (or access) an object. A reference variable is declared to be of a specific type and that type can never be changed. • Note : o It is legal to declare a local variable with the same name as an instance variable; this is called "shadowing." By Ahmed Ali Ali © 2013 12
  • 13. Variable Scope By Ahmed Ali Ali © 2013 13
  • 14. if and switch Statements • The • only legal expression in an if statement is a boolean expression. Curly braces are optional for if blocks that have only one conditional statement. • switch statements can evaluate only to enums or the byte, short, int, and char data types.You can't say, By Ahmed Ali Ali © 2013 14
  • 15. Ternary (Conditional Operator) Returns one of two values based on whether a boolean expression is true or false. • • Returns the value after the ? if the expression is true. • Returns the value after the : if the expression is false. x = (boolean expression) ? value to assign if true : value to assign if false By Ahmed Ali Ali © 2013 15
  • 16. String Concatenation Operator • If either operand is a String, the + operator concatenates the operands. • If both operands are numeric, the + operator adds the operands. By Ahmed Ali Ali © 2013 16
  • 17. Overloading & Overriding • Abstract methods must be overridden by the first concrete (subclass). • final methods cannot be overridden. • Only inherited methods may be overridden, and remember that private methods are not inherited. •A subclass uses super. overriddenMethodName() to call the superclass version of an overridden method. • Object type (not the reference variable's type), determines which overridden method is used at runtime. By Ahmed Ali Ali © 2013 17
  • 18. Overloading & Overriding (cont’) • Methods from a superclass can be overloaded in a subclass. • constructors can be overloaded but not overridden. • Overloading means reusing a method name, but with different arguments. • Overloaded methods. o Must have different argument lists o May have different return types, if argument lists are also different o May have different access modifiers o May throw different exceptions • Polymorphism applies to overriding, not to overloading. • Reference type determines which overloaded method will be used at compile time. By Ahmed Ali Ali © 2013 18
  • 19. Stack and Heap—Quick Review • understanding the basics of the stack and the heap makes it far easier to understand topics like argument passing, threads, exceptions, • Instance variables and objects live on the heap. • Local variables live on the stack. By Ahmed Ali Ali © 2013 19
  • 20. Wrapper Classes •What’s consept of Wrapper Class ? •The wrapper classes correlate to the primitive types •The three most important method families are o xxxValue() Takes no arguments, returns a primitive o parseXxx() Takes a String, returns a primitive o valueOf() Takes a String, returns a wrapped object By Ahmed Ali Ali © 2013 20
  • 21. Handling Exceptions • The term "exception" means "exceptional condition" and is an occurrence that alters the normal program flow. • Exception handling allows developers to detect errors easily without writing special code to test return values. •A bunch of things can lead to exceptions, including hardware failures, resource exhaustion, and good old bugs. When an exceptional event occurs in Java, an exception is said to be "thrown." The code that's responsible for doing something about the exception is called an "exception handler," and it "catches" the thrown exception. By Ahmed Ali Ali © 2013 21
  • 22. Handling Exceptions (cont’) Example : By Ahmed Ali Ali © 2013 22
  • 23. Assertion Mechanism • the assertion mechanism, added to the language with version 1.4, gives you a way to do testing and debugging checks on conditions you expect to smoke out while developing, • writing code with assert statement will help you to be better programmer and improve quality of code, yes this is true based on my experience when we write code using assert statement we think through hard, we think about possible input to a function, we think about boundary condition which eventually result in better discipline and quality code. "If" is a conditional operator with a specific loop syntax. It can be followed with the loop continuation syntax "else". The "Assert" keyword will throw a run-time error if the condition of the loop returns 'false' and is used for conditional validation(parameter checking). Assertions are mainly used to debug code and are generally removed in a live product. Both "If" & "Assert" evaluate a Boolean condition. • By Ahmed Ali Ali © 2013 23
  • 24. Assertion Mechanism Use assertions for internal logic checks within your code, and normal exceptions for error conditions outside your immediate code's control. Really simple: private void doStuff() { assert (y > x); // more code assuming y //is greater than x } Simple: private void doStuff() { assert (y > x): "y is " + y + " x is " + x; // more code assuming y is greater than x } By Ahmed Ali Ali © 2013 24
  • 25. immutable • an immutable object is an object whose state cannot be modified after it is created •Strings Are Immutable Objects By Ahmed Ali Ali © 2013 25
  • 26. StringBuffer, and StringBuilder • The java.lang.StringBuffer and java.lang.StringBuilder classes should be used when you have to make a lot of modifications to strings of characters • StringBuilder is not thread safe. In other words, its methods are not synchronized. • StringBuilder runs faster. By Ahmed Ali Ali © 2013 26
  • 27. Dates, Numbers, and Currency • Here are the date related classes you'll need to understand. o java.util.Date o java.util.Calendar o java.text.DateFormat o java.text.NumberFormat o java.util.Locale By Ahmed Ali Ali © 2013 27
  • 28. Dates, Numbers, and Currency (cont’) By Ahmed Ali Ali © 2013 28
  • 29. Dates, Numbers, and Currency (cont’) By Ahmed Ali Ali © 2013 29
  • 30. A Search Tutorial • To find specific pieces of data in large data sources, Java provides several mechanisms that use the concepts of regular expressions (Regex). Simple Searches we'd like to search through the following source String (abaaaba) for all occurrences (or matches) of the expression (ab) . • What the result if we search on (aba) inside the String (abababa) ? By Ahmed Ali Ali © 2013 30
  • 31. A Search Tutorial (cont’) [abc] Searches only for a's, b's or c's [a-f] Searches only for a, b, c, d, e, or f characters d A digit s A whitespace character w A word character (letters, digits, or "_" (underscore)) the quantifier that represents "one or more" is the "+" (Ex. d+) Example : source: "a 1 56 _Z" index: 012345678 pattern: w In this case will return positions 0, 2, 4, 5, 7, and 8. By Ahmed Ali Ali © 2013 31
  • 32. Tokenizing • Tokenizing is the process of taking big pieces of source data, breaking them into little pieces, and storing the little pieces in variables. Tokens and Delimiters source: "ab,cd5b,6x,z4" If we say that our delimiter is a comma, then our four tokens would be ab cd5b 6x z4 By Ahmed Ali Ali © 2013 32
  • 33. Tokenizing (cont’) Tokenizing with String.split() By Ahmed Ali Ali © 2013 33
  • 34. Quiz By Ahmed Ali Ali © 2013 34
  • 35. Questions By Ahmed Ali Ali © 2013 35
  • 36. Thanks By Ahmed Ali Ali © 2013 36