Download presentation
Presentation is loading. Please wait.
Published byAlan McBride Modified over 8 years ago
1
Introduction to Java Programming by Laurie Murphy Revised 09/08/2016
2
What is Java? What does a Java program look like? How do I go about writing a Java program?
3
What is Java?
4
Java is an object-oriented programming language developed at Sun Microsystems in 1995.
5
Algorithm Program
6
Automobile C02 Calculator Ask the user for miles per gallon Ask the user for the number of miles driven Calculate the gallons of fuel used Calculate pounds of CO2 used (gallons of fuel used times the emissions factor of 19.6) Display gallons of fuel and CO2 used algorithm
7
CPU: Central Processing Unit The “brain” of the computer. Types: –Intel: Core i5, Core i7, Pentium, Core Duo, … –AMD: Bulldozer, Athlon, Opteron, … –Motorola: 68000, PowerPC,… –ARM: ARM11, Cortex, ARM3,… CPUs (Processors) may speak different languages.
8
The CPU Understands only one language
10
What does a Java program look like?
11
// calculates pounds of C02 emitted by a gasoline powered automobile public class CO2Calculator { public static void main(String[] args) { int milesDriven = 360; double mpg = 24.5; double gallonsUsed, co2Used; double emissionsFactor = 19.6; // calculate gallons of fuel used gallonsUsed = milesDriven/mpg; // calculate and display pounds of C02 emitted co2Used = gallonsUsed * emissionsFactor; System.out.println("You used " + co2Used + " pounds of C02”); }
12
ClassA methodOne methodTwo statement1 statement2 statement3 program structure ClassB
13
public class C02Calculator {}{} // comments about the class class header class body Java code
14
public class C02Calculator {}{} public static void main (String[] args) {}{} // comments about the class // comments about the method method header method body Java code
15
public class C02Calculator {}{} public static void main (String[] args) {}{} Reserved words
16
Java reserved words abstract boolean break byte case catch char class const continue default do double else extends false final finally float for goto if implements import instanceof int interface long native new null package private protected public return short static strictfp super switch synchronized this throw throws transient true try void volatile while
17
public class C02Calculator {}{} public static void main (String[] args) {}{} Identifiers
18
Rules for Identifiers An identifier can be made up of letters, digits, the underscore character ( _ ), and the dollar sign ( $ ) Identifiers cannot begin with a digit Java is case sensitive - Total, total, and TOTAL are different identifiers By convention, Java programmers use different case styles for different types of identifiers, such as –title case for class names - Lincoln –upper case for constants - MAXIMUM
19
Identifying identifiers: is it valid or not? class CLASS 1time abc123 bank-account bank_account $hello
20
Variables 0x000 0x001 0x002 0x003 0x004 0x005 0x006 0x007 int milesDriven = 360; 360 variable milesDriven is a symbolic name for the memory location 0x003. memoryJava code
21
How do I go about writing a program?
22
compile execute edit
23
Program Development Process Text editor Source code (.java ) Saves Java statements
24
Text Editor: Atom
26
Program Development Process Text editor Source code (.java ) Java compiler Is read by Byte code (.class ) Produces
27
Java Compiler: javac
28
Program Development Process Text editor Source code (.java ) Java compiler Byte code (.class ) Java Virtual Machine Is interpreted by Program Execution Results in
29
Java Interpreter: java
30
compilation/syntax errors
31
logic errors
32
Let’s give it a try…
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.