SlideShare a Scribd company logo
1 of 24
WELCOME TO VIBRANT
TECHNOLOGIES AND
COMPUTERS
vibrant technologies and computers
vibrant technologies and computers
Course content
 Present the syntax of Java
 Introduce the Java API
 Demonstrate how to build
 stand-alone Java programs
 Java applets, which run within browsers e.g.
Netscape
 Example programs
vibrant technologies and computers
Why Java?
 It’s the current “hot” language
 It’s almost entirely object-oriented
 It has a vast library of predefined objects and
operations
 It’s more platform independent
 this makes it great for Web programming
 It’s more secure
 It isn’t C++
vibrant technologies and computers
Applets, Servlets and
Applications
 An apple t is designed to be embedded in a
Web page, and run by a browser
 Applets run in a sandbo x with numerous
restrictions; for example, they can’t read files
and then use the network
 A se rvle t is designed to be run by a web
server
 An applicatio n is a conventional program
vibrant technologies and computers
Building Standalone JAVA
Programs (on UNIX)
 Prepare the file foo.java using an editor
 Invoke the compiler: javac foo.java
 This creates foo.class
 Run the java interpreter: java foo
vibrant technologies and computers
Java Virtual Machine
 The .class files generated by the compiler are
not executable binaries
 so Java combines compilation and interpretation
 Instead, they contain “byte-codes” to be
executed by the Java Virtual Machine
 other languages have done this, e.g. UCSD
Pascal
 This approach provides platform
independence, and greater security
vibrant technologies and computers
HelloWorld (standalone)
 Note that String is built in
 println is a member function for the
System.out class
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
vibrant technologies and computers
Comments are almost like C++
 /* This kind of comment can span multiple lines */
 // This kind is to the end of the line
 /**
* This kind of comment is a special
* ‘javadoc’ style comment
*/
vibrant technologies and computers
Primitive data types are like C
 Main data types are int, double,
boolean, char
 Also have byte, short, long, float
 boolean has values true and false
 Declarations look like C, for example,
 double x, y;
 int count = 0;
vibrant technologies and computers
Expressions are like C
 Assignment statements mostly look like those in C;
you can use =, +=, *= etc.
 Arithmetic uses the familiar + - * / %
 Java also has ++ and --
 Java has boolean operators && || !
 Java has comparisons < <= == != >= >
 Java does no t have pointers or pointer arithmetic
vibrant technologies and computers
Control statements are like C
 if (x < y) smaller = x;
 if (x < y){ smaller=x;sum += x;}
else { smaller = y; sum += y; }
 while (x < y) { y = y - x; }
 do { y = y - x; } while (x < y)
 for (int i = 0; i < max; i++)
sum += i;
 BUT: conditions must be boolean !
vibrant technologies and computers
Control statements II
 Java also introduces the try statement,
about which more later
switch (n + 1) {
case 0: m = n - 1; break;
case 1: m = n + 1;
case 3: m = m * n; break;
default: m = -n; break;
}
vibrant technologies and computers
Java isn't C!
 In C, almost everything is in functions
 In Java, almost everything is in classes
 There is often only one class per file
 There m ust be only one public class per file
 The file name m ust be the same as the name
of that public class, but with a .java extension
vibrant technologies and computers
Java program layout
 A typical Java file looks like:
import java.awt.*;
import java.util.*;
public class SomethingOrOther {
// object definitions go here
. . .
}
This must be in a file named SomethingOrOther.java !
vibrant technologies and computers
What is a class?
 Early languages had only arrays
 all elements had to be of the same type
 Then languages introduced structures (called
records, or structs)
 allowed different data types to be grouped
 Then Abstract Data Types (ADTs) became
popular
 grouped operations along with the data
vibrant technologies and computers
So, what is a class?
 A class consists of
 a collection of fie lds, or variable s , very much like
the named fields of a struct
 all the operations (called m e tho ds) that can be
performed on those fields
 can be instantiate d
 A class describes objects and operations
defined on those objects
vibrant technologies and computers
Name conventions
 Java is case-sensitive; maxval, maxVal, and
MaxVal are three different names
 Class names begin with a capital letter
 All other names begin with a lowercase letter
 Subsequent words are capitalized: theBigOne
 Underscores are not used in names
 These are ve ry stro ng conventions!
vibrant technologies and computers
The class hierarchy
 Classes are arranged in a hierarchy
 The root, or topmost, class is Object
 Every class but Object has at least one
superclass
 A class may have subclasses
 Each class inhe rits all the fields and methods
of its (possibly numerous) superclasses
vibrant technologies and computers
An example of a class
class Person {
String name;
int age;
void birthday ( ) {
age++;
System.out.println (name + ' is
now ' + age);
}
}
vibrant technologies and computers
Another example of a class
class Driver extends Person {
long driversLicenseNumber;
Date expirationDate;
}
vibrant technologies and computers
Creating and using an object
 Person john;
john = new Person ( );
john.name = "John Smith";
john.age = 37;
 Person mary = new Person ( );
mary.name = "Mary Brown";
mary.age = 33;
mary.birthday ( );
vibrant technologies and computers
An array is an object
 Person mary = new Person ( );
 int myArray[ ] = new int[5];
 or:
 int myArray[ ] = {1, 4, 9, 16,
25};
 String languages [ ] = {"Prolog",
"Java"};
vibrant technologies and computers
Thank you
vibrant technologies and computers

More Related Content

What's hot

Introduction to java
Introduction to  javaIntroduction to  java
Introduction to javaKalai Selvi
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelRamrao Desai
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#foreverredpb
 
Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming conceptsGanesh Karthik
 
Lecture d-inheritance
Lecture d-inheritanceLecture d-inheritance
Lecture d-inheritanceTej Kiran
 
Unit3 packages &amp; interfaces
Unit3 packages &amp; interfacesUnit3 packages &amp; interfaces
Unit3 packages &amp; interfacesKalai Selvi
 
Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes Uzair Salman
 
Introduce oop in python
Introduce oop in pythonIntroduce oop in python
Introduce oop in pythontuan vo
 
Unit3 part3-packages and interfaces
Unit3 part3-packages and interfacesUnit3 part3-packages and interfaces
Unit3 part3-packages and interfacesDevaKumari Vijay
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHPLorna Mitchell
 
Class, object and inheritance in python
Class, object and inheritance in pythonClass, object and inheritance in python
Class, object and inheritance in pythonSantosh Verma
 

What's hot (20)

Introduction to java
Introduction to  javaIntroduction to  java
Introduction to java
 
Java notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esectionJava notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esection
 
Java notes
Java notesJava notes
Java notes
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
 
OOPs in Java
OOPs in JavaOOPs in Java
OOPs in Java
 
Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming concepts
 
Lecture d-inheritance
Lecture d-inheritanceLecture d-inheritance
Lecture d-inheritance
 
Unit3 packages &amp; interfaces
Unit3 packages &amp; interfacesUnit3 packages &amp; interfaces
Unit3 packages &amp; interfaces
 
Oops in Java
Oops in JavaOops in Java
Oops in Java
 
OOPS in Java
OOPS in JavaOOPS in Java
OOPS in Java
 
Lecture 01 - Basic Concept About OOP With Python
Lecture 01 - Basic Concept About OOP With PythonLecture 01 - Basic Concept About OOP With Python
Lecture 01 - Basic Concept About OOP With Python
 
Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes
 
Introduce oop in python
Introduce oop in pythonIntroduce oop in python
Introduce oop in python
 
Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
 
Unit3 part3-packages and interfaces
Unit3 part3-packages and interfacesUnit3 part3-packages and interfaces
Unit3 part3-packages and interfaces
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP
 
Oops in java
Oops in javaOops in java
Oops in java
 
Java basic
Java basicJava basic
Java basic
 
Class, object and inheritance in python
Class, object and inheritance in pythonClass, object and inheritance in python
Class, object and inheritance in python
 

Similar to core java course online

Similar to core java course online (20)

Java PPt.ppt
Java PPt.pptJava PPt.ppt
Java PPt.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
Java tutorial for beginners-tibacademy.in
Java tutorial for beginners-tibacademy.inJava tutorial for beginners-tibacademy.in
Java tutorial for beginners-tibacademy.in
 
java-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbaijava-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbai
 
java-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbaijava-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbai
 
Java
JavaJava
Java
 
Java
JavaJava
Java
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
mukul Dubey.pptx
mukul Dubey.pptxmukul Dubey.pptx
mukul Dubey.pptx
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 

More from Vibrant Technologies & Computers

Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Vibrant Technologies & Computers
 

More from Vibrant Technologies & Computers (20)

Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5
 
SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables  SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables
 
SQL- Introduction to MySQL
SQL- Introduction to MySQLSQL- Introduction to MySQL
SQL- Introduction to MySQL
 
SQL- Introduction to SQL database
SQL- Introduction to SQL database SQL- Introduction to SQL database
SQL- Introduction to SQL database
 
ITIL - introduction to ITIL
ITIL - introduction to ITILITIL - introduction to ITIL
ITIL - introduction to ITIL
 
Salesforce - Introduction to Security & Access
Salesforce -  Introduction to Security & Access Salesforce -  Introduction to Security & Access
Salesforce - Introduction to Security & Access
 
Data ware housing- Introduction to olap .
Data ware housing- Introduction to  olap .Data ware housing- Introduction to  olap .
Data ware housing- Introduction to olap .
 
Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.
 
Data ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housingData ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housing
 
Salesforce - classification of cloud computing
Salesforce - classification of cloud computingSalesforce - classification of cloud computing
Salesforce - classification of cloud computing
 
Salesforce - cloud computing fundamental
Salesforce - cloud computing fundamentalSalesforce - cloud computing fundamental
Salesforce - cloud computing fundamental
 
SQL- Introduction to PL/SQL
SQL- Introduction to  PL/SQLSQL- Introduction to  PL/SQL
SQL- Introduction to PL/SQL
 
SQL- Introduction to advanced sql concepts
SQL- Introduction to  advanced sql conceptsSQL- Introduction to  advanced sql concepts
SQL- Introduction to advanced sql concepts
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
 
SQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set OperationsSQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set Operations
 
Sas - Introduction to designing the data mart
Sas - Introduction to designing the data martSas - Introduction to designing the data mart
Sas - Introduction to designing the data mart
 
Sas - Introduction to working under change management
Sas - Introduction to working under change managementSas - Introduction to working under change management
Sas - Introduction to working under change management
 
SAS - overview of SAS
SAS - overview of SASSAS - overview of SAS
SAS - overview of SAS
 
Teradata - Architecture of Teradata
Teradata - Architecture of TeradataTeradata - Architecture of Teradata
Teradata - Architecture of Teradata
 
Teradata - Restoring Data
Teradata - Restoring Data Teradata - Restoring Data
Teradata - Restoring Data
 

Recently uploaded

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 

core java course online

  • 1. WELCOME TO VIBRANT TECHNOLOGIES AND COMPUTERS vibrant technologies and computers
  • 3. Course content  Present the syntax of Java  Introduce the Java API  Demonstrate how to build  stand-alone Java programs  Java applets, which run within browsers e.g. Netscape  Example programs vibrant technologies and computers
  • 4. Why Java?  It’s the current “hot” language  It’s almost entirely object-oriented  It has a vast library of predefined objects and operations  It’s more platform independent  this makes it great for Web programming  It’s more secure  It isn’t C++ vibrant technologies and computers
  • 5. Applets, Servlets and Applications  An apple t is designed to be embedded in a Web page, and run by a browser  Applets run in a sandbo x with numerous restrictions; for example, they can’t read files and then use the network  A se rvle t is designed to be run by a web server  An applicatio n is a conventional program vibrant technologies and computers
  • 6. Building Standalone JAVA Programs (on UNIX)  Prepare the file foo.java using an editor  Invoke the compiler: javac foo.java  This creates foo.class  Run the java interpreter: java foo vibrant technologies and computers
  • 7. Java Virtual Machine  The .class files generated by the compiler are not executable binaries  so Java combines compilation and interpretation  Instead, they contain “byte-codes” to be executed by the Java Virtual Machine  other languages have done this, e.g. UCSD Pascal  This approach provides platform independence, and greater security vibrant technologies and computers
  • 8. HelloWorld (standalone)  Note that String is built in  println is a member function for the System.out class public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } vibrant technologies and computers
  • 9. Comments are almost like C++  /* This kind of comment can span multiple lines */  // This kind is to the end of the line  /** * This kind of comment is a special * ‘javadoc’ style comment */ vibrant technologies and computers
  • 10. Primitive data types are like C  Main data types are int, double, boolean, char  Also have byte, short, long, float  boolean has values true and false  Declarations look like C, for example,  double x, y;  int count = 0; vibrant technologies and computers
  • 11. Expressions are like C  Assignment statements mostly look like those in C; you can use =, +=, *= etc.  Arithmetic uses the familiar + - * / %  Java also has ++ and --  Java has boolean operators && || !  Java has comparisons < <= == != >= >  Java does no t have pointers or pointer arithmetic vibrant technologies and computers
  • 12. Control statements are like C  if (x < y) smaller = x;  if (x < y){ smaller=x;sum += x;} else { smaller = y; sum += y; }  while (x < y) { y = y - x; }  do { y = y - x; } while (x < y)  for (int i = 0; i < max; i++) sum += i;  BUT: conditions must be boolean ! vibrant technologies and computers
  • 13. Control statements II  Java also introduces the try statement, about which more later switch (n + 1) { case 0: m = n - 1; break; case 1: m = n + 1; case 3: m = m * n; break; default: m = -n; break; } vibrant technologies and computers
  • 14. Java isn't C!  In C, almost everything is in functions  In Java, almost everything is in classes  There is often only one class per file  There m ust be only one public class per file  The file name m ust be the same as the name of that public class, but with a .java extension vibrant technologies and computers
  • 15. Java program layout  A typical Java file looks like: import java.awt.*; import java.util.*; public class SomethingOrOther { // object definitions go here . . . } This must be in a file named SomethingOrOther.java ! vibrant technologies and computers
  • 16. What is a class?  Early languages had only arrays  all elements had to be of the same type  Then languages introduced structures (called records, or structs)  allowed different data types to be grouped  Then Abstract Data Types (ADTs) became popular  grouped operations along with the data vibrant technologies and computers
  • 17. So, what is a class?  A class consists of  a collection of fie lds, or variable s , very much like the named fields of a struct  all the operations (called m e tho ds) that can be performed on those fields  can be instantiate d  A class describes objects and operations defined on those objects vibrant technologies and computers
  • 18. Name conventions  Java is case-sensitive; maxval, maxVal, and MaxVal are three different names  Class names begin with a capital letter  All other names begin with a lowercase letter  Subsequent words are capitalized: theBigOne  Underscores are not used in names  These are ve ry stro ng conventions! vibrant technologies and computers
  • 19. The class hierarchy  Classes are arranged in a hierarchy  The root, or topmost, class is Object  Every class but Object has at least one superclass  A class may have subclasses  Each class inhe rits all the fields and methods of its (possibly numerous) superclasses vibrant technologies and computers
  • 20. An example of a class class Person { String name; int age; void birthday ( ) { age++; System.out.println (name + ' is now ' + age); } } vibrant technologies and computers
  • 21. Another example of a class class Driver extends Person { long driversLicenseNumber; Date expirationDate; } vibrant technologies and computers
  • 22. Creating and using an object  Person john; john = new Person ( ); john.name = "John Smith"; john.age = 37;  Person mary = new Person ( ); mary.name = "Mary Brown"; mary.age = 33; mary.birthday ( ); vibrant technologies and computers
  • 23. An array is an object  Person mary = new Person ( );  int myArray[ ] = new int[5];  or:  int myArray[ ] = {1, 4, 9, 16, 25};  String languages [ ] = {"Prolog", "Java"}; vibrant technologies and computers