Introduction to-programming

BG Java EE Course
BG Java EE Course Manager, Technical Training at BG Java EE Course
Introduction to Java Programming
Contents ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Contents ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Programming in Java
The Java API ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What is Java API Documentation? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Java API Documentation
A Java Program
The Java Programming Language ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Writing Java Programs ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Java Program – Example public class HelloJava { public static void main(String[] args) { System.out.println("Hello, Java!"); } } HelloJava.java javac HelloJava.java java –cp . HelloJava Hello, Java!
Typical Errors ,[object Object],[object Object],[object Object],[object Object]
Typical Errors ,[object Object],[object Object],[object Object]
Structure of Java Programs
The Source File Contents ,[object Object],[object Object],[object Object],[object Object],package jeecourse.example; import java.io.*; public class SomeClass { // ... }
Classes and Packages ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Important Java Packages ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Java Programs ,[object Object],[object Object],[object Object],[object Object],[object Object],public static void main(String[] args)
Programs, Classes, and Packages – Example package jeecourse.example; import java.io.*; public class SomeClass { private static int mValue = 5; public static void printValue() { System.out.println("mValue = " + mValue); } public static void main(String[] args) { System.out.println("Some Class"); printValue(); } }
Keywords, Identifiers, Data Types
Keywords ,[object Object],[object Object],[object Object]
Java Language Keywords abstract  continue  for  new  switch  assert   default  goto    package  synchronized  boolean  do  if  private  this  break  double  implements  protected  throw  byte  else  import  public  throws  case  enum   instanceof  return  transient  catch  extends  int  short  try  char  final  interface  static  void  class  finally  long  strictfp   volatile  const    float  native  super  while
Reserved Words ,[object Object],[object Object],[object Object]
Identifiers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Primitive Data Types ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Primitive Data Types ,[object Object],[object Object],Type Effective Size (bits) byte 8 short 16 int 32 long 64 float 32 double 64 char 16
Boolean Type ,[object Object],[object Object],[object Object],[object Object]
Textual Types:  char ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Integral Types:  byte ,  short ,  int , and  long ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],long value = 1234L;
Ranges of the Integral Primitive Types Type Size Minimum Maximum byte 8 bits -2 7 2 7  – 1 short 16 bits -2 15 2 15  – 1 int 32 bits -2 31 2 31  – 1 long 64 bits -2 63 2 63  – 1
Floating Point Types:  float  and  double ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Ranges of the Floating-Point Primitive Types Type Size Minimum Maximum float 32 bits +/- 1.40 -45 +/- 3.40 +38 double 64 bits +/- 4.94 -324 +/- 1.79 +308 char 16 bits 0 2 16  - 1
Non-numeric Floating-Point Values ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Textual Types: String ,[object Object],[object Object],[object Object],[object Object],[object Object],String greeting = "Good Morning !! "; String errorMsg = "Record Not Found!"; "The quick brown fox jumps over the lazy dog."
Values and Objects ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Values vs. Objects ,[object Object],[object Object],int x = 7; int y = x; String s = "Hello"; String t = s; 7 x 7 y 0x01234567 s 0x01234567 t "Hello" 0x01234567 Heap (dynamic memory)
Enumerations (enums) ,[object Object],[object Object],[object Object],[object Object],public enum Color { WHITE, RED, GREEN, BLUE, BLACK } ... Color c = Color.RED;
Enumerations (enums) ,[object Object],switch (color) { case WHITE:  System.out.println("бяло");  break; case RED:  System.out.println("червено");  break; ... } if (color == Color.RED) { ... }
Variables, Declarations, Assignments, Operators
Variables, Declarations, and Assignments ,[object Object],[object Object],[object Object],[object Object],[object Object],int i; // declare variable int value = 5; // declare and assign variable i = 25; // assign a value to a variable that is already declared
Variables, Declarations, and Assignments – Examples  public class Assignments { public static void main(String args []) { int x, y; // declare int variables float z = 3.414f; // declare and assign float double w = 3.1415; // declare and assign double boolean b = true; // declare and assign boolean char ch; // declare character variable String str; // declare String variable String s = "bye"; // declare and assign String ch = 'A'; // assign a value to char variable str = "Hi out there!"; // assign value to String x = 6; // assign value to int variable y = 1000; // assign values to int variable ... } }
Variables and Scope ,[object Object],[object Object],[object Object],[object Object]
Operators Category Operators Unary ++  --  +  -  !  ~  (type) Arithmetic *  /  % +  - Shift <<  >>  >>> Comparison <  <=  >  >=  instanceof ==  != Bitwise &  ^  | Short-circuit &&  || Conditional ? : Assignment =  op=
The Ordinal Comparisons Operators: <, <=, >, and >= ,[object Object],[object Object],[object Object],[object Object],[object Object]
The Ordinal Comparisons Operators – Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Short-Circuit Logical Operators ,[object Object],[object Object],MyDate d = null; if ((d != null) && (d.day() > 31)) { // Do something } boolean goodDay = (d == null) || ((d != null) && (d.day() >= 12));
String Concatenation with + ,[object Object],[object Object],[object Object],[object Object],[object Object],String salutation = &quot;Dr. &quot;; String name = &quot;Pete &quot; + &quot;Seymour&quot;; System.out.println(salutation + name + 5);
The Unary Operators ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Cast Operator: (type) ,[object Object],[object Object],[object Object],[object Object],[object Object],int circum = (int)(Math.PI * diameter);
The Multiplication and Division Operators: * and / ,[object Object],[object Object],int a = 5; int value = a * 10;
The Bitwise Operators ,[object Object],[object Object],int first = 100; int second = 200; int xor = first ^ second; int and = first & second;
Operator Evaluation Order ,[object Object],[object Object],[object Object],[object Object],int[] a = {4, 4}; int b = 1; a[b] = b = 0;
Expressions and Statements
Expressions ,[object Object],int r = (150-20) / 2 + 5; // Expression for calculation of // the surface of the circle double surface = Math.PI * r * r; // Expression for calculation of // the perimeter of the circle double perimeter = 2 * Math.PI * r;
Statements ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Statements and Blocks ,[object Object],[object Object],[object Object],salary = days * daySalary; { x = x + 1; y = y + 1; }
Conditional Statements  ,[object Object],if (boolean condition) { statement or block; } if (boolean condition) { statement or block; } else { statement or block; }
If Statement – Example public static void main(String[] args) { int radius = 5; double surface = Math.PI * radius * radius; if (surface > 100) { System.out.println(&quot;The circle is too big!&quot;); } else if (surface > 50) { System.out.println( &quot;The circle has acceptable size!&quot;); } else { System.out.println( &quot;The circle is too small!&quot;); } }
Conditional Statements ,[object Object],switch (expression) { case constant1: statements; break; case constant2: statements; break; default: statements; break; }
The  switch  Statement – Example int dayOfWeek = 3; switch (dayOfWeek) { case 1: System.out.println(&quot;Monday&quot;); break; case 2: System.out.println(&quot;Tuesday&quot;); break; ... default: System.out.println(&quot;Invalid day!&quot;); break; }
Looping Statements ,[object Object],[object Object],for (init_expr; boolean testexpr; alter_expr) { statement or block; } for (int i = 0; i < 10; i++) { System.out.println(&quot;i=&quot; + i); } System.out.println(&quot; Finished !&quot;)
Looping Statements ,[object Object],[object Object],for ( Type variable : some collection ) { statement or block; } public static void main(String[] args) { String[] towns = new String[] { &quot;Sofia&quot;, &quot;Plovdiv&quot;, &quot;Varna&quot; }; for (String town : towns) { System.out.println(town); } }
Looping Statements ,[object Object],[object Object],while (boolean condition) { statement or block; } int i=100; while (i>0) { System.out.println(&quot;i=&quot; + i); i--; } while (true) { // This is an infinite loop }
Looping Statements ,[object Object],[object Object],do { statement or block; } while (boolean condition); public static void main(String[] args) { int counter=100; do { System.out.println(&quot;counter=&quot; + counter); counter = counter - 5; } while (counter>=0); }
Special Loop Flow Control ,[object Object],[object Object],[object Object],[object Object],[object Object],for (int counter=100; counter>=0; counter-=5) { System.out.println(&quot;counter=&quot; + counter); if (counter == 50) break; }
Special Loop Flow Control – Examples ,[object Object],for (int counter=100; counter>=0; counter-=5) { if (counter == 50)  { continue ; } System.out.println(&quot;counter=&quot; + counter); }
Special Loop Flow Control – Examples ,[object Object],outerLoop: for (int i=0; i<50; i++) { for (int counter=100; counter>=0; counter-=5) { System.out.println(&quot;counter=&quot; + counter); if ((i==2) && (counter == 50))  { break outerLoop; } } }
Comments ,[object Object],// comment on one line /* comment on one or more lines */ /** documenting comment */
Console Input and Output
Console Input/Output ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Printing to the Console ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],System.out.print(3.14159); System.out.println(&quot;Welcome to Java&quot;); int i=5; System.out.println(&quot;i=&quot; + i);
Reading from the Console ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Scanner in = new Scanner(System.in);
Reading from the Console ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Scanner – Example  import java.util.Scanner; public class ScannerDemo { public static void main(String[] args) { Scanner console = new Scanner(System.in); // Get the first input System.out.print(&quot;What is your name? &quot;); String name = console.nextLine(); // Get the second input System.out.print(&quot;How old are you? &quot;); int age = console.nextInt(); // Display output on the console System.out.println(&quot;Hello, &quot; + name + &quot;. &quot; +  &quot;Next year, you'll be &quot; + (age + 1)); } }
Formatting Output ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],String name = &quot;Nakov&quot;; int age = 25; System.out.printf( &quot;My name is %s.I am %d years old.&quot;, name, age);
Arrays and Array Manipulation
Creating Arrays ,[object Object],[object Object],[object Object],[object Object],[object Object]
Array Declaration ,[object Object],[object Object],[object Object],int[] ints; Dimensions[] dims; float[][] twoDimensions;  int ints[];
Array Construction ,[object Object],[object Object],[object Object],[object Object],int[] ints; // Declaration  ints = new int[25]; // Construction int[] ints = new int[25];
Array Initialization ,[object Object],[object Object],[object Object],[object Object]
Elements Initialization Element Type Initial Value byte 0 int 0 float 0.0f char ‘ 0000’ object reference null short 0 long 0L double 0.0d boolean false
Array Elements Initialization ,[object Object],[object Object],float[] diameters = {1.1f, 2.2f, 3.3f, 4.4f, 5.5f};
Access to Elements ,[object Object],[object Object],[object Object],int[] arr = new int[10]; arr[3] = 5; // Writing element int value = arr[3]; // Reading element int[] arr = new int[10]; int value = arr[10]; // ArrayIndexOutOfBoundsException
Arrays – Example // Finding the smallest and largest // elements in an array int[] values = {3,2,4,5,6,12,4,5,7}; int min = values[0]; int max = values[0]; for (int i=1; i<values.length; i++) { if (values[i] < min) { min = values[i]; } else if (values[i] > max) { max = values[i]; } } System.out.printf(&quot;MIN=%d&quot;, min); System.out.printf(&quot;MAX=%d&quot;, max);
M ulti-dimension al   A rrays ,[object Object],[object Object],[object Object],[object Object],int[][] matrix = new int[3][4]; matrix[1][3] = 42; int rows = matrix.length; int colsInFirstRow = matrix[0].length;
M ulti-dimension al   A rrays ,[object Object],[object Object],WRONG ! int[][] myInts = new int[3][4];
M ulti-dimension al   A rrays ,[object Object],CORRECT!
M ulti-dimension al   A rrays ,[object Object],[object Object],int[][] myInts = { {1, 2, 3}, {91, 92, 93, 94}, {2001, 2002} };
M ulti-dimension al   A rrays  – Example // Finding the sum of all positive // cells from the matrix int[][] matrix =  {{2,4,-3},  {8,-1,6}}; int sum = 0; for (int row=0; row<matrix.length; row++) { for (int col=0; col<matrix[row].length; col++) { if (matrix[row][col] > 0) { sum += matrix[row][col]; } } } System.out.println(&quot;Sum = &quot; + sum);
Questions ? Introduction to Java Programming
Exercises ,[object Object],[object Object],[object Object],[object Object],[object Object]
Exercises ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Exercises ,[object Object],[object Object],[object Object]
Exercises ,[object Object],[object Object],[object Object],[object Object]
Exercises ,[object Object],[object Object],[object Object],[object Object]
Exercises ,[object Object]
1 of 96

Recommended

Java Basics by
Java BasicsJava Basics
Java BasicsDhanunjai Bandlamudi
2.2K views37 slides
Core java by
Core javaCore java
Core javakasaragaddaslide
1.5K views56 slides
Java Basics by
Java BasicsJava Basics
Java Basicsshivamgarg_nitj
6.6K views53 slides
Java tutorial for Beginners and Entry Level by
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelRamrao Desai
3.4K views56 slides
Core java by
Core javaCore java
Core javaShivaraj R
334 views112 slides
Core Java Tutorials by Mahika Tutorials by
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsMahika Tutorials
1.4K views122 slides

More Related Content

What's hot

Java basic tutorial by sanjeevini india by
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaSanjeev Tripathi
584 views55 slides
Introduction to java 101 by
Introduction to java 101Introduction to java 101
Introduction to java 101kankemwa Ishaku
436 views77 slides
Java Tutorial by
Java TutorialJava Tutorial
Java TutorialSingsys Pte Ltd
1.9K views30 slides
JAVA BASICS by
JAVA BASICSJAVA BASICS
JAVA BASICSVEERA RAGAVAN
1.1K views74 slides
Object Oriented Programming with Java by
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with JavaJussi Pohjolainen
12.9K views105 slides
Core java by
Core java Core java
Core java Ravi varma
802 views137 slides

What's hot(17)

Java basic tutorial by sanjeevini india by Sanjeev Tripathi
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
Sanjeev Tripathi584 views
Object Oriented Programming with Java by Jussi Pohjolainen
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
Jussi Pohjolainen12.9K views
Core java by Ravi varma
Core java Core java
Core java
Ravi varma802 views
Core java complete ppt(note) by arvind pandey
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
arvind pandey5.9K views
OCP Java (OCPJP) 8 Exam Quick Reference Card by Hari kiran G
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
Hari kiran G7.8K views
Programming Fundamentals With OOPs Concepts (Java Examples Based) by indiangarg
Programming Fundamentals With OOPs Concepts (Java Examples Based)Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)
indiangarg1.1K views
Core java concepts by Ram132
Core java  conceptsCore java  concepts
Core java concepts
Ram13235.8K views
Java Tutorial by Vijay A Raj
Java TutorialJava Tutorial
Java Tutorial
Vijay A Raj34.3K views
Core java notes with examples by bindur87
Core java notes with examplesCore java notes with examples
Core java notes with examples
bindur87724 views
java: basics, user input, data type, constructor by Shivam Singhal
java:  basics, user input, data type, constructorjava:  basics, user input, data type, constructor
java: basics, user input, data type, constructor
Shivam Singhal4.8K views

Viewers also liked

Introduction to java by
Introduction to javaIntroduction to java
Introduction to javaVeerabadra Badra
185.4K views22 slides
Java tutorial PPT by
Java tutorial PPTJava tutorial PPT
Java tutorial PPTIntelligo Technologies
177.7K views55 slides
Introduction to Java Programming by
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java ProgrammingRavi Kant Sahu
31.2K views40 slides
Java programming course for beginners by
Java programming course for beginnersJava programming course for beginners
Java programming course for beginnersEduonix Learning Solutions
24.9K views13 slides
Introduction to programming by
Introduction to programmingIntroduction to programming
Introduction to programmingCavite National Science High School
1.4K views38 slides
Introduction to Java Programming Language by
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Languagejaimefrozr
26.2K views18 slides

Viewers also liked(17)

Introduction to Java Programming by Ravi Kant Sahu
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
Ravi Kant Sahu31.2K views
Introduction to Java Programming Language by jaimefrozr
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Language
jaimefrozr26.2K views
LPW: Beginners Perl by Dave Cross
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners Perl
Dave Cross43.6K views
Basic Concepts of OOPs (Object Oriented Programming in Java) by Michelle Anne Meralpis
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
1 Introduction To Java Technology by dM Technologies
1 Introduction To Java Technology 1 Introduction To Java Technology
1 Introduction To Java Technology
dM Technologies9.2K views
oops concept in java | object oriented programming in java by CPD INDIA
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA38.3K views
Advanced Java Practical File by Soumya Behera
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical File
Soumya Behera14.3K views
Java PRACTICAL file by RACHIT_GUPTA
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL file
RACHIT_GUPTA12.3K views

Similar to Introduction to-programming

Md03 - part3 by
Md03 - part3Md03 - part3
Md03 - part3Rakesh Madugula
363 views55 slides
Introduction to Java Programming by
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java ProgrammingOne97 Communications Limited
1.5K views96 slides
Java fundamentals by
Java fundamentalsJava fundamentals
Java fundamentalsJayfee Ramos
199 views52 slides
Java: Primitive Data Types by
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data TypesTareq Hasan
3.8K views114 slides
OOP-java-variables.pptx by
OOP-java-variables.pptxOOP-java-variables.pptx
OOP-java-variables.pptxssuserb1a18d
2 views38 slides
C++ Basics introduction to typecasting Webinar Slides 1 by
C++ Basics introduction to typecasting Webinar Slides 1C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1Ali Raza Jilani
191 views51 slides

Similar to Introduction to-programming(20)

Java: Primitive Data Types by Tareq Hasan
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
Tareq Hasan3.8K views
C++ Basics introduction to typecasting Webinar Slides 1 by Ali Raza Jilani
C++ Basics introduction to typecasting Webinar Slides 1C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1
Ali Raza Jilani191 views
Data Types, Variables, and Operators by Marwa Ali Eissa
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
Marwa Ali Eissa2.6K views
The JavaScript Programming Language by Raghavan Mohan
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
Raghavan Mohan1.4K views
The Java Script Programming Language by zone
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Language
zone983 views
Javascript by Yahoo by birbal
Javascript by YahooJavascript by Yahoo
Javascript by Yahoo
birbal740 views
Les origines de Javascript by Bernard Loire
Les origines de JavascriptLes origines de Javascript
Les origines de Javascript
Bernard Loire436 views

More from BG Java EE Course

Rich faces by
Rich facesRich faces
Rich facesBG Java EE Course
6.3K views80 slides
JSP Custom Tags by
JSP Custom TagsJSP Custom Tags
JSP Custom TagsBG Java EE Course
5.3K views21 slides
Java Server Faces (JSF) - advanced by
Java Server Faces (JSF) - advancedJava Server Faces (JSF) - advanced
Java Server Faces (JSF) - advancedBG Java EE Course
64.1K views55 slides
Java Server Faces (JSF) - Basics by
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsBG Java EE Course
12.3K views63 slides
JSTL by
JSTLJSTL
JSTLBG Java EE Course
1.3K views32 slides
Unified Expression Language by
Unified Expression LanguageUnified Expression Language
Unified Expression LanguageBG Java EE Course
4.2K views29 slides

More from BG Java EE Course (20)

Recently uploaded

Business Analyst Series 2023 - Week 4 Session 7 by
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7DianaGray10
146 views31 slides
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023 by
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023BookNet Canada
44 views19 slides
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOsPriyanka Aash
162 views59 slides
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ... by
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...ShapeBlue
171 views28 slides
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... by
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...ShapeBlue
162 views25 slides
"Package management in monorepos", Zoltan Kochan by
"Package management in monorepos", Zoltan Kochan"Package management in monorepos", Zoltan Kochan
"Package management in monorepos", Zoltan KochanFwdays
34 views18 slides

Recently uploaded(20)

Business Analyst Series 2023 - Week 4 Session 7 by DianaGray10
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7
DianaGray10146 views
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023 by BookNet Canada
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
BookNet Canada44 views
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash162 views
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ... by ShapeBlue
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
ShapeBlue171 views
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... by ShapeBlue
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
ShapeBlue162 views
"Package management in monorepos", Zoltan Kochan by Fwdays
"Package management in monorepos", Zoltan Kochan"Package management in monorepos", Zoltan Kochan
"Package management in monorepos", Zoltan Kochan
Fwdays34 views
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online by ShapeBlue
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online
ShapeBlue225 views
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue196 views
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda... by ShapeBlue
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
ShapeBlue164 views
The Power of Heat Decarbonisation Plans in the Built Environment by IES VE
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built Environment
IES VE84 views
Future of AR - Facebook Presentation by Rob McCarty
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
Rob McCarty65 views
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT by ShapeBlue
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
ShapeBlue208 views
LLMs in Production: Tooling, Process, and Team Structure by Aggregage
LLMs in Production: Tooling, Process, and Team StructureLLMs in Production: Tooling, Process, and Team Structure
LLMs in Production: Tooling, Process, and Team Structure
Aggregage57 views
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue by ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
ShapeBlue224 views
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue152 views
Why and How CloudStack at weSystems - Stephan Bienek - weSystems by ShapeBlue
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystems
ShapeBlue247 views
Business Analyst Series 2023 - Week 4 Session 8 by DianaGray10
Business Analyst Series 2023 -  Week 4 Session 8Business Analyst Series 2023 -  Week 4 Session 8
Business Analyst Series 2023 - Week 4 Session 8
DianaGray10145 views

Introduction to-programming

  • 1. Introduction to Java Programming
  • 2.
  • 3.
  • 5.
  • 6.
  • 9.
  • 10.
  • 11. Java Program – Example public class HelloJava { public static void main(String[] args) { System.out.println(&quot;Hello, Java!&quot;); } } HelloJava.java javac HelloJava.java java –cp . HelloJava Hello, Java!
  • 12.
  • 13.
  • 14. Structure of Java Programs
  • 15.
  • 16.
  • 17.
  • 18.
  • 19. Programs, Classes, and Packages – Example package jeecourse.example; import java.io.*; public class SomeClass { private static int mValue = 5; public static void printValue() { System.out.println(&quot;mValue = &quot; + mValue); } public static void main(String[] args) { System.out.println(&quot;Some Class&quot;); printValue(); } }
  • 21.
  • 22. Java Language Keywords abstract continue for new switch assert  default goto   package synchronized boolean do if private this break double implements protected throw byte else import public throws case enum  instanceof return transient catch extends int short try char final interface static void class finally long strictfp  volatile const   float native super while
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30. Ranges of the Integral Primitive Types Type Size Minimum Maximum byte 8 bits -2 7 2 7 – 1 short 16 bits -2 15 2 15 – 1 int 32 bits -2 31 2 31 – 1 long 64 bits -2 63 2 63 – 1
  • 31.
  • 32. Ranges of the Floating-Point Primitive Types Type Size Minimum Maximum float 32 bits +/- 1.40 -45 +/- 3.40 +38 double 64 bits +/- 4.94 -324 +/- 1.79 +308 char 16 bits 0 2 16 - 1
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 40.
  • 41. Variables, Declarations, and Assignments – Examples public class Assignments { public static void main(String args []) { int x, y; // declare int variables float z = 3.414f; // declare and assign float double w = 3.1415; // declare and assign double boolean b = true; // declare and assign boolean char ch; // declare character variable String str; // declare String variable String s = &quot;bye&quot;; // declare and assign String ch = 'A'; // assign a value to char variable str = &quot;Hi out there!&quot;; // assign value to String x = 6; // assign value to int variable y = 1000; // assign values to int variable ... } }
  • 42.
  • 43. Operators Category Operators Unary ++ -- + - ! ~ (type) Arithmetic * / % + - Shift << >> >>> Comparison < <= > >= instanceof == != Bitwise & ^ | Short-circuit && || Conditional ? : Assignment = op=
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58. If Statement – Example public static void main(String[] args) { int radius = 5; double surface = Math.PI * radius * radius; if (surface > 100) { System.out.println(&quot;The circle is too big!&quot;); } else if (surface > 50) { System.out.println( &quot;The circle has acceptable size!&quot;); } else { System.out.println( &quot;The circle is too small!&quot;); } }
  • 59.
  • 60. The switch Statement – Example int dayOfWeek = 3; switch (dayOfWeek) { case 1: System.out.println(&quot;Monday&quot;); break; case 2: System.out.println(&quot;Tuesday&quot;); break; ... default: System.out.println(&quot;Invalid day!&quot;); break; }
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74. Scanner – Example import java.util.Scanner; public class ScannerDemo { public static void main(String[] args) { Scanner console = new Scanner(System.in); // Get the first input System.out.print(&quot;What is your name? &quot;); String name = console.nextLine(); // Get the second input System.out.print(&quot;How old are you? &quot;); int age = console.nextInt(); // Display output on the console System.out.println(&quot;Hello, &quot; + name + &quot;. &quot; + &quot;Next year, you'll be &quot; + (age + 1)); } }
  • 75.
  • 76. Arrays and Array Manipulation
  • 77.
  • 78.
  • 79.
  • 80.
  • 81. Elements Initialization Element Type Initial Value byte 0 int 0 float 0.0f char ‘ 0000’ object reference null short 0 long 0L double 0.0d boolean false
  • 82.
  • 83.
  • 84. Arrays – Example // Finding the smallest and largest // elements in an array int[] values = {3,2,4,5,6,12,4,5,7}; int min = values[0]; int max = values[0]; for (int i=1; i<values.length; i++) { if (values[i] < min) { min = values[i]; } else if (values[i] > max) { max = values[i]; } } System.out.printf(&quot;MIN=%d&quot;, min); System.out.printf(&quot;MAX=%d&quot;, max);
  • 85.
  • 86.
  • 87.
  • 88.
  • 89. M ulti-dimension al A rrays – Example // Finding the sum of all positive // cells from the matrix int[][] matrix = {{2,4,-3}, {8,-1,6}}; int sum = 0; for (int row=0; row<matrix.length; row++) { for (int col=0; col<matrix[row].length; col++) { if (matrix[row][col] > 0) { sum += matrix[row][col]; } } } System.out.println(&quot;Sum = &quot; + sum);
  • 90. Questions ? Introduction to Java Programming
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.

Editor's Notes

  1. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  2. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  3. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  4. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## The Java API is set of runtime libraries that give you a standard way to access the system resources of a host computer. When you write a Java program, you assume the class files of the Java API will be available at any Java virtual machine that may ever have the privilege of running your program (because the Java virtual machine and the class files for the Java API are the required components of any implementation of the Java Platform). When you run a Java program, the virtual machine loads the Java API class files that are referred to by your program&apos;s class files. The combination of all loaded class files (from your program and from the Java API) and any loaded dynamic libraries (containing native methods) constitute the full program executed by the Java virtual machine. The class files of the Java API are inherently specific to the host platform. To access the native resources of the host, the Java API calls native methods. The class files of the Java API invoke native methods so your Java program doesn&apos;t have to. In this manner, the Java API&apos;s class files provide a Java program with a standard, platform-independent interface to the underlying host. Creating platform- independent API is inherently difficult , given that system functionality varies greatly from one platform to another. In addition to facilitating platform independence, the Java API contributes to Java&apos;s security model. The methods of the Java API, before they perform any action that could potentially be harmful (such as writing to the local disk), check for permission. In Java releases prior to 1.2, the methods of the Java API checked permission by querying the security manager . The security manager is a special object that defines a custom security policy for the application . A security manager could, for example, forbid access to the local disk.
  5. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  6. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## As a whole, Java technology leans heavily in the direction of networks, but the Java programming language is quite general-purpose . Java is, first and foremost, an object-oriented language. One promise of object-orientation is that it promotes the re-use of code, resulting in better productivity for developers. In Java, there is no way to directly access memory by arbitrarily casting pointers to a different type or by using pointer arithmetic, as there is in C++. Java requires that you strictly obey rules of type when working with objects. Because Java enforces strict type rules at run- time, you are not able to directly manipulate memory in ways that can accidentally corrupt it. As a result, you can&apos;t ever create certain kinds of bugs in Java programs that regularly harass C++ programmers and hamper their productivity. Another way Java prevents you from inadvertently corrupting memory is through automatic garbage collection . Java has a new operator, just like C++, that you use to allocate memory on the heap for a new object. But unlike C++, Java has no corresponding delete operator, which C++ programmers use to free the memory for an object that is no longer needed by the program. In Java, you merely stop referencing an object, and at some later time, the garbage collector will reclaim the memory occupied by the object. You can be more productive in Java primarily because you don&apos;t have to chase down memory corruption bugs. But also, you can be more productive because when you no longer have to worry about explicitly freeing memory, program design becomes easier. A third way Java protects the integrity of memory at run-time is array bounds checking . In Java, arrays are full-fledged objects, and array bounds are checked each time an array is used. If you create an array of ten items in Java and try to write to the eleventh, Java will throw an exception. Java won&apos;t let you corrupt memory by writing beyond the end of an array. One final example of how Java ensures program robustness is by checking object references , each time they are used, to make sure they are not null. In C++, using a null pointer usually results in a program crash. In Java, using a null reference results in an exception being thrown. The productivity boost you can get just by using the Java language results in quicker development cycles and lower development costs . You can realize further cost savings if you take advantage of the potential platform independence of Java programs. Even if you are not concerned about a network, you may still want to deliver a program on multiple platforms. Java can make support for multiple platforms easier, and therefore, cheaper.
  7. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## The executables “javac” and “java” are platform-specific and are part of the Java Development Kit (JDK), which must be installed on the target host machine. Each of the executables take large number of arguments that customize the compilation and execution process (set custom classpath etc.)
  8. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  9. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  10. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  11. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  12. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  13. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  14. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  15. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96 To create an application, you write a class definition that includes a main() method. To execute an application, type java at the command line, followed by the name of the class containing the main() method to be executed. The main() method must be public so that the JVM can call it. It is static so that it can be executed without the necessity of constructing an instance of the application class. The return type must be void . The argument to main() is a single-dimension array of Strings, containing any arguments that the user might have entered on the command line. For example, consider the following command line: # java Mapper France Belgium With this command line, the args[] array has two elements: France in args[0], and Belgium in args[1].
  16. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  17. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  18. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96
  19. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96 Unused keywords There are two keywords that are reserved in Java but which are not used. If you try to use one of these reserved keywords, the Java compiler will produce the following: KeywordTest.java:4: ‘goto’ not supported.                goto MyLabel; 1 error const Do not use to declare a constant; use public static final . goto Not implemented in the Java language.
  20. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96 According to the Java Language Specification these are technically literal values and not keywords. A literal is much the same as a number or any other value. If we try to create an identifier with one of these literal values we will receive errors. class LiteralTest {      public static void main (String [] args) {           int true = 100; // this will cause error      } } Compiling this code gives us the following error: c:Java ProjectsLiteralTest&gt;javac LiteralTest.java LiteralTest.java:3: Invalid expression statement.                   int true = 100; .. In other words, trying to assign a value to true is much like saying: int 200 = 100;
  21. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  22. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96
  23. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96
  24. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  25. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  26. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  27. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96 All numeric primitive types are signed. The char type is integral but unsigned. The range of a variable of type char is from 0 through 216 − 1. Java characters are in Unicode, which is a 16-bit encoding capable of representing a wide range of international characters. If the most significant 9 bits of a char are all 0, then the encoding is the same as 7-bit ASCII.
  28. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  29. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96 These types conform to the IEEE 754 specification. Many mathematical operations can yield results that have no expression in numbers (infinity, for example). To describe such non-numeric situations, both double and float can take on values that are bit patterns that do not represent numbers. Rather, these patterns represent non-numeric values. The patterns are defined in the Float and Double classes and may be referenced as shown in the next slide.
  30. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96 NaN stands for Not a Number The following code fragment shows the use of these constants: double d = -10.0 / 0.0; if (d == Double.NEGATIVE_INFINITY) { System.out.println(&amp;quot;d just exploded: &amp;quot; + d); } In this code fragment, the test on line 2 passes, so line 3 is executed. Non-numeric values cannot be compared – the following is TRUE: ( Float.NaN != Float.NaN )
  31. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  32. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  33. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  34. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  35. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  36. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  37. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  38. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  39. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  40. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96 The Java operators are listed in precedence order, with the highest precedence at the top of the table. Each group has been given a name for reference purposes; that name is shown in the left column of the table. Arithmetic and comparison operators are each split further into two sub groupings because they have different levels of precedence. We’ll discuss these groupings later.
  41. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96 These are applicable to all numeric types and to char and produce a boolean result.
  42. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96 Notice that arithmetic promotions are applied when these operators are used. This is entirely according to the normal rules discussed in Module 4. For example, although it would be an error to attempt to assign, say, the float value 9.0F to the char variable c , it is perfectly acceptable to compare the two. To achieve the result, Java promotes the smaller type to the larger type; hence the char value ‘A’ (represented by the Unicode value 65) is promoted to a float 65.0F. The comparison is then performed on the resulting float values. Although the ordinal comparisons operate satisfactorily on dissimilar numeric types, including char , they are not applicable to any non-numeric types. They cannot take boolean or any classtype operands.
  43. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  44. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  45. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96
  46. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96 If the cast, which is represented by the (int) part, were not present, the compiler would reject the assignment; a double value, such as is returned by the arithmetic here, cannot be represented accurately by an int variable. Casts can also be applied to object references. This often happens when you use containers, such as the Vector object. If you put, for example, String objects into a Vector, then when you extract them, the return type of the elementAt() method is simply Object. Module 4, “Converting and Casting,” covers casting, the rules governing which casts are legal and which are not, and the nature of the runtime checks that are performed on cast operations.
  47. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96
  48. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96
  49. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96 An evaluation from left to right requires that the leftmost expression, a[b], be evaluated first, so it is a reference to the element a[1]. Next, b is evaluated, which is simply a reference to the variable called b. The constant expression 0 is evaluated next, which clearly does not involve any work. Now that the operands have been evaluated, the operations take place. This is done in the order specified by precedence and associativity. For assignments, associativity is right to left, so the value 0 is first assigned to the variable called b; then the value 0 is assigned into the last element of the array a.
  50. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  51. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  52. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  53. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  54. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  55. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  56. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  57. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  58. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  59. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  60. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  61. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  62. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  63. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  64. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  65. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  66. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  67. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  68. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  69. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  70. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  71. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  72. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  73. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  74. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96 A Java array is an ordered collection of primitives, object references, or other arrays. Java arrays are homogeneous: except as allowed by polymorphism, all elements of an array must be of the same type. That is, when you create an array, you specify the element type, and the resulting array can contain only elements that are instances of that class or subclasses of that class.
  75. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96 The first example declares an array of a primitive type. Example 2 declares an array of object references (Dimension is a class in the java.awt package). Example 3 declares a two-dimensional array—that is, an array of arrays of floats. The square brackets can come before or after the array variable name - This is also true, and perhaps most useful, in method declarations. A method that takes an array of doubles could be declared as myMethod(double dubs[]) or as myMethod(double[] dubs); a method that returns an array of doubles may be declared as either double[] anotherMethod() or as double anotherMethod()[]. In this last case, the first form is probably more readable.
  76. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96 Since array size is not used until runtime, it is legal to specify size with a variable rather than a literal: int size = 1152 * 900; int [] raster; raster = new int[size];
  77. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96 Arrays are actually objects, even to the extent that you can execute methods on them (mostly the methods of the Object class), although you cannot subclass the array class. So this initialization is exactly the same as for other objects, and as a consequence you will see the initialization table again in the next section.
  78. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96
  79. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96 Of course, an array can also be initialized by explicitly assigning a value to each element, starting at array index 0: long [] squares; squares = new long[6000]; for ( int i = 0; i &lt; squares.length; i++) { squares[i] = i * i; } Keep in mind, that the next code is also legal, although it will show only 3 elements: float [] diameters = {1.1f, 2.2f, 3.3f, }; for ( int i = 0; i &lt; diameters.length; i++) { System.out.println(&amp;quot;Element [&amp;quot; + i + &amp;quot;] = &amp;quot; + diameters[i]); }
  80. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  81. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  82. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96 Actually, the f igure is misleading. myInts is actually an array with three elements. Each element is a reference to an array containing 4 ints, as shown in the next slide .
  83. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96 Actually, the f igure is misleading. myInts is actually an array with three elements. Each element is a reference to an array containing 4 ints, as shown in the next slide .
  84. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96
  85. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ## ## (c) 2006 National Academy for Software Development - http://academy.devbg.org* * 07/16/96 When you realize that the outermost array is a single-dimension array containing references, you understand that you can replace any of the references with a reference to a different subordinate array, provided the new subordinate array is of the right type. For example, you can do the following: int [][] myInts = { {1, 2, 3}, {91, 92, 93, 94}, {2001, 2002} }; int [] replacement = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; myInts[1] = replacement;
  86. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  87. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  88. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  89. * 10/09/1007/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  90. * 10/09/1007/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  91. * 10/09/1007/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  92. * 10/09/1007/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  93. * 10/09/1007/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  94. * 10/09/1007/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  95. * 10/09/1007/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  96. * 10/09/1007/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##