Shlomo Hershkop1 Introduction to java 3101-003 Class 1 Fall 2003 Shlomo Hershkop.

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.
Programming with Java. Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: –Understand the.
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.
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.
Libraries Programs that other people write that help you. #include // enables C++ #include // enables human-readable text #include // enables math functions.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.
DAT602 Database Application Development Lecture 5 JAVA Review.
General Features of Java Programming Language Variables and Data Types Operators Expressions Control Flow Statements.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Introduction to Computer Systems and the Java Programming Language.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
CS591x A very brief introduction to Java. Java Developed by Sun Microsystems was intended a language for embedded applications became a general purpose.
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.
Chapter 2: Java Fundamentals
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.
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.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
COMP Primitive and Class Types Yi Hong May 14, 2015.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
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
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,
Object Oriented Programming Lecture 2: BallWorld.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
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.
CompSci 230 S Programming Techniques
Information and Computer Sciences University of Hawaii, Manoa
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Crash course in the Java Programming Language
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
Introduction to Programming in Java
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
Expressions and Assignment
Focus of the Course Object-Oriented Software Development
Primitive Types and Expressions
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:

Shlomo Hershkop1 Introduction to java Class 1 Fall 2003 Shlomo Hershkop

2 Welcome History First Java Application Data types Variables Strings Assignments Math, Boolean expressions Relational operations If statements System.exit

Shlomo Hershkop3 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

Shlomo Hershkop4 Course Information Textbook: Java in a Nutshell Reading class 1 chapters 1,2

Shlomo Hershkop5 Basic Definitions Java is an object oriented language. –Object –Method –Class –Applications –Applets –Native classes –Threads –Exceptions

Shlomo Hershkop6 First Application /** *Hello World, first application, only output. */ import java.io.*; public class hello{ public static void main (String [] args) { System.out.println(“Hello World\n”); } //end main }//end class

Shlomo Hershkop7 How to get it running Text in hello.java file –Why? To compile: –javac hello.java To run: –java hello

Shlomo Hershkop8 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

Shlomo Hershkop9 Variables Variables: –Name –Type –Value Naming: –May contain numbers,underscore,dollar sign, or letters –Can not start with number –Can be any length –Reserved keywords –Case sensitive

Shlomo Hershkop10 Primitive data types Byte Short Int Long64 Float32 Double64 Boolean101 Char16

Shlomo Hershkop11 Assignment = Example: int n; n = 10; or int n = 10; //same

Shlomo Hershkop12 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;

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

Shlomo Hershkop14 Math Unary int x = -9; Regular math (+,-,*,/) int y = 3+x; % modulo operator

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

Shlomo Hershkop16 Casting int n = 40; Wrong : byte b = n; why?? Right: byte b = (byte) n; Type casting converts to target type

Shlomo Hershkop17 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??

Shlomo Hershkop18 Assignment += -= *= /= %=

Shlomo Hershkop19 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));

Shlomo Hershkop20 Relational Operators ==equality !=inequality >greater than <less than >=greater than or equal to <=less than or equal to

Shlomo Hershkop21 The if - branching statement if ( x < y) { x = y; } if ( x < y ) { x = y; } else { x = 88; }

Shlomo Hershkop22 If/Else if (logic condition) { something } else if (logic condition) { something } else { something else }

Shlomo Hershkop23 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

Shlomo Hershkop24 Switch/Case Switch(variable){ case(1): something; break; case(23): something; break; default:something; }

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

Shlomo Hershkop26 try….catch blocks. Try { ……. } catch ( IOException v) { ………. }

Shlomo Hershkop27 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);

Shlomo Hershkop28 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.