SlideShare una empresa de Scribd logo
1 de 96
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]

Más contenido relacionado

La actualidad más candente

Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaSanjeev Tripathi
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101kankemwa Ishaku
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with JavaJussi Pohjolainen
 
Java basics variables
 Java basics   variables Java basics   variables
Java basics variablesJoeReddieMedia
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)arvind pandey
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardHari kiran G
 
Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)indiangarg
 
Core java concepts
Core java  conceptsCore java  concepts
Core java conceptsRam132
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examplesbindur87
 
java: basics, user input, data type, constructor
java:  basics, user input, data type, constructorjava:  basics, user input, data type, constructor
java: basics, user input, data type, constructorShivam Singhal
 

La actualidad más candente (17)

Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
JAVA BASICS
JAVA BASICSJAVA BASICS
JAVA BASICS
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Core java
Core java Core java
Core java
 
Java basics variables
 Java basics   variables Java basics   variables
Java basics variables
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
 
Java Notes
Java NotesJava Notes
Java Notes
 
Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)
 
Presentation to java
Presentation  to  javaPresentation  to  java
Presentation to java
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Java basic
Java basicJava basic
Java basic
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examples
 
java: basics, user input, data type, constructor
java:  basics, user input, data type, constructorjava:  basics, user input, data type, constructor
java: basics, user input, data type, constructor
 

Destacado

Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java ProgrammingRavi Kant Sahu
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Languagejaimefrozr
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners PerlDave Cross
 
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)
Basic Concepts of OOPs (Object Oriented Programming in Java)Michelle Anne Meralpis
 
1 Introduction To Java Technology
1 Introduction To Java Technology 1 Introduction To Java Technology
1 Introduction To Java Technology dM Technologies
 
oops concept in java | object oriented programming in java
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 javaCPD INDIA
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical FileSoumya Behera
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL fileRACHIT_GUPTA
 

Destacado (17)

Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Java programming course for beginners
Java programming course for beginnersJava programming course for beginners
Java programming course for beginners
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Language
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners Perl
 
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)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Java for beginners
Java for beginnersJava for beginners
Java for beginners
 
1 Introduction To Java Technology
1 Introduction To Java Technology 1 Introduction To Java Technology
1 Introduction To Java Technology
 
oops concept in java | object oriented programming in java
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
 
02 basic java programming and operators
02 basic java programming and operators02 basic java programming and operators
02 basic java programming and operators
 
Packages and interfaces
Packages and interfacesPackages and interfaces
Packages and interfaces
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical File
 
Java codes
Java codesJava codes
Java codes
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL file
 
Java programming-examples
Java programming-examplesJava programming-examples
Java programming-examples
 

Similar a Introduction to-programming

demo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.pptdemo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.pptFerdieBalang
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data TypesTareq Hasan
 
OOP-java-variables.pptx
OOP-java-variables.pptxOOP-java-variables.pptx
OOP-java-variables.pptxssuserb1a18d
 
C++ Basics introduction to typecasting Webinar Slides 1
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
 
Lecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptxLecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptxSaqlainYaqub1
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and OperatorsMarwa Ali Eissa
 
The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Languagezone
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming LanguageRaghavan Mohan
 
Les origines de Javascript
Les origines de JavascriptLes origines de Javascript
Les origines de JavascriptBernard Loire
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoobirbal
 

Similar a Introduction to-programming (20)

Md03 - part3
Md03 - part3Md03 - part3
Md03 - part3
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
demo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.pptdemo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.ppt
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
 
OOP-java-variables.pptx
OOP-java-variables.pptxOOP-java-variables.pptx
OOP-java-variables.pptx
 
C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1
 
Lecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptxLecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptx
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
 
The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Language
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
Javascript
JavascriptJavascript
Javascript
 
Les origines de Javascript
Les origines de JavascriptLes origines de Javascript
Les origines de Javascript
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoo
 
Basic of java 2
Basic of java  2Basic of java  2
Basic of java 2
 
Javascript
JavascriptJavascript
Javascript
 
Basic
BasicBasic
Basic
 
Csharp4 basics
Csharp4 basicsCsharp4 basics
Csharp4 basics
 
C# AND F#
C# AND F#C# AND F#
C# AND F#
 

Más de BG Java EE Course (20)

Rich faces
Rich facesRich faces
Rich faces
 
JSP Custom Tags
JSP Custom TagsJSP Custom Tags
JSP Custom Tags
 
Java Server Faces (JSF) - advanced
Java Server Faces (JSF) - advancedJava Server Faces (JSF) - advanced
Java Server Faces (JSF) - advanced
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - Basics
 
JSTL
JSTLJSTL
JSTL
 
Unified Expression Language
Unified Expression LanguageUnified Expression Language
Unified Expression Language
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and Deployment
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
CSS
CSSCSS
CSS
 
HTML: Tables and Forms
HTML: Tables and FormsHTML: Tables and Forms
HTML: Tables and Forms
 
HTML Fundamentals
HTML FundamentalsHTML Fundamentals
HTML Fundamentals
 
WWW and HTTP
WWW and HTTPWWW and HTTP
WWW and HTTP
 
JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery Fundamentals
 
Creating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSSCreating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSS
 
Processing XML with Java
Processing XML with JavaProcessing XML with Java
Processing XML with Java
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
Introduction to-RDBMS-systems
Introduction to-RDBMS-systemsIntroduction to-RDBMS-systems
Introduction to-RDBMS-systems
 

Último

Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 

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.

Notas del editor

  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.* ##