Introduction to Programming in Java

Slides:



Advertisements
Similar presentations
Today’s lecture Review of Chapter 1 Go over homework exercises for chapter 1.
Advertisements

Air Force Institute of Technology Electrical and Computer Engineering
1 pritisajja.info Unlocking the World of Java Programming….. Priti Srinivas Sajja February, 2014 Visit pritisajja.info for detail Future Technology for.
Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
1 Java Basics. 2 Compiling A “compiler” is a program that translates from one language to another Typically from easy-to-read to fast-to-run e.g. from.
Shlomo Hershkop1 Introduction to java Class 1 Fall 2003 Shlomo Hershkop.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Computer Science A 2: 6/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
DAT602 Database Application Development Lecture 5 JAVA Review.
General Features of Java Programming Language Variables and Data Types Operators Expressions Control Flow Statements.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
1 Programming Java Java Basics. 2 Java Program Java Application Program Application Program written in general programming language Applet Program running.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs -
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Developed at Sun Microsystems in 1991 James Gosling, initially named “OAK” Formally announced java in 1995 Object oriented and cant write procedural.
By Mr. Muhammad Pervez Akhtar
Reference Learning Java DDC publishing Herst, Yamauchi, Adler COP 3331 Object Oriented Analysis and Design Java Part I.
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
C++ Lesson 1.
Information and Computer Sciences University of Hawaii, Manoa
Key Words / Reserved Words
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Chapter 2 Basic Computation
Chapter 1.2 Introduction to C++ Programming
Lecture 2: Data Types, Variables, Operators, and Expressions
Internet and Java Foundations, Programming and Practice
Data types and variables
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 2 Basic Computation
Object-Oriented Programming
Statements, Comments & Simple Arithmetic
CET 3640 – Lecture 2 Java Syntax Chapters 2, 4, 5
Starting JavaProgramming
Introduction to Java Programming
An Introduction to Java – Part I, language basics
Chapter 1: Computer Systems
Introduction to Primitive Data types
Expressions and Assignment
elementary programming
Focus of the Course Object-Oriented Software Development
Chapter 3 Selections Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Primitive Types and Expressions
Agenda Types and identifiers Practice Assignment Keywords in Java
Control Structure.
Variables and Constants
Introduction to Primitive Data types
JAVA. Java is a high-level programming language originally developed by Sun Microsystems and released in Java runs on a variety of platforms, such.
Presentation transcript:

Introduction to Programming in Java AP Computer Science A Dr. Persin www.Lnk2Lrn.com

Contents History First Java Application Data types Variables Strings Assignments Math, Boolean expressions Relational operations If statements System.exit www.Lnk2Lrn.com

Very Brief History Started in 1991 by SUN Microsystems Targeted at consumer electronics. Wanted reliable programming language. Integrated into browsers Evolved into write once run anywhere, integrates into Netscape General purpose libraries released www.Lnk2Lrn.com

Basic Definitions Java is an object oriented language. Object Method Class Applications Applets Native classes Threads Exceptions www.Lnk2Lrn.com

First Application /** *Hello World, first application, only output. */ public class hello{ public static void main (String [] args) { System.out.println(“Hello World”); } //end main }//end class www.Lnk2Lrn.com

Notice: Java is CASE SENSITIVE!! Whitespace is ignored by compiler Whitespace makes things easier to read…hence it affects your grade  File name has to be the same as class name in file. Need to import necessary class definitions www.Lnk2Lrn.com

Variables Variables: Naming: Name Type Value May contain numbers,underscore,dollar sign, or letters Can not start with number Can be any length Reserved keywords Case sensitive www.Lnk2Lrn.com

Primitive data types Byte 8 -27 27-1 Short 16 -215 215-1 Int 32 -231 231-1 Long 64 Float Double Boolean 1 Char www.Lnk2Lrn.com

Assignment = Example: int n; n = 10; or int n = 10; //same www.Lnk2Lrn.com

Strings Not a primitive class, its actually something called a wrapper class To find a built in class’s method use API documentation. String is a group of char’s A character has single quotes char c = ‘h’; A String has double quotes String s = “Hello World”; Method length int n = s.length; www.Lnk2Lrn.com

Using Strings public class hello{ public static void main (String [] args) { String s = “Hello World”; System.out.println(s); //output simple string } //end main }//end class hello www.Lnk2Lrn.com

Math Unary Regular math (+,-,*,/) % modulo operator int x = -9; int y = 3+x; % modulo operator www.Lnk2Lrn.com

Incrementing Increment and Decrement i++ equivalent to i = i + 1; Can also do ++i, which uses i before incrementing it. Decrementing: i--; www.Lnk2Lrn.com

Casting int n = 40; Wrong : byte b = n; why?? Right: byte b = (byte) n; Type casting converts to target type www.Lnk2Lrn.com

Casting II Type char is stored as a number. The ASCII value of the character. A declaration of : char c = ‘B’; stores the value 66 in location c can use its value by casting to int how?? www.Lnk2Lrn.com

Assignment += -= *= /= %= www.Lnk2Lrn.com

Boolean Expressions boolean b b will be either true (1) or false (0) Logical operations: !(not), && (and) || (or) boolean a,b; a = true; b = false; System.out.println (“a && b is “ + (a && b)); www.Lnk2Lrn.com

Relational Operators == equality != inequality > greater than < less than >= greater than or equal to <= less than or equal to www.Lnk2Lrn.com

The if - branching statement if ( x < y) { x = y; } if ( x < y ) { x = y; } else { x = 88; } www.Lnk2Lrn.com

If/Else if (logic condition) { something } else if (logic condition) { something } else { something else } www.Lnk2Lrn.com

Nested IF if ( x < 0 ) { System.out.println( “ x is negative “ ); } else { if ( x > 0 ) { System.out.println ( “x is positive” ); } //end if x > 0 else { System.out.println ( “x is zero “ ); } } //end else x >=0 www.Lnk2Lrn.com

Switch/Case Switch(variable){ case(1): something; break; default: something; } www.Lnk2Lrn.com

Exceptions Java exception object. java.io.Exception most general one. Some exception like in Throwable class define methods to get the message. www.Lnk2Lrn.com

try….catch blocks. Try { ……. } catch ( IOException v) { ………. } www.Lnk2Lrn.com

System.out.println println is a method in the Printstream class. Defined: public void println(String x) can be any type of string or combination string using addition to join parts. Example: println(“hello “ + “world “ + x); www.Lnk2Lrn.com

System.exit() One method in java.lang.System Defined: public static void exit ( int status) Terminates currently running Java VM Status is status code, non zero will usually mean something abnormal. Used at end to indicate success, or in middle to signal problems. For more practice go to http://www.javabat.com www.Lnk2Lrn.com