Introduction to Java Programming What is Java What














![Reserved words public class C 02 Calculator { public static void main (String[] args) Reserved words public class C 02 Calculator { public static void main (String[] args)](https://slidetodoc.com/presentation_image_h2/2b33a21c49626a61c0826cdbd5087c52/image-15.jpg)

![Identifiers public class C 02 Calculator { public static void main (String[] args) { Identifiers public class C 02 Calculator { public static void main (String[] args) {](https://slidetodoc.com/presentation_image_h2/2b33a21c49626a61c0826cdbd5087c52/image-17.jpg)















- Slides: 32

Introduction to Java Programming

What is Java? What does a Java program look like? How do I go about writing a Java program?

What is Java?

Java is an object-oriented programming language developed at Sun Microsystems in 1995.

Algorithm Program

Automobile C 02 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 CO 2 used (gallons of fuel used times the emissions factor of 19. 6) Display gallons of fuel and CO 2 used algorithm

CPU: Central Processing Unit • The “brain” of the computer. • Types: – – Intel: Core i 5, Core i 7, Pentium, Core Duo, … AMD: Bulldozer, Athlon, Opteron, … Motorola: 68000, Power. PC, … ARM: ARM 11, Cortex, ARM 3, … • CPUs (Processors) may speak different languages.

The CPU Understands only one language


What does a Java program look like?

// calculates pounds of C 02 emitted by a gasoline powered automobile public class CO 2 Calculator { public static void main(String[] args) { int miles. Driven = 360; double mpg = 24. 5; double gallons. Used, co 2 Used; double emissions. Factor = 19. 6; // calculate gallons of fuel used gallons. Used = miles. Driven/mpg; // calculate and display pounds of C 02 emitted co 2 Used = gallons. Used * emissions. Factor; System. out. println("You used " + co 2 Used + " pounds of C 02”); } }

program structure Class. A method. One statement 1 statement 2 statement 3 method. Two Class. B

Java code // comments about the class public class C 02 Calculator { class header class body }

Java code // comments about the class public class C 02 Calculator { // comments about the method public static void main (String[] args) { method body } } method header
![Reserved words public class C 02 Calculator public static void main String args Reserved words public class C 02 Calculator { public static void main (String[] args)](https://slidetodoc.com/presentation_image_h2/2b33a21c49626a61c0826cdbd5087c52/image-15.jpg)
Reserved words public class C 02 Calculator { public static void main (String[] args) { } }

Java reserved words abstract boolean break byte case catch char class const continue default do double else extends false finally float for goto if implements import instanceof interface long native new null package private protected public return short static strictfp super switch synchronized this throws transient true try void volatile while
![Identifiers public class C 02 Calculator public static void main String args Identifiers public class C 02 Calculator { public static void main (String[] args) {](https://slidetodoc.com/presentation_image_h2/2b33a21c49626a61c0826cdbd5087c52/image-17.jpg)
Identifiers public class C 02 Calculator { public static void main (String[] args) { } }

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

Identifying identifiers: is it valid or not? class CLASS 1 time abc 123 bank-account bank_account $hello

Variables memory 0 x 000 0 x 001 0 x 002 0 x 003 0 x 004 0 x 005 0 x 006 0 x 007 Java code int miles. Driven = 360; 360 variable miles. Driven is a symbolic name for the memory location 0 x 003.

How do I go about writing a program?

edit compile execute

Program Development Process Text editor Saves Java statements Source code (. java)

Text Editor: Atom


Program Development Process Text editor y b d a Is re Java compiler Produces Source code (. java) Byte code (. class)

Java Compiler: javac

Program Development Process Text editor Source code (. java) Java compiler Byte code (. class) by d e t re p r e t s in I Java Virtual Machine Results in Program Execution

Java Interpreter: java

compilation/syntax errors

logic errors

Let’s give it a try…