By Mr. Muhammad Pervez Akhtar

Slides:



Advertisements
Similar presentations
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Advertisements

1 pritisajja.info Unlocking the World of Java Programming….. Priti Srinivas Sajja February, 2014 Visit pritisajja.info for detail Future Technology for.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
Some basic I/O.
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
JavaScript, Fourth Edition
Review Java.
JavaScript, Third Edition
Hello, world! Dissect HelloWorld.java Compile it Run it.
Introduction to programming Language C, Data Types, Variables, Constants. Basics of C –Every program consists of one or more functions and must have main.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
1 2 2 Introduction to Java Applications Introduction Java application programming –Display messages –Obtain information from the user –Arithmetic.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
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.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
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.
Chapter 2: Java Fundamentals
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.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
An introduction to Java Primitive Java– Chapter 1.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
A Sample Program public class Hello { public static void main(String[] args) { System.out.println( " Hello, world! " ); }
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
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 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.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
Information and Computer Sciences University of Hawaii, Manoa
Definition of the Programming Language CPRL
The Machine Model Memory
Working with Java.
Crash course in the Java Programming Language
Yanal Alahmad Java Workshop Yanal Alahmad
Java Programming: From Problem Analysis to Program Design, 4e
Statements, Comments & Simple Arithmetic
Fundamentals of Java Programs, Input/Output, Variables, and Arithmetic
CET 3640 – Lecture 2 Java Syntax Chapters 2, 4, 5
Starting JavaProgramming
Basics of ‘C’.
Chapter 2: Basic Elements of Java
Group Status Project Status.
MSIS 655 Advanced Business Applications Programming
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
elementary programming
Introduction to Java Applications
Presentation transcript:

By Mr. Muhammad Pervez Akhtar

 The general environment  The first program  Comments, Main, Terminal Output  Primitive types  Primitive types, Constants, Declaration and Initialization, Terminal Input and Output  Basics Operators  Assignment Operators, Binary Arithmetic Operators, Unary Operators, Type Conversion Operators

 Conditional Statements  Relational and equality operators, Logical operators, The if statement, The while statement, The for statement, The do statement, break and continue, The switch statement, The conditional operator  Methods  Overloading of method names  Storage classes

 Java Source code resides in files whose names end with the.java suffix  The local compiler, javac, compiles the program and generates.class files, which contain bytecode  Java bytecodes represent the portable intermediate language that is interpreted by running the Java interpreter, java.  The interpreter is also known as the Virtual Machine  Java programs, input can come from one of many places:  Standard input, Command Line Arguments, A File, GUI Component

 Save program as FirstProgram.java  Compile program as javac FirstProgram.java  Run program as javac FirstProgram  Four things to note in program  Comments, class, main method, standard output

 Comments are non-compiled and non- executable code  Three types of comments  // : single line comment, inherited from C  /*…*/: multi line comments inherited from c  /**…*/: information for javadoc utility to generate documentation form comments  Why Comments are needed?  Make code easier for humans to read  Helps programmers to modify the program  Commented program is a good sign of programmer

 Java program consists of interacting classes which contain methods and data elements  Methods can be invoked using object of its class  Static method can be invoked without object of its class  Public static void main(String args[]) is special method with void return type, command line argument, public access modifier and is static  It is the method that executes first of all

 System.out.println: is the primary output mechanism in java  Also called standard output (output on console)  System.out.print: is another way of output  println vs print  println shifts control to start of next line after output  but print does not shifts control to next line  Can output integer, floating point, string, or some other type

 Integer constants can be represented in either decimal, octal, or hexadecimal notation  Octal notation is indicated by a leading 0; hexadecimal is indicated by a leading 0x or 0X  Equivalent ways of representing the integer 37: 37,045,0x25 ::Decimal, Octal and Hexa  Character constant is enclosed with a pair of single quotation marks, as in 'a‘  Internally, this character sequence is interpreted as a small number  String constant consists of a sequence of characters enclosed within double quotation marks, as in "Hello"

 Escape sequence is a constant but with special meanings  It starts with a ‘\’ backslash followed by a character to print  Followings are commonly used:  ‘\n’New line character  ‘\\’Backslash character  ‘\’’Single quotation mark  ‘\”’Double quotation mark

 A primitive type, is declared by providing its type, its name, and optionally its initial value  Type should be primitive type (int, float etc)  The name must be an identifier, that consists of:  Any combination of letters, digits, and the under- score character but it not start with a digit  Reserved words are not allowed  Not reuse identifier names that are already visibly used  Are case sensitive, age or Age are different

 Basic formatted terminal I/O is accomplished by nextLine and println  The standard input stream is System.in  The standard output stream is System.out  Formatted I/O uses the String type  + combines two Strings  If one of the argument is not a String, a temporary String is created for it if it is a primitive type  For input, we associate a Scanner object with System.in.  Scanner has different methods for different primitive types

 Operators are symbols to perform an operation  Operators are used to form expressions  Expression is combination of variables, constants and operators  Following are the types of operators  Assignment Operators =, +=, -=, *=, /=  Binary Arithmetic Operators +, -, *, /, %  Unary Operators ++, --, - ::prefix or postfix use  Type Conversion Operators Generate a temporary entity of a new type

 Statements that affect the flow of control  Relational and Equality operators , >=, ==, !=  Logical Operators  AND, OR, NOT or conjunction, disjunction and negation respectively  &&, ||, ! Is another representation  ! Has highest precedence and && has higher precedence than ||  && and || called short-circuit operators

 The IF, IF THAN ELSE statement  Two common mistakes  Loops the While, For, and Do statements

 Break and Continue statements  Break statement terminate execution in the middle of a repeated statements (loop)  Continue Statement Give up on the current iteration of a loop and go on to the next iteration

 Switch Statement  Suitable when multiple branches against one Condition  The conditional operator  a shorthand for simple if-else statements  testExpr ? yesExpr : noExpr

 Known as a function or procedure :: main()  A method header consists of a name, a (possibly empty) list of parameters, and a return type  The actual code to implement the method, sometimes called the method body  A method declaration consists of a header plus the body  Overloading of method  Several methods may have the same name and be declared in the same class scope as long as their signatures(that is, their parameter list types) differ.

 Local Variables:  Entities that are declared inside the body of a method are local variables  Can be accessed by name only within the method body  Global Variables  A variable declared outside the body of a method is global to the class  if the word static is used, is similar to global variables in other languages  Static Final Variable  If both static and final are used, they are global symbolic constants