SlideShare a Scribd company logo
Java
Programming(for designers)
What is a Program?
A list of detailed instructions that the computer
carries out
To make a cup of coffee the
following would not be sufficient:
The instructions would have
to be much more detailed:
You have to say exactly what to do in the right order with no ambiguity
1. Boil water
2. Put coffee in cup
3. Pour in hot water
4. Add milk
1.1. Go to kettle
1.2. Check kettle has water in it
1.3. If not
1.3.1 Take kettle to cold tap
1.3.2 Remove lid of kettle
1.3.3 Put kettle under cold tap
1.3.4 Turn on tap
1.3.5 When kettle full turn off tap
1.3.6 Return kettle to worktop
1.4. Plug kettle into mains
1.5.Switch on electricity
…….
Java is…
• Platform-independent
• Apps for mobile phones and other consumer
devices
• Secure, portable, multithreaded
• Online, server-side applications
• Simple, Object oriented
• GPL libraries
X
X
X?
☺
X
☺
Get started
• Two components:
• Java Virtual Machine (VM)
• Base for the Java platform, install Win version
• Java Application Programming Interface (API)
• Prewritten code, organized into packages of similar
topics. Each package or library contains classes and
interfaces that you can call and extend. Example:
• Rectangle2D = new Rectangle2D(loc, width, height)
• http://java.sun.com/learning/new2java
Acronyms
• JDK or J2SE, Development Kit
• Set of Java development tools, consisting of the
API classes, a Java compiler, and the Java virtual
machine (VM) interpreter
• The JDK is used to compile Java applications and
applets. The most current version is the J2SE 5
• J2SE, Runtime Environment 5.0
Set up: Download the JDK
• And set the classpath in Windows
Include the directories
where you will run
Java apps
Set Up a Development
Environment
• NetBeans IDE, JEdit, Eclipse, JCreator
• Or use a simple text editor, and compile and
run from the command line
Set Up
• Download J2SE 5.0 Documentation
• Look for useful libraries
Some Useful Libraries
• Colt: or High Performance Scientific and Technical Computing
• Weka 3: Data Mining Software in Java
• JHotDraw is a two-dimensional graphics framework for structured
drawing editors
• JGAP is a genetic algorithms component written in the form of a
Java package
• OpenAI: a full suite of Artificial Intelligence components: Agents,
Neural Nets, GAs…
• JUNG:Java Universal Network/Graph Framework
• JOONE: JGAP's genetic algorithms to evolve neural nets
• HyperGraph: to work with hyperbolic geometry and especially with
hyperbolic trees
• Repast: an agent modeling toolkit (like Swarm)
• JExcel or JXL provides the ability to read, write, and modify
Microsoft Excel spreadsheets
Standard Java Libraries
• Language
• Maths
• Graphics
• 2D
• 3D
• File I/O
•JAI: Advanced
Networking
•Imaging
•XML
•Print
Swing
• GUI-control (widget) library in Java 2
• Built-in controls, flexible and customizable
• Features aimed at interface design
• Buttons, tabbed panes,
dockable toolbars,
scroll panes, tooltips,
tables, etc.
• Look & feel can be changed
Java 2D
• Standard drawing library in Java 2
• Drawing attributes
• Fill patterns and images
• Fonts
• Line thicknesses and dashing patterns
• Colour mixing rules and transparency
• Transformations
• Floating-point coordinate system
• Mapping from memory coords to
screen or printer coords
• Affine transforms: translate, scale,
rotate, and shear
Java 3D
• Extension to Java
• Not part of “core” Java language like Java 2D
• Built on Direct3D or OpenGL, depending on
platform
• Scene-graph based model, not primarily
immediate-mode rendering
Java Versions
• Java 1.0, 1.1… “Java 2” refers to 1.2 onwards
• Popular: 1.4.2
• New: 1.5. The leading "1." is dropped, now it
is Java Platform Standard Edition 5.0
• But… version 5.0 also keeps the version
number 1.5.0 in some places visible only to
developers
• This release is also known as “Tiger” (not the latest Mac OS X!)
Jargon
• Application is a stand-alone Java program
• Applet is a browser-based Java program
Basic Procedure
1. Write a .java file
2. Compile it with the javac command
3. Now you have a .class file
4. Run it with the java command
5. Voilá!
Running a Java
ApplicationWrite
Java
code
javac MyProg.java
java MyProg
Java code:
MyProg.java
Bytecode:
MyProg.class
IDE or
Text
Editor
Output
Save the file
with a .java
extension
Run the
Java
compiler
'javac'
Execute the
bytecode with the
command 'java'
This creates
a file of
bytecode with
a .class
extension User to interact
with the system
Program to
execute and
produce a data
set, graphs, etc.
Java program layout
• A typical Java file looks like:
import java.awt.*;
import java.util.*;
public class SomethingOrOther {
// field and method definitions
. . .
}
This must be in a file named
SomethingOrOther.java !
What does it mean?
import java.awt.*;
import java.applet.Applet;
public class Greetings extends Applet {
public void paint(Graphics g) {
g.drawString("Hello World!", 50, 50);
}
}
These 2 lines tell the computer to include
(import) two standard libraries awt (Abstract
Window Toolkit) and applet.
This line tells the
computer to display
some text (a string) on
the screen.
This line announces that the
program (class) can be run by
anyone (public), is called
Greetings and is an Applet.
This line
declares what
follows in the {
} as a method
called paint.
This is where it is displayed in
pixels across and down from the
top left hand corner
This is what is displayed
A Java Class
• Java programs are collections of classes
• OOP:
• A class that represents a rectangle would contain
variables for its location, its width, and its height
• The class can also contain a method that
calculates the area of the rectangle
• An instance of the rectangle class could contain
the information for a specific rectangle, such as
the dimensions of a room
ITFT - Java Coding
An Applet is a Panel is a
Container… is an Object
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Panel
|
+----java.applet.Applet
…so you can do things with it that you’d do with
applets, panels, containers, components, and objects.
Object Oriented (OO)
Programming
A key aspect is Inheritance.
You don’t have to describe similar objects completely. You
can define a superclass (sometimes called base class) that
has the common attributes and methods and inherit these
adding only the ones that are different.
Vehicle
Bus Lorry
Attributes: Speed, Colour
Methods: Start, Stop
Attributes:
Max Load
Methods:
Pick up Load
Attributes: Max
Passengers
Methods: Pick up
Passengers
These are inherited
What classes, why?
• A file can contain multiple classes, but only
one can be declared public, and that one’s
name must match the filename
• Usually 1 class = 1 file
• Most difficult part is to plan the program: the
classes, the methods, the variables, the
procedure
• If you can define it in paper & pencil, the rest is
easy
Methods
• Define a group of statements that perform a
particular operation
• With or without arguments
calculateArea(shape) {
// here geom operations
}
createShape() {
// new square...
// calculateArea(square)
}
Primitives and Objects
• Java distinguishes two kinds of entities
• Primitive types
• Objects
• Primitive types: integers, doubles, booleans,
strings…
• Objects are associated with reference
variables which store an object’s address
Expressions
• Assignment statements: =, +=, *= etc.
• Arithmetic uses the familiar + - * / %
• Java uses ++ and --
• Java has boolean operators && || !
• Java has comparisons < <= == != >= >
Control statements
if (x < y) smaller = x;
if (x < y){ smaller=x; sum += x;}
else { smaller = y; sum += y; }
while (x < y) { y = y - x; }
do { y = y - x; } while (x < y)
for (int i = 0; i < max; i++)
sum += i;
The main method
• Every Java application must contain a main
method:
• public static void main(String[] args)
• An application executes the main method
first. The array of Strings can be empty or it
can receive arguments to customise how the
program runs (number of iterations, number
of agents, etc).
Example
An Evolutionary Design System
ITFT - Java Coding
ITFT - Java Coding
ITFT - Java Coding
ITFT - Java Coding
ITFT - Java Coding
ITFT - Java Coding
ITFT - Java Coding
public static void main(String[] args) {
new Model();
}
public Model() {
EvoDesign frame = new EvoDesign();
frame.setVisible(true);
}
public EvoDesign() {
jbInit();
}
private void jbInit() throws Exception {
setSize(new Dimension(860,680));
setTitle("Evolutionary Design");
jMenuFile.setText("File");…
setJMenuBar(jMenuBar);
JComboBox jGens…
JList jListFns…
JButton jRun…
jTabs.addTabs…
contentPane.add(…);
}
void jTabs_clicked(ChangeEvent e) { … }
void jLists_mouseClicked(MouseEvent e) {
… }
Image makeFitnessLines(Image im) {
LineGraph bg = new LineGraph();
bg.setDefaultLineThickness(0.1);
…
try {
new ImageOutput(im);
out.render(bg); im = out.getImage();
}
}
void jMenuExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
class drawPanel extends JPanel {
public void paint(Graphics g) {
g.setFont(EvoDesign.myFont);
g2.drawImage(new BufferedImage(0, 50, 2);
}
}
public void setupGA() throws Exception {
fitnessHistory = new DoubleArrayList();
topFitness.clear();
Configuration conf = new DefaultConfiguration();
conf.addGeneticOperator( new MutationOperator(mut) );
conf.addGeneticOperator( new CustomCrossover(cross) );
FitnessFunction myFunc = new FitnessFn(chrom);
conf.setFitnessFunction(myFunc);
Gene[] g = new Gene[chrom];
g[0] = new BooleanGene();
g[i] = new IntegerGene(1, alle);
Chromosome sampleChromosome = new Chromosome(g);
conf.setSampleChromosome(sampleChromosome);
conf.setPopulationSize(EvoDesign.pop);
genPopulation = Genotype.randomInitialGenotype(conf);
Chromosome best = genPopulation.getFittestChromosome();
}
public FitnessFn(int a) {
}
public int evaluate(Chromosome a) {
int fitness = 0;
Gene[] gs = a.getGenes();
if (EvoDesign.fnCrit.equals("minMean")) {
fitness += ( EvoDesign.alle -
Descriptive.mean(sd) );
}
return Math.max(1, fitness);
}
public Colours01() {
setColorPalettes();
}
public static BufferedImage
makeOutputImage() {
for (int i = 0; i < topSolutions.size(); i++) {
Chromosome s = topSolutions.get(i);
for (int j = 0; j < s.size(); j++) {
Gene si = s.getGene(j);
g2.setColor( getAllele() .intValue());
g2.fillRect(boxX, boxY, stepX, 25);
}
}
return bf;
}
Code
• Get these slides and the source code for the
example at:
http://www.arch.usyd.edu.au/~rsos7705/programming.html
Ad

Recommended

Java 101 Intro to Java Programming
Java 101 Intro to Java Programming
agorolabs
 
Java notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esection
Arc Keepers Solutions
 
Java 101 intro to programming with java
Java 101 intro to programming with java
Hawkman Academy
 
Introduction to java 101
Introduction to java 101
kankemwa Ishaku
 
Java 201 Intro to Test Driven Development in Java
Java 201 Intro to Test Driven Development in Java
agorolabs
 
New Features Of JDK 7
New Features Of JDK 7
Deniz Oguz
 
Java 101 Intro to Java Programming - Exercises
Java 101 Intro to Java Programming - Exercises
agorolabs
 
Hadoop cluster performance profiler
Hadoop cluster performance profiler
Ihor Bobak
 
Introduction to new features in java 8
Introduction to new features in java 8
New York City College of Technology Computer Systems Technology Colloquium
 
PROGRAMMING IN JAVA-unit 3-part II
PROGRAMMING IN JAVA-unit 3-part II
SivaSankari36
 
Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)
Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)
DevelopIntelligence
 
PROGRAMMING IN JAVA
PROGRAMMING IN JAVA
SivaSankari36
 
Java Tutorial
Java Tutorial
Vijay A Raj
 
55 New Features in Java 7
55 New Features in Java 7
Boulder Java User's Group
 
Core java Basics
Core java Basics
RAMU KOLLI
 
Presentation on java
Presentation on java
shashi shekhar
 
Java user group 2015 02-09-java8
Java user group 2015 02-09-java8
marctritschler
 
55 New Features in Java SE 8
55 New Features in Java SE 8
Simon Ritter
 
Core java
Core java
Ravi varma
 
PROGRAMMING IN JAVA- unit 4-part I
PROGRAMMING IN JAVA- unit 4-part I
SivaSankari36
 
02 basic java programming and operators
02 basic java programming and operators
Danairat Thanabodithammachari
 
Java 102 intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
agorolabs
 
Java For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
Partnered Health
 
Basic java part_ii
Basic java part_ii
Khaled AlGhazaly
 
Basic java for Android Developer
Basic java for Android Developer
Nattapong Tonprasert
 
PROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part I
SivaSankari36
 
Java basic
Java basic
Arati Gadgil
 
Java basics notes
Java basics notes
poonguzhali1826
 
76829060 java-coding-conventions
76829060 java-coding-conventions
slavicp
 
Coding Standards & Conventions for Java and Rails projects
Coding Standards & Conventions for Java and Rails projects
David Francisco
 

More Related Content

What's hot (20)

Introduction to new features in java 8
Introduction to new features in java 8
New York City College of Technology Computer Systems Technology Colloquium
 
PROGRAMMING IN JAVA-unit 3-part II
PROGRAMMING IN JAVA-unit 3-part II
SivaSankari36
 
Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)
Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)
DevelopIntelligence
 
PROGRAMMING IN JAVA
PROGRAMMING IN JAVA
SivaSankari36
 
Java Tutorial
Java Tutorial
Vijay A Raj
 
55 New Features in Java 7
55 New Features in Java 7
Boulder Java User's Group
 
Core java Basics
Core java Basics
RAMU KOLLI
 
Presentation on java
Presentation on java
shashi shekhar
 
Java user group 2015 02-09-java8
Java user group 2015 02-09-java8
marctritschler
 
55 New Features in Java SE 8
55 New Features in Java SE 8
Simon Ritter
 
Core java
Core java
Ravi varma
 
PROGRAMMING IN JAVA- unit 4-part I
PROGRAMMING IN JAVA- unit 4-part I
SivaSankari36
 
02 basic java programming and operators
02 basic java programming and operators
Danairat Thanabodithammachari
 
Java 102 intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
agorolabs
 
Java For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
Partnered Health
 
Basic java part_ii
Basic java part_ii
Khaled AlGhazaly
 
Basic java for Android Developer
Basic java for Android Developer
Nattapong Tonprasert
 
PROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part I
SivaSankari36
 
Java basic
Java basic
Arati Gadgil
 
Java basics notes
Java basics notes
poonguzhali1826
 
PROGRAMMING IN JAVA-unit 3-part II
PROGRAMMING IN JAVA-unit 3-part II
SivaSankari36
 
Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)
Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)
DevelopIntelligence
 
Core java Basics
Core java Basics
RAMU KOLLI
 
Java user group 2015 02-09-java8
Java user group 2015 02-09-java8
marctritschler
 
55 New Features in Java SE 8
55 New Features in Java SE 8
Simon Ritter
 
PROGRAMMING IN JAVA- unit 4-part I
PROGRAMMING IN JAVA- unit 4-part I
SivaSankari36
 
Java 102 intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
agorolabs
 
Java For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
Partnered Health
 
PROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part I
SivaSankari36
 

Viewers also liked (11)

76829060 java-coding-conventions
76829060 java-coding-conventions
slavicp
 
Coding Standards & Conventions for Java and Rails projects
Coding Standards & Conventions for Java and Rails projects
David Francisco
 
Php Coding Convention
Php Coding Convention
Phuong Vy
 
Standards For Java Coding
Standards For Java Coding
Rahul Bhutkar
 
Standard Coding, OOP Techniques and Code Reuse
Standard Coding, OOP Techniques and Code Reuse
Rayhan Chowdhury
 
Why coding convention ?
Why coding convention ?
Panji Gautama
 
Secure Coding for Java - An introduction
Secure Coding for Java - An introduction
Sebastien Gioria
 
Standard java coding convention
Standard java coding convention
Tam Thanh
 
Coding Best practices (PHP)
Coding Best practices (PHP)
Christian Baune
 
Coding standards for java
Coding standards for java
maheshm1206
 
Coding convention
Coding convention
Khoa Nguyen
 
76829060 java-coding-conventions
76829060 java-coding-conventions
slavicp
 
Coding Standards & Conventions for Java and Rails projects
Coding Standards & Conventions for Java and Rails projects
David Francisco
 
Php Coding Convention
Php Coding Convention
Phuong Vy
 
Standards For Java Coding
Standards For Java Coding
Rahul Bhutkar
 
Standard Coding, OOP Techniques and Code Reuse
Standard Coding, OOP Techniques and Code Reuse
Rayhan Chowdhury
 
Why coding convention ?
Why coding convention ?
Panji Gautama
 
Secure Coding for Java - An introduction
Secure Coding for Java - An introduction
Sebastien Gioria
 
Standard java coding convention
Standard java coding convention
Tam Thanh
 
Coding Best practices (PHP)
Coding Best practices (PHP)
Christian Baune
 
Coding standards for java
Coding standards for java
maheshm1206
 
Coding convention
Coding convention
Khoa Nguyen
 
Ad

Similar to ITFT - Java Coding (20)

Java Programming for Designers
Java Programming for Designers
R. Sosa
 
1 java programming- introduction
1 java programming- introduction
jyoti_lakhani
 
java slides
java slides
RizwanTariq18
 
CS8392 OOP
CS8392 OOP
DhanalakshmiVelusamy1
 
oop unit1.pptx
oop unit1.pptx
sureshkumara29
 
object oriented programming unit one ppt
object oriented programming unit one ppt
isiagnel2
 
Java Programming Fundamentals: Complete Guide for Beginners
Java Programming Fundamentals: Complete Guide for Beginners
Taranath Jaishy
 
JavaClassPresentation
JavaClassPresentation
juliasceasor
 
Unit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rd
prat0ham
 
Java Introduction
Java Introduction
sunmitraeducation
 
Introduction to java programming part 1
Introduction to java programming part 1
university of education,Lahore
 
Letest
Letest
Prakash Poudel
 
Java Programming concept
Java Programming concept
Prakash Poudel
 
Java Programming and J2ME: The Basics
Java Programming and J2ME: The Basics
tosine
 
basic core java up to operator
basic core java up to operator
kamal kotecha
 
Java1 in mumbai
Java1 in mumbai
vibrantuser
 
2. Introduction to Java for engineering stud
2. Introduction to Java for engineering stud
vyshukodumuri
 
Javalecture 1
Javalecture 1
mrinalbhutani
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
FAKHRUN NISHA
 
this_is_how_to_start_coding_in_java_lang.ppt
this_is_how_to_start_coding_in_java_lang.ppt
AhmedHamzaJandoubi
 
Java Programming for Designers
Java Programming for Designers
R. Sosa
 
1 java programming- introduction
1 java programming- introduction
jyoti_lakhani
 
object oriented programming unit one ppt
object oriented programming unit one ppt
isiagnel2
 
Java Programming Fundamentals: Complete Guide for Beginners
Java Programming Fundamentals: Complete Guide for Beginners
Taranath Jaishy
 
JavaClassPresentation
JavaClassPresentation
juliasceasor
 
Unit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rd
prat0ham
 
Java Programming concept
Java Programming concept
Prakash Poudel
 
Java Programming and J2ME: The Basics
Java Programming and J2ME: The Basics
tosine
 
basic core java up to operator
basic core java up to operator
kamal kotecha
 
2. Introduction to Java for engineering stud
2. Introduction to Java for engineering stud
vyshukodumuri
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
FAKHRUN NISHA
 
this_is_how_to_start_coding_in_java_lang.ppt
this_is_how_to_start_coding_in_java_lang.ppt
AhmedHamzaJandoubi
 
Ad

More from Blossom Sood (9)

ITFT- Dbms
ITFT- Dbms
Blossom Sood
 
ITFT - Web security
ITFT - Web security
Blossom Sood
 
ITFT - Trends in it
ITFT - Trends in it
Blossom Sood
 
ITFT - Search engine
ITFT - Search engine
Blossom Sood
 
ITFT - Oops
ITFT - Oops
Blossom Sood
 
ITFT - Number system
ITFT - Number system
Blossom Sood
 
ITFT - Java
ITFT - Java
Blossom Sood
 
ITFT - DOS - Disk Operating System
ITFT - DOS - Disk Operating System
Blossom Sood
 
ITFT - Window explorer
ITFT - Window explorer
Blossom Sood
 
ITFT - Web security
ITFT - Web security
Blossom Sood
 
ITFT - Trends in it
ITFT - Trends in it
Blossom Sood
 
ITFT - Search engine
ITFT - Search engine
Blossom Sood
 
ITFT - Number system
ITFT - Number system
Blossom Sood
 
ITFT - DOS - Disk Operating System
ITFT - DOS - Disk Operating System
Blossom Sood
 
ITFT - Window explorer
ITFT - Window explorer
Blossom Sood
 

Recently uploaded (20)

K12 Tableau User Group virtual event June 18, 2025
K12 Tableau User Group virtual event June 18, 2025
dogden2
 
Peer Teaching Observations During School Internship
Peer Teaching Observations During School Internship
AjayaMohanty7
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 6-14-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 6-14-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
Ultimatewinner0342
 
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
sumadsadjelly121997
 
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
Ronisha Das
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
Q1_TLE 8_Week 1- Day 1 tools and equipment
Q1_TLE 8_Week 1- Day 1 tools and equipment
clairenotado3
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
LDMMIA Shop & Student News Summer Solstice 25
LDMMIA Shop & Student News Summer Solstice 25
LDM & Mia eStudios
 
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
IIT Kharagpur Quiz Club
 
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
jutaydeonne
 
Photo chemistry Power Point Presentation
Photo chemistry Power Point Presentation
mprpgcwa2024
 
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
parmarjuli1412
 
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
 
HistoPathology Ppt. Arshita Gupta for Diploma
HistoPathology Ppt. Arshita Gupta for Diploma
arshitagupta674
 
List View Components in Odoo 18 - Odoo Slides
List View Components in Odoo 18 - Odoo Slides
Celine George
 
Aprendendo Arquitetura Framework Salesforce - Dia 02
Aprendendo Arquitetura Framework Salesforce - Dia 02
Mauricio Alexandre Silva
 
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
Mayvel Nadal
 
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
 
K12 Tableau User Group virtual event June 18, 2025
K12 Tableau User Group virtual event June 18, 2025
dogden2
 
Peer Teaching Observations During School Internship
Peer Teaching Observations During School Internship
AjayaMohanty7
 
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
Ultimatewinner0342
 
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
sumadsadjelly121997
 
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
Ronisha Das
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
Q1_TLE 8_Week 1- Day 1 tools and equipment
Q1_TLE 8_Week 1- Day 1 tools and equipment
clairenotado3
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
LDMMIA Shop & Student News Summer Solstice 25
LDMMIA Shop & Student News Summer Solstice 25
LDM & Mia eStudios
 
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
IIT Kharagpur Quiz Club
 
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
jutaydeonne
 
Photo chemistry Power Point Presentation
Photo chemistry Power Point Presentation
mprpgcwa2024
 
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
parmarjuli1412
 
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
 
HistoPathology Ppt. Arshita Gupta for Diploma
HistoPathology Ppt. Arshita Gupta for Diploma
arshitagupta674
 
List View Components in Odoo 18 - Odoo Slides
List View Components in Odoo 18 - Odoo Slides
Celine George
 
Aprendendo Arquitetura Framework Salesforce - Dia 02
Aprendendo Arquitetura Framework Salesforce - Dia 02
Mauricio Alexandre Silva
 
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
Mayvel Nadal
 
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
 

ITFT - Java Coding

  • 2. What is a Program? A list of detailed instructions that the computer carries out To make a cup of coffee the following would not be sufficient: The instructions would have to be much more detailed: You have to say exactly what to do in the right order with no ambiguity 1. Boil water 2. Put coffee in cup 3. Pour in hot water 4. Add milk 1.1. Go to kettle 1.2. Check kettle has water in it 1.3. If not 1.3.1 Take kettle to cold tap 1.3.2 Remove lid of kettle 1.3.3 Put kettle under cold tap 1.3.4 Turn on tap 1.3.5 When kettle full turn off tap 1.3.6 Return kettle to worktop 1.4. Plug kettle into mains 1.5.Switch on electricity …….
  • 3. Java is… • Platform-independent • Apps for mobile phones and other consumer devices • Secure, portable, multithreaded • Online, server-side applications • Simple, Object oriented • GPL libraries X X X? ☺ X ☺
  • 4. Get started • Two components: • Java Virtual Machine (VM) • Base for the Java platform, install Win version • Java Application Programming Interface (API) • Prewritten code, organized into packages of similar topics. Each package or library contains classes and interfaces that you can call and extend. Example: • Rectangle2D = new Rectangle2D(loc, width, height) • http://java.sun.com/learning/new2java
  • 5. Acronyms • JDK or J2SE, Development Kit • Set of Java development tools, consisting of the API classes, a Java compiler, and the Java virtual machine (VM) interpreter • The JDK is used to compile Java applications and applets. The most current version is the J2SE 5 • J2SE, Runtime Environment 5.0
  • 6. Set up: Download the JDK • And set the classpath in Windows Include the directories where you will run Java apps
  • 7. Set Up a Development Environment • NetBeans IDE, JEdit, Eclipse, JCreator • Or use a simple text editor, and compile and run from the command line
  • 8. Set Up • Download J2SE 5.0 Documentation • Look for useful libraries
  • 9. Some Useful Libraries • Colt: or High Performance Scientific and Technical Computing • Weka 3: Data Mining Software in Java • JHotDraw is a two-dimensional graphics framework for structured drawing editors • JGAP is a genetic algorithms component written in the form of a Java package • OpenAI: a full suite of Artificial Intelligence components: Agents, Neural Nets, GAs… • JUNG:Java Universal Network/Graph Framework • JOONE: JGAP's genetic algorithms to evolve neural nets • HyperGraph: to work with hyperbolic geometry and especially with hyperbolic trees • Repast: an agent modeling toolkit (like Swarm) • JExcel or JXL provides the ability to read, write, and modify Microsoft Excel spreadsheets
  • 10. Standard Java Libraries • Language • Maths • Graphics • 2D • 3D • File I/O •JAI: Advanced Networking •Imaging •XML •Print
  • 11. Swing • GUI-control (widget) library in Java 2 • Built-in controls, flexible and customizable • Features aimed at interface design • Buttons, tabbed panes, dockable toolbars, scroll panes, tooltips, tables, etc. • Look & feel can be changed
  • 12. Java 2D • Standard drawing library in Java 2 • Drawing attributes • Fill patterns and images • Fonts • Line thicknesses and dashing patterns • Colour mixing rules and transparency • Transformations • Floating-point coordinate system • Mapping from memory coords to screen or printer coords • Affine transforms: translate, scale, rotate, and shear
  • 13. Java 3D • Extension to Java • Not part of “core” Java language like Java 2D • Built on Direct3D or OpenGL, depending on platform • Scene-graph based model, not primarily immediate-mode rendering
  • 14. Java Versions • Java 1.0, 1.1… “Java 2” refers to 1.2 onwards • Popular: 1.4.2 • New: 1.5. The leading "1." is dropped, now it is Java Platform Standard Edition 5.0 • But… version 5.0 also keeps the version number 1.5.0 in some places visible only to developers • This release is also known as “Tiger” (not the latest Mac OS X!)
  • 15. Jargon • Application is a stand-alone Java program • Applet is a browser-based Java program
  • 16. Basic Procedure 1. Write a .java file 2. Compile it with the javac command 3. Now you have a .class file 4. Run it with the java command 5. Voilá!
  • 17. Running a Java ApplicationWrite Java code javac MyProg.java java MyProg Java code: MyProg.java Bytecode: MyProg.class IDE or Text Editor Output Save the file with a .java extension Run the Java compiler 'javac' Execute the bytecode with the command 'java' This creates a file of bytecode with a .class extension User to interact with the system Program to execute and produce a data set, graphs, etc.
  • 18. Java program layout • A typical Java file looks like: import java.awt.*; import java.util.*; public class SomethingOrOther { // field and method definitions . . . } This must be in a file named SomethingOrOther.java !
  • 19. What does it mean? import java.awt.*; import java.applet.Applet; public class Greetings extends Applet { public void paint(Graphics g) { g.drawString("Hello World!", 50, 50); } } These 2 lines tell the computer to include (import) two standard libraries awt (Abstract Window Toolkit) and applet. This line tells the computer to display some text (a string) on the screen. This line announces that the program (class) can be run by anyone (public), is called Greetings and is an Applet. This line declares what follows in the { } as a method called paint. This is where it is displayed in pixels across and down from the top left hand corner This is what is displayed
  • 20. A Java Class • Java programs are collections of classes • OOP: • A class that represents a rectangle would contain variables for its location, its width, and its height • The class can also contain a method that calculates the area of the rectangle • An instance of the rectangle class could contain the information for a specific rectangle, such as the dimensions of a room
  • 22. An Applet is a Panel is a Container… is an Object java.lang.Object | +----java.awt.Component | +----java.awt.Container | +----java.awt.Panel | +----java.applet.Applet …so you can do things with it that you’d do with applets, panels, containers, components, and objects.
  • 23. Object Oriented (OO) Programming A key aspect is Inheritance. You don’t have to describe similar objects completely. You can define a superclass (sometimes called base class) that has the common attributes and methods and inherit these adding only the ones that are different. Vehicle Bus Lorry Attributes: Speed, Colour Methods: Start, Stop Attributes: Max Load Methods: Pick up Load Attributes: Max Passengers Methods: Pick up Passengers These are inherited
  • 24. What classes, why? • A file can contain multiple classes, but only one can be declared public, and that one’s name must match the filename • Usually 1 class = 1 file • Most difficult part is to plan the program: the classes, the methods, the variables, the procedure • If you can define it in paper & pencil, the rest is easy
  • 25. Methods • Define a group of statements that perform a particular operation • With or without arguments calculateArea(shape) { // here geom operations } createShape() { // new square... // calculateArea(square) }
  • 26. Primitives and Objects • Java distinguishes two kinds of entities • Primitive types • Objects • Primitive types: integers, doubles, booleans, strings… • Objects are associated with reference variables which store an object’s address
  • 27. Expressions • Assignment statements: =, +=, *= etc. • Arithmetic uses the familiar + - * / % • Java uses ++ and -- • Java has boolean operators && || ! • Java has comparisons < <= == != >= >
  • 28. Control statements if (x < y) smaller = x; if (x < y){ smaller=x; sum += x;} else { smaller = y; sum += y; } while (x < y) { y = y - x; } do { y = y - x; } while (x < y) for (int i = 0; i < max; i++) sum += i;
  • 29. The main method • Every Java application must contain a main method: • public static void main(String[] args) • An application executes the main method first. The array of Strings can be empty or it can receive arguments to customise how the program runs (number of iterations, number of agents, etc).
  • 38. public static void main(String[] args) { new Model(); } public Model() { EvoDesign frame = new EvoDesign(); frame.setVisible(true); }
  • 39. public EvoDesign() { jbInit(); } private void jbInit() throws Exception { setSize(new Dimension(860,680)); setTitle("Evolutionary Design"); jMenuFile.setText("File");… setJMenuBar(jMenuBar); JComboBox jGens… JList jListFns… JButton jRun… jTabs.addTabs… contentPane.add(…); } void jTabs_clicked(ChangeEvent e) { … } void jLists_mouseClicked(MouseEvent e) { … }
  • 40. Image makeFitnessLines(Image im) { LineGraph bg = new LineGraph(); bg.setDefaultLineThickness(0.1); … try { new ImageOutput(im); out.render(bg); im = out.getImage(); } } void jMenuExit_actionPerformed(ActionEvent e) { System.exit(0); } class drawPanel extends JPanel { public void paint(Graphics g) { g.setFont(EvoDesign.myFont); g2.drawImage(new BufferedImage(0, 50, 2); } }
  • 41. public void setupGA() throws Exception { fitnessHistory = new DoubleArrayList(); topFitness.clear(); Configuration conf = new DefaultConfiguration(); conf.addGeneticOperator( new MutationOperator(mut) ); conf.addGeneticOperator( new CustomCrossover(cross) ); FitnessFunction myFunc = new FitnessFn(chrom); conf.setFitnessFunction(myFunc); Gene[] g = new Gene[chrom]; g[0] = new BooleanGene(); g[i] = new IntegerGene(1, alle); Chromosome sampleChromosome = new Chromosome(g); conf.setSampleChromosome(sampleChromosome); conf.setPopulationSize(EvoDesign.pop); genPopulation = Genotype.randomInitialGenotype(conf); Chromosome best = genPopulation.getFittestChromosome(); }
  • 42. public FitnessFn(int a) { } public int evaluate(Chromosome a) { int fitness = 0; Gene[] gs = a.getGenes(); if (EvoDesign.fnCrit.equals("minMean")) { fitness += ( EvoDesign.alle - Descriptive.mean(sd) ); } return Math.max(1, fitness); }
  • 43. public Colours01() { setColorPalettes(); } public static BufferedImage makeOutputImage() { for (int i = 0; i < topSolutions.size(); i++) { Chromosome s = topSolutions.get(i); for (int j = 0; j < s.size(); j++) { Gene si = s.getGene(j); g2.setColor( getAllele() .intValue()); g2.fillRect(boxX, boxY, stepX, 25); } } return bf; }
  • 44. Code • Get these slides and the source code for the example at: http://www.arch.usyd.edu.au/~rsos7705/programming.html