SlideShare a Scribd company logo
Java 101: Intro to Java
Programming
Introduction
• Your Name: Manuela Grindei
• Your day job: Software Developer @ Gamesys
• Your last holiday destination: Dublin
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
Intelli j Setup & Demo
https://www.jetbrains.com/idea/download/
Java 101: Introduction to Java
Language Overview
Java Language History
Java Language Overview
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
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.
Anatomy of a Java Application
Comments Class Name
Access
modifier
Function/static
method
Arguments
Compiling Your First Java Program
• Save the HelloWorld class in the IDE
• Run your program: right-clicking and selecting Run
As>Java Application
• 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(eclipse) or out (Intelli j)folder.
• What do you see?
Built-in classes
Introduction to Java
Built-in Data Types
Built-in Data Types
• Data types 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 -2^31 to +2^31-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 IntOps in 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 && || !
Logical operators
& (AND) | (OR)
^
(EXCLUSIVE OR)
True False True False True False
True True False True True False True
False False False True False True False
Logical operators
• & (AND): Only TRUE if both operands are TRUE
• | (OR): Only FALSE if both operands are FALSE
• ^ (EXCLUSIVE OR): Only TRUE if both operands are
DIFFERENT
Conditional & Negation operators
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
• Intelli J IDE User Guide - https://www.jetbrains.com/idea/documentation/
• Eclipse Tutorial - http://www.vogella.com/tutorials/Eclipse/article.html

More Related Content

What's hot

SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
Andreas Enbohm
 
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Edureka!
 
OCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIsOCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIs
İbrahim Kürce
 
SOLID principles
SOLID principlesSOLID principles
SOLID principles
Jonathan Holloway
 
JUnit 5
JUnit 5JUnit 5
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
Ram132
 
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
Danairat Thanabodithammachari
 
Oop in kotlin
Oop in kotlinOop in kotlin
collection framework in java
collection framework in javacollection framework in java
collection framework in java
MANOJ KUMAR
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features Overview
Sergii Stets
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for javamaheshm1206
 
Java Presentation
Java PresentationJava Presentation
Java Presentationpm2214
 
Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java ...
Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java ...Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java ...
Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java ...
Edureka!
 
Solid principles
Solid principlesSolid principles
Solid principles
Monica Rodrigues
 
Clean code: SOLID
Clean code: SOLIDClean code: SOLID
Clean code: SOLID
Indeema Software Inc.
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
Sony India Software Center
 

What's hot (20)

SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
 
Practical Groovy DSL
Practical Groovy DSLPractical Groovy DSL
Practical Groovy DSL
 
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
 
OCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIsOCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIs
 
SOLID principles
SOLID principlesSOLID principles
SOLID principles
 
Core java Essentials
Core java EssentialsCore java Essentials
Core java Essentials
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
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
 
Oop in kotlin
Oop in kotlinOop in kotlin
Oop in kotlin
 
collection framework in java
collection framework in javacollection framework in java
collection framework in java
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features Overview
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for java
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java ...
Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java ...Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java ...
Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java ...
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Clean code: SOLID
Clean code: SOLIDClean code: SOLID
Clean code: SOLID
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Java input
Java inputJava input
Java input
 

Similar to Java 101

Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101
kankemwa Ishaku
 
Java 101 intro to programming with java
Java 101  intro to programming with javaJava 101  intro to programming with java
Java 101 intro to programming with java
Hawkman Academy
 
Java 101 Intro to Java Programming
Java 101 Intro to Java ProgrammingJava 101 Intro to Java Programming
Java 101 Intro to Java Programming
agorolabs
 
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#
Hawkman Academy
 
Programming in java basics
Programming in java  basicsProgramming in java  basics
Programming in java basics
LovelitJose
 
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
AssignmentjsnsnshshusjdnsnshhzudjdndndjdAssignmentjsnsnshshusjdnsnshhzudjdndndjd
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
tusharjain613841
 
Session 1 of programming
Session 1 of programmingSession 1 of programming
Session 1 of programming
Ramy F. Radwan
 
ITFT - Java Coding
ITFT - Java CodingITFT - Java Coding
ITFT - Java Coding
Blossom Sood
 
Java for android developers
Java for android developersJava for android developers
Java for android developers
Aly Abdelkareem
 
java in Aartificial intelligent by virat andodariya
java in Aartificial intelligent by virat andodariyajava in Aartificial intelligent by virat andodariya
java in Aartificial intelligent by virat andodariya
viratandodariya
 
JAVA in Artificial intelligent
JAVA in Artificial intelligentJAVA in Artificial intelligent
JAVA in Artificial intelligent
Virat Andodariya
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
apoorvams
 
Knowledge of Javascript
Knowledge of JavascriptKnowledge of Javascript
Knowledge of Javascript
Samuel Abraham
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
Sujit Majety
 
CS8392 OOP
CS8392 OOPCS8392 OOP
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
sureshkumara29
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
Pray Desai
 
Java Review
Java ReviewJava Review
Java Review
pdgeorge
 
Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Core Java introduction | Basics | free course
Core Java introduction | Basics | free course
Kernel Training
 

Similar to Java 101 (20)

Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101
 
Java 101 intro to programming with java
Java 101  intro to programming with javaJava 101  intro to programming with java
Java 101 intro to programming with java
 
Java 101 Intro to Java Programming
Java 101 Intro to Java ProgrammingJava 101 Intro to Java Programming
Java 101 Intro to Java Programming
 
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
 
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
AssignmentjsnsnshshusjdnsnshhzudjdndndjdAssignmentjsnsnshshusjdnsnshhzudjdndndjd
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
 
Session 1 of programming
Session 1 of programmingSession 1 of programming
Session 1 of programming
 
Unit 1
Unit 1Unit 1
Unit 1
 
ITFT - Java Coding
ITFT - Java CodingITFT - Java Coding
ITFT - Java Coding
 
Java for android developers
Java for android developersJava for android developers
Java for android developers
 
java in Aartificial intelligent by virat andodariya
java in Aartificial intelligent by virat andodariyajava in Aartificial intelligent by virat andodariya
java in Aartificial intelligent by virat andodariya
 
JAVA in Artificial intelligent
JAVA in Artificial intelligentJAVA in Artificial intelligent
JAVA in Artificial intelligent
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
 
Knowledge of Javascript
Knowledge of JavascriptKnowledge of Javascript
Knowledge of Javascript
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Java Review
Java ReviewJava Review
Java Review
 
Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Core Java introduction | Basics | free course
Core Java introduction | Basics | free course
 

More from Manuela Grindei

TDD Training
TDD TrainingTDD Training
TDD Training
Manuela Grindei
 
Java 104
Java 104Java 104
Java 104
Manuela Grindei
 
Java 103
Java 103Java 103
Java 103
Manuela Grindei
 
Continuous delivery - takeaways
Continuous delivery - takeawaysContinuous delivery - takeaways
Continuous delivery - takeaways
Manuela Grindei
 
Release it! - Takeaways
Release it! - TakeawaysRelease it! - Takeaways
Release it! - Takeaways
Manuela Grindei
 
Exceptions and errors in Java
Exceptions and errors in JavaExceptions and errors in Java
Exceptions and errors in Java
Manuela Grindei
 

More from Manuela Grindei (6)

TDD Training
TDD TrainingTDD Training
TDD Training
 
Java 104
Java 104Java 104
Java 104
 
Java 103
Java 103Java 103
Java 103
 
Continuous delivery - takeaways
Continuous delivery - takeawaysContinuous delivery - takeaways
Continuous delivery - takeaways
 
Release it! - Takeaways
Release it! - TakeawaysRelease it! - Takeaways
Release it! - Takeaways
 
Exceptions and errors in Java
Exceptions and errors in JavaExceptions and errors in Java
Exceptions and errors in Java
 

Recently uploaded

Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
MayankTawar1
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
Sharepoint Designs
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 

Recently uploaded (20)

Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 

Java 101

  • 1. Java 101: Intro to Java Programming
  • 2. Introduction • Your Name: Manuela Grindei • Your day job: Software Developer @ Gamesys • Your last holiday destination: Dublin
  • 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
  • 10. Hands-on Exercise Intelli j Setup & Demo https://www.jetbrains.com/idea/download/
  • 11. Java 101: Introduction to Java Language Overview
  • 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
  • 20. 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.
  • 21. Anatomy of a Java Application Comments Class Name Access modifier Function/static method Arguments
  • 22. Compiling Your First Java Program • Save the HelloWorld class in the IDE • Run your program: right-clicking and selecting Run As>Java Application • 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(eclipse) or out (Intelli j)folder. • What do you see?
  • 25. Built-in Data Types • Data types are sets of values and operations defined on those values
  • 26. Basic Definitions • Variable - a name that refers to a value. • Assignment statement - associates a value with a variable.
  • 27. String Data Type Data Type Attributes Values sequence of characters Typical literals “Hello”, “1 “, “*” Operation Concatenate Operator + • Useful for program input and output.
  • 29. String Data Type • Meaning of characters depends on context.
  • 30. String Data Type Expression Value “Hi, “ + “Bob” “Hi, Bob” “1” + “ 2 “ + “ 1” “ 1 2 1” “1234” + “ + “ + “99” “1234 + 99” “1234” + “99” “123499”
  • 32. Exercise: Command Line Arguments • Create the Java program below that takes a name as command-line argument and prints “Hi <name>, How are you?”
  • 33. Integer Data Type Data Type Attributes Values Integers between -2^31 to +2^31-1 Typical literals 1234, -99 , 99, 0, 1000000 Operation Add subtract multiply divide remainder Operator + - * / % • Useful for expressing algorithms.
  • 34. 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
  • 35. 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 + - * /
  • 36. 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
  • 37. 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
  • 39. Exercise: Integer Operations • Create a Java class named IntOps in the Java101 project that performs integer operations on a pair of integers from the command line and prints the results.
  • 41. 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 && || !
  • 42. Logical operators & (AND) | (OR) ^ (EXCLUSIVE OR) True False True False True False True True False True True False True False False False True False True False
  • 43. Logical operators • & (AND): Only TRUE if both operands are TRUE • | (OR): Only FALSE if both operands are FALSE • ^ (EXCLUSIVE OR): Only TRUE if both operands are DIFFERENT
  • 44. Conditional & Negation operators 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
  • 45. 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
  • 46. Type Conversion • Convert from one type of data to another. • Implicit – no loss of precision – with strings • Explicit: – cast – method.
  • 47. 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
  • 49. 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
  • 51. 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.
  • 53. Conditionals and Loops • Sequence of statements that are actually executed in a program. • Enable us to choreograph control flow.
  • 54. Conditionals • The if statement is a common branching structure. – Evaluate a boolean expression. • If true, execute some statements. • If false, execute other statements.
  • 56. More If Statement Examples
  • 57. While Loop • A common repetition structure. – Evaluate a boolean expression. – If true, execute some statements. – Repeat.
  • 58. For Loop • Another common repetition structure. – Execute initialization statement. – Evaluate a boolean expression. • If true, execute some statements. – And then the increment statement. – Repeat.
  • 59. Anatomy of a For Loop
  • 63. 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
  • 65. 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
  • 66. Homework Exercises Java 101: Introduction to Java
  • 68. 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
  • 71. 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.
  • 72. 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
  • 74. 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
  • 76. 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
  • 77. 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 • Intelli J IDE User Guide - https://www.jetbrains.com/idea/documentation/ • Eclipse Tutorial - http://www.vogella.com/tutorials/Eclipse/article.html

Editor's Notes

  1. System is a final class from java.lang package. out is the reference of PrintStream class and a static member of System class. println is a method of PrintStream class.
  2. System is a built-in class... System is a final class from java.lang package. out is the reference of PrintStream class and a static member of System class. println is a method of PrintStream class.
  3. Variables hold the state of the program, and methods operate on that state. If the change is important to remember, a variable stores that change. That’s all classes really do. Java calls a word with special meaning a keyword It probably comes as no surprise that Java has precise rules about identifier names. Luckily, the same rules for identifiers apply to anything you are free to name, including variables, methods, classes, and fields. There are only three rules to remember for legal identifiers: The name must begin with a letter or the symbol $ or _. Subsequent characters may also be numbers. You cannot use the same name as a Java reserved word. As you might imagine, a reserved word is a keyword that Java has reserved so that you are not allowed to use it. Remember that Java is case sensitive, so you can use versions of the keywords that only differ in case. Please don’t, though.
  4. The Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int.In addition, this class provides several methods for converting an int to a String and a String to an int, as well as other constants and methods useful when dealing with an int.
  5. The last thing you need to know about numeric literals is a feature added in Java 7. You can have underscores in numbers to make them easier to read:
  6. Literals are valid values assigned to data types
  7. To sum up: - float is represented in 32 bits, with 1 sign bit, 8 bits of exponent, and 23 bits of the mantissa (or what follows from a scientific-notation number: 2.33728*1012; 33728 is the mantissa). - Double is represented in 64 bits, with 1 sign bit, 11 bits of exponent, and 52 bits of mantissa. By default, Java uses double to represent its floating-point numerals (so a literal 3.14 is typed double). It's also the data type that will give you a much larger number range, so I would strongly encourage its use over float. There may be certain libraries that actually force your usage of float, but in general - unless you can guarantee that your result will be small enough to fit in float's prescribed range, then it's best to opt with double.
  8. & (AND): Only TRUE if both operands are TRUE | (OR): Only FALSE if both operands are FALSE ^ (EXCLUSIVE OR): Only TRUE if both operands are DIFFERENT