SlideShare a Scribd company logo
1 of 78
Java 101: Intro to Java
Programming
Introduction
• Your Name
• Your day job
• Your last holiday destination?
Java 101
• Java Fundamentals
– Setting up your development environment
– Language Overview
– How Java Works
– Writing your first program
– Built-in Data Types
– Conditionals and Loops
Java 102
• Object-oriented Programming
– Classes and Objects
– Polymorphism, Inheritance and Encapsulation
– Functions and Libraries
Java 103
• Data Structures
– Arrays
– Collections
– Algorithms
Java 101: Introduction to Java
Setting up your Development
Environment
Installing Java Development Kit
• Download latest Java SE 8 JDK (not JRE) from
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-
downloads-2133151.html
• For Windows,
– download the X86 version, double click the .exe file and follow the
instructions, accepting all default
• For MACs,
– check if java already installed (javac –version) and if not, download the
JDK dmg file, run it and follow the instructions.
• After installation is complete, type javac –version in the Command
window (Terminal window on MAC OS)-
– The reported version should be 1.8....
– If not, you may need to modify the system variable PATH to include the
bin directory of JDK
What is an IDE?
• IDE = Integrated Development Environment
• Makes you more productive
• Includes text editor, compiler, debugger,
context- sensitive help, works with different
Java SDKs
• Eclipse is the most widely used IDE
• Alternatives:
– IntelliJ IDEA (JetBrains)
– NetBeans (Oracle)
Installing Eclipse
• Download and install the latest Eclipse for Java
EE (32 Bit version) from
http://www.eclipse.org/downloads
• Unzip the content of the archive file you
downloaded
• To start Eclipse
– On PC, double-click on Eclipse.exe
– On Mac, double click Eclipse.app in Application
folder
Hands-on Exercise
Eclipse Setup & Demo
Java 101: Introduction to Java
Language Overview
Java Language Overview
• Object-oriented
• Statically typed
• Widely available
• Widely used
Java Versions
• Brief History…
– 1990 : Small team at Sun
Microsystems start work on
C/C++ replacement
• Major Version Releases
– 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)
Java Editions
• Java SE: Java Standard Edition
• Java EE: Java Enterprise Edition (a.k.a. J2EE)
– includes a set of technologies built on top of Java
SE: Servlets, JSP, JSF, EJB, JMS, et al.
• Java ME: Java Micro Edition
• Java Card for Smart Cards
• All Java programs run inside the Java Virtual
Machine (JVM)
JDK vs. JRE
• Java Development Kit (JDK) is required to
develop and compile programs
• Java Runtime Environment (JRE) is required to
run programs.
• Users must have JRE installed,
• Developers must have the JDK installed
• JDK includes the JRE
Java 101: Introduction to Java
How Java Works
How Java Works
Java File Structure
Java 101: Introduction to Java
Writing Your First Program
Hello, World!
Writing Your First Java Program
• Create a new project in your IDE named Java101
• Create a HelloWorld class in the src folder inside the Java101
project as illustrated below.
Compiling Your First Java Program
• Save the HelloWorld class in the IDE
• This automatically compiles the HelloWorld.java file
into into a HelloWorld.class file
• Go to the folder you created the Java101 project on
your hard disk and open the src folder.
• What do you see?
Running Your First Java Program
• Run your program in Eclipse by right-clicking
and selecting Run As>Java Application.
Anatomy of a Java Application
Comments Class Name
Access
modifier
Function/static
method
Arguments
Language Features
Introduction to Java
Built-in Data Types
Built-in Data Types
• Data type are sets of values and operations
defined on those values.
Basic Definitions
• Variable - a name that refers to a value.
• Assignment statement - associates a value
with a variable.
String Data Type
Data Type Attributes
Values sequence of characters
Typical literals “Hello”, “1 “, “*”
Operation Concatenate
Operator +
• Useful for program input and output.
String Data Type
String Data Type
• Meaning of characters depends on context.
String Data Type
Expression Value
“Hi, “ + “Bob” “Hi, Bob”
“1” + “ 2 “ + “ 1” “ 1 2 1”
“1234” + “ + “ + “99” “1234 + 99”
“1234” + “99” “123499”
Hands-on Exercise
Command Line Arguments
Exercise: Command Line Arguments
• Create the Java program below that takes a name as command-line
argument and prints “Hi <name>, How are you?”
Integer Data Type
Data Type Attributes
Values Integers between -2E31 to +2E31-1
Typical literals 1234, -99 , 99, 0, 1000000
Operation Add subtract multiply divide remainder
Operator + - * / %
• Useful for expressing algorithms.
Integer Data Type
Expression Value Comment
5 + 3 8
5 – 3 2
5 * 3 15
5 / 3 1 no fractional
part
5 % 3 2 remainder
1 / 0 run-time error
3 * 5 - 2 13 * has
precedence
3 + 5 / 2 5 / has
precedence
3 – 5 - 2 -4 left associative
(3-5) - 2 -4 better style
3 – (5-2) 0 unambiguous
Double Data Type
• Useful in scientific applications and floating-
point arithmetic
Data Type Attributes
Values Real numbers specified by the IEEE 754 standard
Typical literals 3.14159 6.022e23 -3.0 2.0 1.41421356237209
Operation Add subtract multiply divide
Operator + - * /
Double Data Type
Expression Value
3.141 + 0.03 3.171
3.141 – 0.03 3.111
6.02e23 / 2 3.01e23
5.0 / 2.0 1.6666666666667
10.0 % 3.141 0.577
1.0 / 0.0 Infinity
Math.sqrt(2.0) 1.4142135623730951
Java Math Library
Methods
Math.sin() Math.cos()
Math.log() Math.exp()
Math.sqrt() Math.pow()
Math.min() Math.max()
Math.abs() Math.PI
http://java.sun.com/javase/6/docs/api/java/lang/Math.html
Hands-on Exercise
Integer Operations
Exercise: Integer Operations
• Create a Java class named IntOpsin the Java101 project that performs integer
operations on a pair of integers from the command line and prints the results.
Solution: Integer Operations
Boolean Data Type
• Useful to control logic and flow of a program.
Data Type Attributes
Values true or false
Typical literals true false
Operation and or not
Operator && || !
Truth-table of Boolean Operations
a !a a b a && b a || b
true false false false false false
false true false true false true
true false false true
true true true true
Boolean Comparisons
• Take operands of one type and produce an
operand of type boolean.
operation meaning true false
== equals 2 == 2 2 == 3
!= Not equals 3 != 2 2 != 2
< Less than 2 < 13 2 < 2
<= Less than or
equal
2 <= 2 3 <= 2
> Greater than 13 > 2 2 > 13
>= Greater than
or equal
3 >= 2 2 >= 3
Type Conversion
• Convert from one type of data to another.
• Implicit
– no loss of precision
– with strings
• Explicit:
– cast
– method.
Type Conversion Examples
expression Expression type Expression value
“1234” + 99 String “123499”
Integer.parseInt(“123”) int 123
(int) 2.71828 int 2
Math.round(2.71828) long 3
(int) Math.round(2.71828) int 3
(int) Math.round(3.14159) int 3
11 * 0.3 double 3.3
(int) 11 * 0.3 double 3.3
11 * (int) 0.3 int 0
(int) (11 * 0.3) int 3
Hands-on Exercise
Leap Year Finder
Exercise: Leap Year Finder
• A year is a leap year if it is either divisible by 400
or divisible by 4 but not 100.
• Write a java class named LeapYear in the Java101
project that takes a numeric year as command
line argument and prints true if it’s a leap year
and false if not
Solution: Leap Year Finder
Data Types Summary
• A data type is a set of values and operations on those
values.
– String for text processing
– double, int for mathematical calculation
– boolean for decision making
• In Java, you must:
– Declare type of values.
– Convert between types when necessary
• Why do we need types?
– Type conversion must be done at some level.
– Compiler can help do it correctly.
– Example: in 1996, Ariane 5 rocket exploded after takeoff
because of bad type conversion.
Introduction to Java
Conditionals and Loops
Conditionals and Loops
• Sequence of statements that are actually
executed in a program.
• Enable us to choreograph control flow.
Conditionals
• The if statement is a common branching structure.
– Evaluate a boolean expression.
• If true, execute some statements.
• If false, execute other statements.
If Statement Example
More If Statement Examples
While Loop
• A common repetition structure.
– Evaluate a boolean expression.
– If true, execute some statements.
– Repeat.
For Loop
• Another common repetition structure.
– Execute initialization statement.
– Evaluate a boolean expression.
• If true, execute some statements.
– And then the increment statement.
– Repeat.
Anatomy of a For Loop
Loop Examples
For Loop
Hands-on Exercise
Powers of Two
Exercise: Powers of Two
• Create a new Java project in Eclipse named Pow2
• Write a java class named PowerOfTwo to print powers of 2 that are
<= 2N where N is a number passed as an argument to the program.
– Increment i from 0 to N.
– Double v each time
Solution: Power of 2
Control Flow Summary
• Sequence of statements that are actually
executed in a program.
• Conditionals and loops enable us to choreograph
the control flow.
Control flow Description Example
Straight line
programs
all statements are executed in the
order given
Conditionals certain statements are executed
depending on the values of certain
variables
If
If-else
Loops certain statements are executed
repeatedly until certain conditions
are met
while
for
do-while
Homework Exercises
Java 101: Introduction to Java
Hands-on Exercise
Random Number Generator
Exercise: Random Number Generator
• Write a java class named RandomInt to generate a
pseudo-random number between 0 and N-1 where N is
a number passed as an argument to the program
Solution: Random Number Generator
Hands-on Exercise
Array of Days
Exercise: Array of Days
• Create a java class named DayPrinter that
prints out names of the days in a week from an
array using a for-loop.
Solution: Arrays of Days
public class DayPrinter {
public static void main(String[] args) {
//initialize the array with the names of days of the
week
String[] daysOfTheWeek =
{"Sunday","Monday","Tuesday","Wednesday",
"Thuesday","Friday”,"Saturday"};
//loop through the array and print their elements to
//stdout
for (int i= 0;i < daysOfTheWeek.length;i++ ){
System.out.println(daysOfTheWeek[i]);
}
}
}
% javac DayPrinter.java
% java DayPrinter
Sunday
Monday
Tuesday
Wednesday
Thuesday
Friday
Saturday
Hands-on Exercise
Print Personal Details
Exercise: Print Personal Details
• Write a program that will print your name and
address to the console, for example:
Alex Johnson
23 Main Street
New York, NY 10001 USA
Hands-on Exercise
Sales Discount
Exercise: Sales Discount
• Create a new project in Eclipse named Sale
• Create, compile, and run the FriendsAndFamily class as illustrated below
• Debug this program in your IDE to find out how it works
Further Reading
• Java Tutorials - https://docs.oracle.com/javase/tutorial/
• Java Language Basics -
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/index.html
• Eclipse IDE Workbench User Guide -
http://help.eclipse.org/kepler/index.jsp
• Eclipse Tutorial - http://www.vogella.com/tutorials/Eclipse/article.html

More Related Content

What's hot

Java 9 Module System Introduction
Java 9 Module System IntroductionJava 9 Module System Introduction
Java 9 Module System IntroductionDan Stine
 
Explore the history, versions and features of Java- a report by Pranav Mishra
Explore the history, versions and features of Java- a report by Pranav MishraExplore the history, versions and features of Java- a report by Pranav Mishra
Explore the history, versions and features of Java- a report by Pranav MishraSopra Steria India
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introductionjyoti_lakhani
 
Java Presentation
Java PresentationJava Presentation
Java PresentationAmr Salah
 
Runnable interface.34
Runnable interface.34Runnable interface.34
Runnable interface.34myrajendra
 
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Luzan Baral
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Languagejaimefrozr
 
Visula C# Programming Lecture 1
Visula C# Programming Lecture 1Visula C# Programming Lecture 1
Visula C# Programming Lecture 1Abou Bakr Ashraf
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Javaparag
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming languageMd.Al-imran Roton
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in javaPratik Soares
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingMd. Tanvir Hossain
 

What's hot (20)

Java 9 Module System Introduction
Java 9 Module System IntroductionJava 9 Module System Introduction
Java 9 Module System Introduction
 
Explore the history, versions and features of Java- a report by Pranav Mishra
Explore the history, versions and features of Java- a report by Pranav MishraExplore the history, versions and features of Java- a report by Pranav Mishra
Explore the history, versions and features of Java- a report by Pranav Mishra
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 
Introduction of java
Introduction  of javaIntroduction  of java
Introduction of java
 
Core java
Core javaCore java
Core java
 
.Net framework
.Net framework.Net framework
.Net framework
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
Control statements in java programmng
Control statements in java programmngControl statements in java programmng
Control statements in java programmng
 
C#.NET
C#.NETC#.NET
C#.NET
 
Runnable interface.34
Runnable interface.34Runnable interface.34
Runnable interface.34
 
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Language
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Visula C# Programming Lecture 1
Visula C# Programming Lecture 1Visula C# Programming Lecture 1
Visula C# Programming Lecture 1
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
 
Java PPT
Java PPTJava PPT
Java PPT
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented Programming
 
Java Object Oriented Programming
Java Object Oriented Programming Java Object Oriented Programming
Java Object Oriented Programming
 

Viewers also liked

Java 101 Intro to Java Programming - Exercises
Java 101   Intro to Java Programming - ExercisesJava 101   Intro to Java Programming - Exercises
Java 101 Intro to Java Programming - Exercisesagorolabs
 
Software para diagnostico, optimización y utilerias
Software para diagnostico, optimización y utileriasSoftware para diagnostico, optimización y utilerias
Software para diagnostico, optimización y utileriasxnoxtrax
 
Intro to Java for C++ Developers
Intro to Java for C++ DevelopersIntro to Java for C++ Developers
Intro to Java for C++ DevelopersZachary Blair
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variablesteach4uin
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java Ahmad Idrees
 
Introduction to Agile & Scrum
Introduction to Agile & ScrumIntroduction to Agile & Scrum
Introduction to Agile & ScrumHawkman Academy
 

Viewers also liked (20)

Java notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esectionJava notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esection
 
Java 101 Intro to Java Programming - Exercises
Java 101   Intro to Java Programming - ExercisesJava 101   Intro to Java Programming - Exercises
Java 101 Intro to Java Programming - Exercises
 
Java principles
Java principlesJava principles
Java principles
 
Java 101
Java 101Java 101
Java 101
 
Software para diagnostico, optimización y utilerias
Software para diagnostico, optimización y utileriasSoftware para diagnostico, optimización y utilerias
Software para diagnostico, optimización y utilerias
 
Java Class Loader
Java Class LoaderJava Class Loader
Java Class Loader
 
Intro to Java
Intro to JavaIntro to Java
Intro to Java
 
Intro to Java for C++ Developers
Intro to Java for C++ DevelopersIntro to Java for C++ Developers
Intro to Java for C++ Developers
 
Java Intro
Java IntroJava Intro
Java Intro
 
Intro to Java Technology
Intro to Java TechnologyIntro to Java Technology
Intro to Java Technology
 
Java
JavaJava
Java
 
Presentation
PresentationPresentation
Presentation
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java
 
Java tutorial PPT
Java tutorial  PPTJava tutorial  PPT
Java tutorial PPT
 
Introduction to Agile & Scrum
Introduction to Agile & ScrumIntroduction to Agile & Scrum
Introduction to Agile & Scrum
 
Java Datatypes
Java DatatypesJava Datatypes
Java Datatypes
 
Java features
Java featuresJava features
Java features
 
Introduction to DevOps
Introduction to DevOpsIntroduction to DevOps
Introduction to DevOps
 

Similar to Java 101: Intro to Java Programming Language Overview

Similar to Java 101: Intro to Java Programming Language Overview (20)

Java 101
Java 101Java 101
Java 101
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 
Programming in java basics
Programming in java  basicsProgramming in java  basics
Programming in java basics
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
 
Session 1 of programming
Session 1 of programmingSession 1 of programming
Session 1 of programming
 
Unit 1
Unit 1Unit 1
Unit 1
 
Java for android developers
Java for android developersJava for android developers
Java for android developers
 
Scala Days NYC 2016
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016
 
Java
Java Java
Java
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
 
Scala-Ls1
Scala-Ls1Scala-Ls1
Scala-Ls1
 
Java basic
Java basicJava basic
Java basic
 
ITFT - Java Coding
ITFT - Java CodingITFT - Java Coding
ITFT - Java Coding
 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
 
java slides
java slidesjava slides
java slides
 
Java Review
Java ReviewJava Review
Java Review
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 

More from Hawkman Academy

What is the secret to great Agile leadership?
What is the secret to great Agile leadership?What is the secret to great Agile leadership?
What is the secret to great Agile leadership?Hawkman Academy
 
Intro to software development
Intro to software developmentIntro to software development
Intro to software developmentHawkman Academy
 
Software Testing Overview
Software Testing OverviewSoftware Testing Overview
Software Testing OverviewHawkman Academy
 
Agile Requirements Discovery
Agile Requirements DiscoveryAgile Requirements Discovery
Agile Requirements DiscoveryHawkman Academy
 
Design 101 : Beyond ideation - Transforming Ideas to Software Requirements
Design 101 : Beyond ideation - Transforming Ideas to Software RequirementsDesign 101 : Beyond ideation - Transforming Ideas to Software Requirements
Design 101 : Beyond ideation - Transforming Ideas to Software RequirementsHawkman Academy
 

More from Hawkman Academy (9)

What is the secret to great Agile leadership?
What is the secret to great Agile leadership?What is the secret to great Agile leadership?
What is the secret to great Agile leadership?
 
Agile Retrospectives
Agile RetrospectivesAgile Retrospectives
Agile Retrospectives
 
Web 102 INtro to CSS
Web 102  INtro to CSSWeb 102  INtro to CSS
Web 102 INtro to CSS
 
Web 101 intro to html
Web 101  intro to htmlWeb 101  intro to html
Web 101 intro to html
 
Intro to software development
Intro to software developmentIntro to software development
Intro to software development
 
Software Testing Overview
Software Testing OverviewSoftware Testing Overview
Software Testing Overview
 
Introduction to Agile
Introduction to AgileIntroduction to Agile
Introduction to Agile
 
Agile Requirements Discovery
Agile Requirements DiscoveryAgile Requirements Discovery
Agile Requirements Discovery
 
Design 101 : Beyond ideation - Transforming Ideas to Software Requirements
Design 101 : Beyond ideation - Transforming Ideas to Software RequirementsDesign 101 : Beyond ideation - Transforming Ideas to Software Requirements
Design 101 : Beyond ideation - Transforming Ideas to Software Requirements
 

Recently uploaded

Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 

Recently uploaded (20)

Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 

Java 101: Intro to Java Programming Language Overview

  • 1. Java 101: Intro to Java Programming
  • 2. Introduction • Your Name • Your day job • Your last holiday destination?
  • 3. Java 101 • Java Fundamentals – Setting up your development environment – Language Overview – How Java Works – Writing your first program – Built-in Data Types – Conditionals and Loops
  • 4. Java 102 • Object-oriented Programming – Classes and Objects – Polymorphism, Inheritance and Encapsulation – Functions and Libraries
  • 5. Java 103 • Data Structures – Arrays – Collections – Algorithms
  • 6. Java 101: Introduction to Java Setting up your Development Environment
  • 7. Installing Java Development Kit • Download latest Java SE 8 JDK (not JRE) from http://www.oracle.com/technetwork/java/javase/downloads/jdk8- downloads-2133151.html • For Windows, – download the X86 version, double click the .exe file and follow the instructions, accepting all default • For MACs, – check if java already installed (javac –version) and if not, download the JDK dmg file, run it and follow the instructions. • After installation is complete, type javac –version in the Command window (Terminal window on MAC OS)- – The reported version should be 1.8.... – If not, you may need to modify the system variable PATH to include the bin directory of JDK
  • 8. What is an IDE? • IDE = Integrated Development Environment • Makes you more productive • Includes text editor, compiler, debugger, context- sensitive help, works with different Java SDKs • Eclipse is the most widely used IDE • Alternatives: – IntelliJ IDEA (JetBrains) – NetBeans (Oracle)
  • 9. Installing Eclipse • Download and install the latest Eclipse for Java EE (32 Bit version) from http://www.eclipse.org/downloads • Unzip the content of the archive file you downloaded • To start Eclipse – On PC, double-click on Eclipse.exe – On Mac, double click Eclipse.app in Application folder
  • 11. Java 101: Introduction to Java Language Overview
  • 12. Java Language Overview • Object-oriented • Statically typed • Widely available • Widely used
  • 13. Java Versions • Brief History… – 1990 : Small team at Sun Microsystems start work on C/C++ replacement • Major Version Releases – 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)
  • 14. Java Editions • Java SE: Java Standard Edition • Java EE: Java Enterprise Edition (a.k.a. J2EE) – includes a set of technologies built on top of Java SE: Servlets, JSP, JSF, EJB, JMS, et al. • Java ME: Java Micro Edition • Java Card for Smart Cards • All Java programs run inside the Java Virtual Machine (JVM)
  • 15. JDK vs. JRE • Java Development Kit (JDK) is required to develop and compile programs • Java Runtime Environment (JRE) is required to run programs. • Users must have JRE installed, • Developers must have the JDK installed • JDK includes the JRE
  • 16. Java 101: Introduction to Java How Java Works
  • 19. Java 101: Introduction to Java Writing Your First Program
  • 21. Writing Your First Java Program • Create a new project in your IDE named Java101 • Create a HelloWorld class in the src folder inside the Java101 project as illustrated below.
  • 22. Compiling Your First Java Program • Save the HelloWorld class in the IDE • This automatically compiles the HelloWorld.java file into into a HelloWorld.class file • Go to the folder you created the Java101 project on your hard disk and open the src folder. • What do you see?
  • 23. Running Your First Java Program • Run your program in Eclipse by right-clicking and selecting Run As>Java Application.
  • 24.
  • 25. Anatomy of a Java Application Comments Class Name Access modifier Function/static method Arguments
  • 28. Built-in Data Types • Data type are sets of values and operations defined on those values.
  • 29. Basic Definitions • Variable - a name that refers to a value. • Assignment statement - associates a value with a variable.
  • 30. String Data Type Data Type Attributes Values sequence of characters Typical literals “Hello”, “1 “, “*” Operation Concatenate Operator + • Useful for program input and output.
  • 32. String Data Type • Meaning of characters depends on context.
  • 33. String Data Type Expression Value “Hi, “ + “Bob” “Hi, Bob” “1” + “ 2 “ + “ 1” “ 1 2 1” “1234” + “ + “ + “99” “1234 + 99” “1234” + “99” “123499”
  • 35. Exercise: Command Line Arguments • Create the Java program below that takes a name as command-line argument and prints “Hi <name>, How are you?”
  • 36. Integer Data Type Data Type Attributes Values Integers between -2E31 to +2E31-1 Typical literals 1234, -99 , 99, 0, 1000000 Operation Add subtract multiply divide remainder Operator + - * / % • Useful for expressing algorithms.
  • 37. Integer Data Type Expression Value Comment 5 + 3 8 5 – 3 2 5 * 3 15 5 / 3 1 no fractional part 5 % 3 2 remainder 1 / 0 run-time error 3 * 5 - 2 13 * has precedence 3 + 5 / 2 5 / has precedence 3 – 5 - 2 -4 left associative (3-5) - 2 -4 better style 3 – (5-2) 0 unambiguous
  • 38. Double Data Type • Useful in scientific applications and floating- point arithmetic Data Type Attributes Values Real numbers specified by the IEEE 754 standard Typical literals 3.14159 6.022e23 -3.0 2.0 1.41421356237209 Operation Add subtract multiply divide Operator + - * /
  • 39. Double Data Type Expression Value 3.141 + 0.03 3.171 3.141 – 0.03 3.111 6.02e23 / 2 3.01e23 5.0 / 2.0 1.6666666666667 10.0 % 3.141 0.577 1.0 / 0.0 Infinity Math.sqrt(2.0) 1.4142135623730951
  • 40. Java Math Library Methods Math.sin() Math.cos() Math.log() Math.exp() Math.sqrt() Math.pow() Math.min() Math.max() Math.abs() Math.PI http://java.sun.com/javase/6/docs/api/java/lang/Math.html
  • 42. Exercise: Integer Operations • Create a Java class named IntOpsin the Java101 project that performs integer operations on a pair of integers from the command line and prints the results.
  • 44. Boolean Data Type • Useful to control logic and flow of a program. Data Type Attributes Values true or false Typical literals true false Operation and or not Operator && || !
  • 45. Truth-table of Boolean Operations a !a a b a && b a || b true false false false false false false true false true false true true false false true true true true true
  • 46. Boolean Comparisons • Take operands of one type and produce an operand of type boolean. operation meaning true false == equals 2 == 2 2 == 3 != Not equals 3 != 2 2 != 2 < Less than 2 < 13 2 < 2 <= Less than or equal 2 <= 2 3 <= 2 > Greater than 13 > 2 2 > 13 >= Greater than or equal 3 >= 2 2 >= 3
  • 47. Type Conversion • Convert from one type of data to another. • Implicit – no loss of precision – with strings • Explicit: – cast – method.
  • 48. Type Conversion Examples expression Expression type Expression value “1234” + 99 String “123499” Integer.parseInt(“123”) int 123 (int) 2.71828 int 2 Math.round(2.71828) long 3 (int) Math.round(2.71828) int 3 (int) Math.round(3.14159) int 3 11 * 0.3 double 3.3 (int) 11 * 0.3 double 3.3 11 * (int) 0.3 int 0 (int) (11 * 0.3) int 3
  • 50. Exercise: Leap Year Finder • A year is a leap year if it is either divisible by 400 or divisible by 4 but not 100. • Write a java class named LeapYear in the Java101 project that takes a numeric year as command line argument and prints true if it’s a leap year and false if not
  • 52. Data Types Summary • A data type is a set of values and operations on those values. – String for text processing – double, int for mathematical calculation – boolean for decision making • In Java, you must: – Declare type of values. – Convert between types when necessary • Why do we need types? – Type conversion must be done at some level. – Compiler can help do it correctly. – Example: in 1996, Ariane 5 rocket exploded after takeoff because of bad type conversion.
  • 54. Conditionals and Loops • Sequence of statements that are actually executed in a program. • Enable us to choreograph control flow.
  • 55. Conditionals • The if statement is a common branching structure. – Evaluate a boolean expression. • If true, execute some statements. • If false, execute other statements.
  • 57. More If Statement Examples
  • 58. While Loop • A common repetition structure. – Evaluate a boolean expression. – If true, execute some statements. – Repeat.
  • 59. For Loop • Another common repetition structure. – Execute initialization statement. – Evaluate a boolean expression. • If true, execute some statements. – And then the increment statement. – Repeat.
  • 60. Anatomy of a For Loop
  • 64. Exercise: Powers of Two • Create a new Java project in Eclipse named Pow2 • Write a java class named PowerOfTwo to print powers of 2 that are <= 2N where N is a number passed as an argument to the program. – Increment i from 0 to N. – Double v each time
  • 66. Control Flow Summary • Sequence of statements that are actually executed in a program. • Conditionals and loops enable us to choreograph the control flow. Control flow Description Example Straight line programs all statements are executed in the order given Conditionals certain statements are executed depending on the values of certain variables If If-else Loops certain statements are executed repeatedly until certain conditions are met while for do-while
  • 67. Homework Exercises Java 101: Introduction to Java
  • 69. Exercise: Random Number Generator • Write a java class named RandomInt to generate a pseudo-random number between 0 and N-1 where N is a number passed as an argument to the program
  • 72. Exercise: Array of Days • Create a java class named DayPrinter that prints out names of the days in a week from an array using a for-loop.
  • 73. Solution: Arrays of Days public class DayPrinter { public static void main(String[] args) { //initialize the array with the names of days of the week String[] daysOfTheWeek = {"Sunday","Monday","Tuesday","Wednesday", "Thuesday","Friday”,"Saturday"}; //loop through the array and print their elements to //stdout for (int i= 0;i < daysOfTheWeek.length;i++ ){ System.out.println(daysOfTheWeek[i]); } } } % javac DayPrinter.java % java DayPrinter Sunday Monday Tuesday Wednesday Thuesday Friday Saturday
  • 75. Exercise: Print Personal Details • Write a program that will print your name and address to the console, for example: Alex Johnson 23 Main Street New York, NY 10001 USA
  • 77. Exercise: Sales Discount • Create a new project in Eclipse named Sale • Create, compile, and run the FriendsAndFamily class as illustrated below • Debug this program in your IDE to find out how it works
  • 78. Further Reading • Java Tutorials - https://docs.oracle.com/javase/tutorial/ • Java Language Basics - http://docs.oracle.com/javase/tutorial/java/nutsandbolts/index.html • Eclipse IDE Workbench User Guide - http://help.eclipse.org/kepler/index.jsp • Eclipse Tutorial - http://www.vogella.com/tutorials/Eclipse/article.html

Editor's Notes

  1. Source: http://profitswithjody.com/wp-content/uploads/2012/11/hello_world_Wallpaper_5ze28.jpg