1 Programming Java Java Basics. 2 Java Program Java Application Program Application Program written in general programming language Applet Program running.

Slides:



Advertisements
Similar presentations
1 pritisajja.info Unlocking the World of Java Programming….. Priti Srinivas Sajja February, 2014 Visit pritisajja.info for detail Future Technology for.
Advertisements

Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
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.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
Java Syntax Primitive data types Operators Control statements.
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
CS 225 Java Review. Java Applications A java application consists of one or more classes –Each class is in a separate file –Use the main class to start.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
Review Java.
Chapter 2 - Java Programming Fundamentals1 Chapter 2 Java Programming Fundamentals.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
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.
Java Building Elements Lecture 2 Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University
DAT602 Database Application Development Lecture 5 JAVA Review.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Sales person receive RM200/week plus 9% of their gross sales for that week. Write an algorithms to calculate the sales person’s earning from the input.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
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.
CS591x A very brief introduction to Java. Java Developed by Sun Microsystems was intended a language for embedded applications became a general purpose.
Java 2 More Java Then Starbucks ;-). Important Terms Primitive Data – Basic, built-in values (characters & numbers) Data Type – Used to talk about values.
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 Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Java Programming: From Problem Analysis to Program Design, 5e Chapter 2 Basic Elements of Java.
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.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
By Mr. Muhammad Pervez Akhtar
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Java Computer Industry Lab. 1 Programming Java Java Basics Incheon Paik.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
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.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
 Array ◦ Single & Multi-dimensional  Java Operators ◦ Assignment ◦ Arithmetic ◦ Relational ◦ Logical ◦ Bitwise & other.
Object Oriented Programming Lecture 2: BallWorld.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
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.
Key Words / Reserved Words
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
JAVA MULTIPLE CHOICE QUESTION.
Programming in Java Sachin Malhotra, Chairperson, PGDM-IT, IMS Ghaziabad Saurabh Chaudhary, Dean, Academics, IMS Ghaziabad.
Yanal Alahmad Java Workshop Yanal Alahmad
Java Programming: From Problem Analysis to Program Design, 4e
Introduction to Programming in Java
CET 3640 – Lecture 2 Java Syntax Chapters 2, 4, 5
Starting JavaProgramming
Principles of Computer Programming (using Java) Chapter 2, Part 1
An Introduction to Java – Part I, language basics
Chapter 2 Edited by JJ Shepherd
An overview of Java, Data types and variables
Chapter 2: Basic Elements of Java
The Building Blocks Classes: Java class library, over 1,800 classes:
Chapter 2 Programming Basics.
Primitive Types and Expressions
Review of Java Fundamentals
Presentation transcript:

1 Programming Java Java Basics

2 Java Program Java Application Program Application Program written in general programming language Applet Program running in Web Browser Environment Can be viewed by appletviewer or Web browser with JVM

3 Classes and Objects Object Memory Space to Define State and Operation Instance of Class Class Template of Creating Object

4 The Java Class Libraries java.applet : Applet related java.awt : Abstract Window Toolkit java.awt.event : Event process from awt component java.awt.image : Image processing java.beans : JavaBeans Component java.io : File or Network I/O Support java.lang : Java Language Support java.net : Network related functions java.util : Utility function

5 Variables and Assignments Variables Types char 16bits Unicode character data boolean Boolean Variable byte 8 bits signed integer short 16 bits signed integer int 32 bits signed integer long 64 bits signed integer float 32 bits signed floating point number double 64 bits signed floating point number

6  Primitive data types Byte Short Int Long64 Float32 Double64 Boolean101 Char16

7  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

8 Variables and Assignments int num = 100; long m = L double type : e e-5 float type : 1.5e-3f; Variable Declaration type varName; Value assignments varName = value; float x, y, x;

9 Type Conversions in Expression char ch; int i; float f; double outcome; ch = ‘0’; i = 10; f = 10.2f; outcome = ch * i / f; int float double

10 Type Conversions in Assignment Widening Conversion byte b = 127; int i; i = b; Narrowing Conversion byte b; int i = 258; b = (byte) i; Wrong Conversion byte b; int i = 127; b = i; Right Conversion (But data may be lost) byte b; int i = 127; b = (byte) i; Type Casting

11  Assignment = Example: int n; n = 10; or int n = 10; //same

12  Assignment += -= *= /= %=

13 Arithmetic Operators Operators + - * / % += -= *= /= %= / 2  2 Why isn’t it 2.5 ? 5 % 2  1 4 / 2  2 4 % 2  0 count * num + 88 / val – 19 % count j += 6;  j = j + 6;

14  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));

15  Relational Operators ==equality !=inequality >greater than <less than >=greater than or equal to <=less than or equal to

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

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

18  If/Else if (logic condition) { something } else if (logic condition) { something } else { something else }

19  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

20

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

22

23 Comments Single Line Comment int i = 10 ; // i is counter Multiple Line Comment /* Some comments */ Documentation Comment /** Documentation Comment */ Using “javadoc” Tool, make document

24 Arrays ( One Dimensional) type VarName[] Definition of One Dimensional Array int ia[]; varName = new type[size] Assign Range to One Dimensional Array ia = new int[10]; type varName[] = new type[size] Declaration of One Dimensional Array with Range int ia[] = new int[10];

25 Arrays ( One Dimensional) varName.length Number of elements in Array Type varName[] = {e0, …, en}; Initialization of One Dimensional Array int j[] = {0, 1, 2, 3, 4, 5}; int k[]; K = j; Example 1.15

26 Arrays ( Multi-Dimensional) type VarName[][]; Definition of Two Dimensional Array float fa[][]; varName = new type[size1][size2]; Assign Range to Two Dimensional Array fa = new float[2][3]; type varName[][] = new type[size1][size2]; Declaration of Two Dimensional Array with Range float fa[] = new float[2][3];

27 Arrays ( Two Dimensional) varName.length Number of elements in Multi-Dimensional Array Type varName[][] = {{e00, …, e0n}, {e10, …,e1y}, {e20, …, e2z}}; Initialization of Multi-Dimensional Array Example 1.16 varName[index].length Number of elements in Each elements of Multi-Dimensional Array Number of Raw

28 Java Keywords 50 Java Keywords abstractdoubleintsuper booleanelseinterfaceswitch breakextendslong synchronized bytefinalnativethis casefinallynewthrow catchfloatpackagethrows charforprivatetransient* classgoto*protectedtry const*ifpublicvoid continueimplementsreturnvolatile defaultimportshortwhile doinstanceofstatic strictfp assert (New in 1.5) enum (New in 1.5) The “assert” is recognized as keyword in JDK1.4 compiler, but we could not use it. It can be used it from 1.5.

29  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

30  How to get it running Text in hello.java file Why? To compile: javac hello.java To run: java hello

31  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