SlideShare a Scribd company logo
1 of 30
Download to read offline
Saeid Zebardast 
@saeid 
http://about.me/saeid 
saeid.zebardast@gmail.com 
1
Please Please Please 
Ask Questions 
As Much As You Like 
• This is not a lecture! 
- But an opportunity to learn 
from each other. 
- If you haven’t seen some of 
these frameworks, methods, 
etc. It is OK! 
- Let we know if you know 
‣ Better ways 
‣ Best practices 
‣ My mistakes!
Introduction 
• What’s Java? 
- Since 1995 
- By James Gosling and Sun Microsystems 
‣ Sun acquired by Oracle in 2009/2010, $7.4 billion. 
‣ James Gosling resigned from Oracle (April 2010). 
- Base on C/C++ 
- JVM (Java Virtual Machine) 
• License Issue 
- What’s OpenJDK? 
3
JVM
Java Principles 
1. Simple 
- Syntax is based on C++. 
- No need to remove unreferenced objects. 
2.Secure 
- No explicit pointer. 
- Programs run inside virtual machine sandbox. 
3.Object Oriented 
- Object, Class, Inheritance, Abstraction and etc. 
- Java is pure OOP Language. (C++ is semi object oriented). 
4.Robust 
- Compiler detects many problems. 
- Strong memory management. 
- Lack of pointers that avoids security problem. 
- Automatic garbage collection.
Java Principles 
5.Architecture-neutral 
- Machine independent. 
- Write one, run anywhere. 
6.Portable 
- Java byte codes on any environment and any platform. 
7.High Performance 
- Byte code is "close" to native code. 
- Still somewhat slower than a compiled language (e.g., C++). 
8.Multithreaded 
- Many tasks at once by defining multiple threads. 
9.Distributed 
- URL class allows a Java application to open and access remote objects on the internet.
Java History 
• JDK 1.0 (January 21, 1996) 
• JDK 1.1 (February 19, 1997) 
• J2SE 1.2 (December 8, 1998) 
• J2SE 1.3 (May 8, 2000) 
• J2SE 1.4 (February 6, 2002) 
• J2SE 5.0 (September 30, 2004) 
• Java SE 6 (December 11, 2006) 
• Java SE 7 (July 28, 2011) 
• Java SE 8 (March 18, 2014) 
7
Java Uses 
• Desktop, Web-based and Mobile Apps 
- Android 
- JetBrains IDEs (IntelliJ Idea, CLion and etc.), Eclipse, NetBeans 
- LibreOffice (OpenOffice) 
• Embedded Systems 
- X86, ARM, MIPS, LynxOS, WinCE. 
• Big Data 
- Hadoop (Facebook), Cassandra (Netflix, CERN, Reddit) 
8
Installation 
• Just enter the following command: 
- $ sudo apt-get install openjdk-7-jdk 
• Check Java version: 
- $ java -version 
• Check Java compiler version: 
- $ javac -version 
9
Java Syntax 
• Data Types 
• Variables 
• Operators 
• Statements 
10
Data Types 
• Primitives 
- short, byte, boolean, int and etc. 
• Objects 
- Object, String, Date, Integer, Long and etc. 
11
Primitive Data Types 
Integer 
Type Min Max 2^ 
byte -128 127 2^7 
short -32,768 32,767 2^15 
int -2,147,483,648 2,147,483,647 2^31 
long -9,223,372,036,854,775,808 9,223,372,036,854,775,807 2^63
Primitive Data Types 
Floating-point 
Type Size (bits) Precision 
float 32 From 3.402,823,5 E+38 to 1.4 E-45 
double 64 From 1.797,693,134,862,315,7 E+308 to 4.9 E-324
Primitive Data Types 
Other 
Type Size (bits) Precision 
boolean 1 true, false 
char 16 
All Unicode characters. 
From ‘u0000’ to ‘uFFFF’. 
Check http://unicode-table.com/
Object Data Types 
• Everything is Object! 
- String 
- Date 
- Integer, Long, Double 
- Person, Shape 
- and almost everything. 
15
Variables 
• type identifier [=value]; 
- boolean status; 
- int i = 0; 
- int d = 66, e, f = 1410; 
‣ declare three ints and initialize d and f. 
- String name; 
- Date today = new Date(); 
16
Operators 
Type operators 
Arthimetic +, -, *, /, % 
Assignment +=, =-. *=, /=, %=, = 
Relational !=, ==, <, >, <=, >= 
Logical &&, ||, ! 
Bitwise &, |, ~, ^, <<, >> 
17
Select Statements 
• () ? : ; 
- inline if, shortcut if-else 
• if () {} 
• if () {} else {} 
• if () {} else if {} else {} 
• switch () { 
case X: ; break; 
case Y: ; break; 
default : ; 
} 
18
Iteration Statements 
• while () {} 
• do {} while (); 
• for () {} 
• for (:) {} //foreach 
19
Syntax 
Comments 
• /* This is a multi-line comment. 
It may occupy more than one line. */ 
• // This is an end-of-line comment 
• Java Docs 
• /** 
* This is a documentation comment. 
* 
* @author Saeid Zebardast 
*/
Access modifiers 
Modifier 
Same class or 
nested class 
Other class inside 
the same package 
Extended Class 
inside another 
package 
Non-extended 
inside another 
package 
private yes no no no 
default 
(package private) 
yes yes no no 
protected yes yes yes no 
public yes yes yes yes
Methods 
• [modifiers] return_type method_name([parameterType parameterName, …]) { 
method body; 
[return result] 
} 
• public static void main(String[] args) { 
System.out.println(“Hello World!”); 
// without return! 
} 
• long getMax(int a, int b) { 
if (a > b) 
return a; 
else 
return b; 
}
Classes 
• Top-level class 
- [modifiers] class CLASS_NAME { //the file name should be CLASS_NAME.java 
// Class members (variables, methods, classes) 
} 
• Inner class 
- class Foo { // Top-level class 
class Bar { // Inner class 
} 
} 
• Local class 
- class Foo { 
void bar() { 
class Foobar {// Local class within a method 
} 
} 
} 
• Initialization 
- Foo foo = new Foo();
Inheritance 
• Use extends 
- class Foo { 
// class members 
} 
- class Foobar extends Foo { 
// class members 
} 
• Overriding methods 
- class Operation { 
public int doSomething() { 
return 0; 
} 
} 
- class NewOperation extends Operation { 
@Override 
public int doSomething() { 
return 1; 
} 
}
Interfaces 
• Interface (Animal.java) 
- interface Animal { 
public void eat(); 
public void sleep(); 
} 
• Implements (Cat.java) 
- public class Cat implements Animal{ 
String name; 
public Cat(String name) { 
this.name = name; 
} 
public void eat(){ 
System.out.println(name + “ eats"); 
} 
public void sleep(){ 
System.out.println(name + “sleeps"); 
} 
public String getName(){ 
return name; 
} 
public static void main(String args[]){ 
Cat cat = new Cat(“Barney”); 
cat.eat(); 
cat.sleep(); 
} 
}
Abstract 
Methods and Classes 
• abstract class GraphicObject { 
int x, y; 
... 
void moveTo(int newX, int newY) { 
... 
} 
abstract void draw(); 
abstract void resize(); 
} 
• class Circle extends GraphicObject { 
void draw() { 
... 
} 
void resize() { 
... 
} 
} 
• class Rectangle extends GraphicObject { 
void draw() { 
... 
} 
void resize() { 
... 
} 
}
Java File Structure 
[package _________] // package directory name (com.zebardast.java.tutorials) 
[import _________] 
[import _________] 
[import _________] 
[public] class CLASS_NAME { //File Name should be CLASS_NAME.java 
//class members 
} 
class Foo { 
//class members 
} 
class Bar { 
//class members 
}
Simple Exercise 
Hello Word! 
• Create HelloWorldApp.java: 
- public class HelloWorldApp { 
public static void main(String[] args) { 
System.out.println("Hello World!"); // Print the string to the console. 
} 
} 
• Compile: 
- $ javac HelloWorldApp.java 
• Run: 
- $ java HelloWorldApp 
28
Read The F* Manual 
• RTFM 
- http://docs.oracle.com/javase/ 
• The Really Big Index 
- http://docs.oracle.com/javase/tutorial/ 
reallybigindex.html 
29
Thank You

More Related Content

What's hot

Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Ayes Chinmay
 
Java OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectJava OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectOUM SAOKOSAL
 
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Ayes Chinmay
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Sagar Verma
 
Java ppt Gandhi Ravi (gandhiri@gmail.com)
Java ppt  Gandhi Ravi  (gandhiri@gmail.com)Java ppt  Gandhi Ravi  (gandhiri@gmail.com)
Java ppt Gandhi Ravi (gandhiri@gmail.com)Gandhi Ravi
 
Core java Basics
Core java BasicsCore java Basics
Core java BasicsRAMU KOLLI
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...Sagar Verma
 
XML & XPath Injections
XML & XPath InjectionsXML & XPath Injections
XML & XPath InjectionsAMol NAik
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesGanesh Samarthyam
 

What's hot (20)

Java Programming - 05 access control in java
Java Programming - 05 access control in javaJava Programming - 05 access control in java
Java Programming - 05 access control in java
 
Core java Essentials
Core java EssentialsCore java Essentials
Core java Essentials
 
Java Programming - 03 java control flow
Java Programming - 03 java control flowJava Programming - 03 java control flow
Java Programming - 03 java control flow
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
 
Java OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectJava OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and Object
 
OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
 
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2
 
Java ppt Gandhi Ravi (gandhiri@gmail.com)
Java ppt  Gandhi Ravi  (gandhiri@gmail.com)Java ppt  Gandhi Ravi  (gandhiri@gmail.com)
Java ppt Gandhi Ravi (gandhiri@gmail.com)
 
Core java Basics
Core java BasicsCore java Basics
Core java Basics
 
Oop concepts in python
Oop concepts in pythonOop concepts in python
Oop concepts in python
 
Database programming
Database programmingDatabase programming
Database programming
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
 
XML & XPath Injections
XML & XPath InjectionsXML & XPath Injections
XML & XPath Injections
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java Bytecodes
 
Hacking XPATH 2.0
Hacking XPATH 2.0Hacking XPATH 2.0
Hacking XPATH 2.0
 
Hello Java-First Level
Hello Java-First LevelHello Java-First Level
Hello Java-First Level
 
Hello java
Hello java  Hello java
Hello java
 
55j7
55j755j7
55j7
 

Viewers also liked

Developing Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginnersDeveloping Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginnersSaeid Zebardast
 
Web Components Revolution
Web Components RevolutionWeb Components Revolution
Web Components RevolutionSaeid Zebardast
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointJavaTpoint.Com
 
Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++KurdGul
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners PerlDave Cross
 
Cheat sheet - String Java (Referência rápida)
Cheat sheet - String Java (Referência rápida)Cheat sheet - String Java (Referência rápida)
Cheat sheet - String Java (Referência rápida)Rafael Liberato
 
Java Cheat Sheet
Java Cheat SheetJava Cheat Sheet
Java Cheat SheetGlowTouch
 
Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!
Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!
Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!Noopur Gupta
 
معرفی سیستم‌های توکار در دانشگاه صنعتی شریف
معرفی سیستم‌های توکار در دانشگاه صنعتی شریفمعرفی سیستم‌های توکار در دانشگاه صنعتی شریف
معرفی سیستم‌های توکار در دانشگاه صنعتی شریفnumb95
 

Viewers also liked (20)

Java programming course for beginners
Java programming course for beginnersJava programming course for beginners
Java programming course for beginners
 
Developing Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginnersDeveloping Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginners
 
Web Components Revolution
Web Components RevolutionWeb Components Revolution
Web Components Revolution
 
Java Cheat Sheet
Java Cheat SheetJava Cheat Sheet
Java Cheat Sheet
 
Cheat Sheet java
Cheat Sheet javaCheat Sheet java
Cheat Sheet java
 
Introduction to-programming
Introduction to-programmingIntroduction to-programming
Introduction to-programming
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners Perl
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
What is REST?
What is REST?What is REST?
What is REST?
 
What is good design?
What is good design?What is good design?
What is good design?
 
How to be different?
How to be different?How to be different?
How to be different?
 
MySQL Cheat Sheet
MySQL Cheat SheetMySQL Cheat Sheet
MySQL Cheat Sheet
 
Cheat sheet - String Java (Referência rápida)
Cheat sheet - String Java (Referência rápida)Cheat sheet - String Java (Referência rápida)
Cheat sheet - String Java (Referência rápida)
 
Java Cheat Sheet
Java Cheat SheetJava Cheat Sheet
Java Cheat Sheet
 
Java basic
Java basicJava basic
Java basic
 
Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!
Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!
Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!
 
MySQL for beginners
MySQL for beginnersMySQL for beginners
MySQL for beginners
 
معرفی سیستم‌های توکار در دانشگاه صنعتی شریف
معرفی سیستم‌های توکار در دانشگاه صنعتی شریفمعرفی سیستم‌های توکار در دانشگاه صنعتی شریف
معرفی سیستم‌های توکار در دانشگاه صنعتی شریف
 

Similar to Java for beginners

Similar to Java for beginners (20)

Cse java
Cse javaCse java
Cse java
 
L04 Software Design 2
L04 Software Design 2L04 Software Design 2
L04 Software Design 2
 
04 Java Language And OOP Part IV
04 Java Language And OOP Part IV04 Java Language And OOP Part IV
04 Java Language And OOP Part IV
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
55 New Features in Java 7
55 New Features in Java 755 New Features in Java 7
55 New Features in Java 7
 
java training faridabad
java training faridabadjava training faridabad
java training faridabad
 
Java - A broad introduction
Java - A broad introductionJava - A broad introduction
Java - A broad introduction
 
Java
JavaJava
Java
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorial
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Programming in java basics
Programming in java  basicsProgramming in java  basics
Programming in java basics
 
SenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don GriffinSenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
 
Java Tutorials
Java Tutorials Java Tutorials
Java Tutorials
 
4java Basic Syntax
4java Basic Syntax4java Basic Syntax
4java Basic Syntax
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Java
Java Java
Java
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast Lane
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
RIBBUN SOFTWARE
RIBBUN SOFTWARERIBBUN SOFTWARE
RIBBUN SOFTWARE
 
Java01
Java01Java01
Java01
 

Recently uploaded

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Recently uploaded (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

Java for beginners

  • 1. Saeid Zebardast @saeid http://about.me/saeid saeid.zebardast@gmail.com 1
  • 2. Please Please Please Ask Questions As Much As You Like • This is not a lecture! - But an opportunity to learn from each other. - If you haven’t seen some of these frameworks, methods, etc. It is OK! - Let we know if you know ‣ Better ways ‣ Best practices ‣ My mistakes!
  • 3. Introduction • What’s Java? - Since 1995 - By James Gosling and Sun Microsystems ‣ Sun acquired by Oracle in 2009/2010, $7.4 billion. ‣ James Gosling resigned from Oracle (April 2010). - Base on C/C++ - JVM (Java Virtual Machine) • License Issue - What’s OpenJDK? 3
  • 4. JVM
  • 5. Java Principles 1. Simple - Syntax is based on C++. - No need to remove unreferenced objects. 2.Secure - No explicit pointer. - Programs run inside virtual machine sandbox. 3.Object Oriented - Object, Class, Inheritance, Abstraction and etc. - Java is pure OOP Language. (C++ is semi object oriented). 4.Robust - Compiler detects many problems. - Strong memory management. - Lack of pointers that avoids security problem. - Automatic garbage collection.
  • 6. Java Principles 5.Architecture-neutral - Machine independent. - Write one, run anywhere. 6.Portable - Java byte codes on any environment and any platform. 7.High Performance - Byte code is "close" to native code. - Still somewhat slower than a compiled language (e.g., C++). 8.Multithreaded - Many tasks at once by defining multiple threads. 9.Distributed - URL class allows a Java application to open and access remote objects on the internet.
  • 7. Java History • JDK 1.0 (January 21, 1996) • JDK 1.1 (February 19, 1997) • J2SE 1.2 (December 8, 1998) • J2SE 1.3 (May 8, 2000) • J2SE 1.4 (February 6, 2002) • J2SE 5.0 (September 30, 2004) • Java SE 6 (December 11, 2006) • Java SE 7 (July 28, 2011) • Java SE 8 (March 18, 2014) 7
  • 8. Java Uses • Desktop, Web-based and Mobile Apps - Android - JetBrains IDEs (IntelliJ Idea, CLion and etc.), Eclipse, NetBeans - LibreOffice (OpenOffice) • Embedded Systems - X86, ARM, MIPS, LynxOS, WinCE. • Big Data - Hadoop (Facebook), Cassandra (Netflix, CERN, Reddit) 8
  • 9. Installation • Just enter the following command: - $ sudo apt-get install openjdk-7-jdk • Check Java version: - $ java -version • Check Java compiler version: - $ javac -version 9
  • 10. Java Syntax • Data Types • Variables • Operators • Statements 10
  • 11. Data Types • Primitives - short, byte, boolean, int and etc. • Objects - Object, String, Date, Integer, Long and etc. 11
  • 12. Primitive Data Types Integer Type Min Max 2^ byte -128 127 2^7 short -32,768 32,767 2^15 int -2,147,483,648 2,147,483,647 2^31 long -9,223,372,036,854,775,808 9,223,372,036,854,775,807 2^63
  • 13. Primitive Data Types Floating-point Type Size (bits) Precision float 32 From 3.402,823,5 E+38 to 1.4 E-45 double 64 From 1.797,693,134,862,315,7 E+308 to 4.9 E-324
  • 14. Primitive Data Types Other Type Size (bits) Precision boolean 1 true, false char 16 All Unicode characters. From ‘u0000’ to ‘uFFFF’. Check http://unicode-table.com/
  • 15. Object Data Types • Everything is Object! - String - Date - Integer, Long, Double - Person, Shape - and almost everything. 15
  • 16. Variables • type identifier [=value]; - boolean status; - int i = 0; - int d = 66, e, f = 1410; ‣ declare three ints and initialize d and f. - String name; - Date today = new Date(); 16
  • 17. Operators Type operators Arthimetic +, -, *, /, % Assignment +=, =-. *=, /=, %=, = Relational !=, ==, <, >, <=, >= Logical &&, ||, ! Bitwise &, |, ~, ^, <<, >> 17
  • 18. Select Statements • () ? : ; - inline if, shortcut if-else • if () {} • if () {} else {} • if () {} else if {} else {} • switch () { case X: ; break; case Y: ; break; default : ; } 18
  • 19. Iteration Statements • while () {} • do {} while (); • for () {} • for (:) {} //foreach 19
  • 20. Syntax Comments • /* This is a multi-line comment. It may occupy more than one line. */ • // This is an end-of-line comment • Java Docs • /** * This is a documentation comment. * * @author Saeid Zebardast */
  • 21. Access modifiers Modifier Same class or nested class Other class inside the same package Extended Class inside another package Non-extended inside another package private yes no no no default (package private) yes yes no no protected yes yes yes no public yes yes yes yes
  • 22. Methods • [modifiers] return_type method_name([parameterType parameterName, …]) { method body; [return result] } • public static void main(String[] args) { System.out.println(“Hello World!”); // without return! } • long getMax(int a, int b) { if (a > b) return a; else return b; }
  • 23. Classes • Top-level class - [modifiers] class CLASS_NAME { //the file name should be CLASS_NAME.java // Class members (variables, methods, classes) } • Inner class - class Foo { // Top-level class class Bar { // Inner class } } • Local class - class Foo { void bar() { class Foobar {// Local class within a method } } } • Initialization - Foo foo = new Foo();
  • 24. Inheritance • Use extends - class Foo { // class members } - class Foobar extends Foo { // class members } • Overriding methods - class Operation { public int doSomething() { return 0; } } - class NewOperation extends Operation { @Override public int doSomething() { return 1; } }
  • 25. Interfaces • Interface (Animal.java) - interface Animal { public void eat(); public void sleep(); } • Implements (Cat.java) - public class Cat implements Animal{ String name; public Cat(String name) { this.name = name; } public void eat(){ System.out.println(name + “ eats"); } public void sleep(){ System.out.println(name + “sleeps"); } public String getName(){ return name; } public static void main(String args[]){ Cat cat = new Cat(“Barney”); cat.eat(); cat.sleep(); } }
  • 26. Abstract Methods and Classes • abstract class GraphicObject { int x, y; ... void moveTo(int newX, int newY) { ... } abstract void draw(); abstract void resize(); } • class Circle extends GraphicObject { void draw() { ... } void resize() { ... } } • class Rectangle extends GraphicObject { void draw() { ... } void resize() { ... } }
  • 27. Java File Structure [package _________] // package directory name (com.zebardast.java.tutorials) [import _________] [import _________] [import _________] [public] class CLASS_NAME { //File Name should be CLASS_NAME.java //class members } class Foo { //class members } class Bar { //class members }
  • 28. Simple Exercise Hello Word! • Create HelloWorldApp.java: - public class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); // Print the string to the console. } } • Compile: - $ javac HelloWorldApp.java • Run: - $ java HelloWorldApp 28
  • 29. Read The F* Manual • RTFM - http://docs.oracle.com/javase/ • The Really Big Index - http://docs.oracle.com/javase/tutorial/ reallybigindex.html 29