SlideShare une entreprise Scribd logo
1  sur  22
INTRODUCTION TO JAVA
5/3, Varathur Road, Kundalahalli Gate,
Bangalore-560066.
+91-9513332301 / 02 www.tibacademy.in
INTRODUCTION
 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
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++
APPLETS, SERVLETS AND APPLICATIONS
 An applet is designed to be embedded in a
Web page, and run by a browser
 Applets run in a sandbox with numerous
restrictions; for example, they can’t read files
and then use the network
 A servlet is designed to be run by a web
server
 An application is a conventional program
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
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
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!");
}
}
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
*/
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;
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 not have pointers or pointer arithmetic
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 !
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;
}
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 must be only one public class per
file
 The file name must be the same as the
name of that public class, but with a
.java extension
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 !
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
SO, WHAT IS A CLASS?
 A class consists of
 a collection of fields, or variables, very much like
the named fields of a struct
 all the operations (called methods) that can be
performed on those fields
 can be instantiated
 A class describes objects and operations
defined on those objects
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 very strong conventions!
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 inherits all the fields and
methods of its (possibly numerous)
superclasses
AN EXAMPLE OF A CLASS
class Person {
String name;
int age;
void birthday ( ) {
age++;
System.out.println (name + ' is
now ' + age);
}
}
ANOTHER EXAMPLE OF A CLASS
class Driver extends Person {
long driversLicenseNumber;
Date expirationDate;
}
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 ( );
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"};

Contenu connexe

Tendances

Unit3 packages &amp; interfaces
Unit3 packages &amp; interfacesUnit3 packages &amp; interfaces
Unit3 packages &amp; interfacesKalai Selvi
 
Inheritance in java
Inheritance in java Inheritance in java
Inheritance in java yash jain
 
Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Enam Khan
 
Intro to OOP PHP and Github
Intro to OOP PHP and GithubIntro to OOP PHP and Github
Intro to OOP PHP and GithubJo Erik San Jose
 
Java Inheritance | Java Course
Java Inheritance | Java Course Java Inheritance | Java Course
Java Inheritance | Java Course RAKESH P
 
Java lec class, objects and constructors
Java lec class, objects and constructorsJava lec class, objects and constructors
Java lec class, objects and constructorsJan Niño Acierto
 
Introduction to PHP OOP
Introduction to PHP OOPIntroduction to PHP OOP
Introduction to PHP OOPfakhrul hasan
 
OCA JAVA - 1 Packages and Class Structure
 OCA JAVA - 1 Packages and Class Structure OCA JAVA - 1 Packages and Class Structure
OCA JAVA - 1 Packages and Class StructureFernando Gil
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member FunctionsMuhammad Hammad Waseem
 
[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their AccessingMuhammad Hammad Waseem
 

Tendances (20)

Unit3 packages &amp; interfaces
Unit3 packages &amp; interfacesUnit3 packages &amp; interfaces
Unit3 packages &amp; interfaces
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Inheritance in java
Inheritance in java Inheritance in java
Inheritance in java
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Java Simple Notes
Java Simple NotesJava Simple Notes
Java Simple Notes
 
10- java language basics part4
10- java language basics part410- java language basics part4
10- java language basics part4
 
Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.
 
Java basics
Java basicsJava basics
Java basics
 
javainheritance
javainheritancejavainheritance
javainheritance
 
Java packages
Java packagesJava packages
Java packages
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Intro to OOP PHP and Github
Intro to OOP PHP and GithubIntro to OOP PHP and Github
Intro to OOP PHP and Github
 
Java Inheritance | Java Course
Java Inheritance | Java Course Java Inheritance | Java Course
Java Inheritance | Java Course
 
Java lec class, objects and constructors
Java lec class, objects and constructorsJava lec class, objects and constructors
Java lec class, objects and constructors
 
Java basic-syntax
Java basic-syntaxJava basic-syntax
Java basic-syntax
 
Introduction to PHP OOP
Introduction to PHP OOPIntroduction to PHP OOP
Introduction to PHP OOP
 
OCA JAVA - 1 Packages and Class Structure
 OCA JAVA - 1 Packages and Class Structure OCA JAVA - 1 Packages and Class Structure
OCA JAVA - 1 Packages and Class Structure
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
 
[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data Member[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data Member
 
[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing
 

Similaire à Java tutorial for beginners-tibacademy.in (20)

Java PPt.ppt
Java PPt.pptJava PPt.ppt
Java PPt.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
 
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
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
Java01
Java01Java01
Java01
 
Java01
Java01Java01
Java01
 
Java intro
Java introJava intro
Java intro
 

Plus de TIB Academy

AWS Training Institute in Bangalore | Best AWS Course In Bangalore
AWS Training Institute in Bangalore | Best AWS Course In BangaloreAWS Training Institute in Bangalore | Best AWS Course In Bangalore
AWS Training Institute in Bangalore | Best AWS Course In BangaloreTIB Academy
 
MySQL training in Bangalore | Best MySQL Course in Bangalore
MySQL training in Bangalore | Best MySQL Course in BangaloreMySQL training in Bangalore | Best MySQL Course in Bangalore
MySQL training in Bangalore | Best MySQL Course in BangaloreTIB Academy
 
CCNA Training in Bangalore | Best Networking course in Bangalore
CCNA Training in Bangalore | Best Networking course in BangaloreCCNA Training in Bangalore | Best Networking course in Bangalore
CCNA Training in Bangalore | Best Networking course in BangaloreTIB Academy
 
Core Java Training in Bangalore | Best Core Java Class in Bangalore
Core Java Training in Bangalore | Best Core Java Class in BangaloreCore Java Training in Bangalore | Best Core Java Class in Bangalore
Core Java Training in Bangalore | Best Core Java Class in BangaloreTIB Academy
 
Advance Java Training in Bangalore | Best Java Training Institute
Advance Java Training in Bangalore | Best Java Training Institute Advance Java Training in Bangalore | Best Java Training Institute
Advance Java Training in Bangalore | Best Java Training Institute TIB Academy
 
Best Hadoop Training in Bangalore - TIB Academy
Best Hadoop Training in Bangalore - TIB AcademyBest Hadoop Training in Bangalore - TIB Academy
Best Hadoop Training in Bangalore - TIB AcademyTIB Academy
 
Selenium training for beginners
Selenium training for beginnersSelenium training for beginners
Selenium training for beginnersTIB Academy
 
TIB Academy provides best Oracal DBA classes in Bangalore
TIB Academy provides best Oracal DBA classes in BangaloreTIB Academy provides best Oracal DBA classes in Bangalore
TIB Academy provides best Oracal DBA classes in BangaloreTIB Academy
 
java tutorial for beginner - Free Download
java tutorial for beginner - Free Downloadjava tutorial for beginner - Free Download
java tutorial for beginner - Free DownloadTIB Academy
 
Aws tutorial for beginners- tibacademy.in
Aws tutorial for beginners- tibacademy.inAws tutorial for beginners- tibacademy.in
Aws tutorial for beginners- tibacademy.inTIB Academy
 
C C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.inC C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.inTIB Academy
 
Android tutorial for beginners-traininginbangalore.com
Android tutorial for beginners-traininginbangalore.comAndroid tutorial for beginners-traininginbangalore.com
Android tutorial for beginners-traininginbangalore.comTIB Academy
 
Hadoop tutorial for beginners-tibacademy.in
Hadoop tutorial for beginners-tibacademy.inHadoop tutorial for beginners-tibacademy.in
Hadoop tutorial for beginners-tibacademy.inTIB Academy
 
SoapUI Training in Bangalore
SoapUI Training in BangaloreSoapUI Training in Bangalore
SoapUI Training in BangaloreTIB Academy
 
Spring-training-in-bangalore
Spring-training-in-bangaloreSpring-training-in-bangalore
Spring-training-in-bangaloreTIB Academy
 
Salesforce Certification
Salesforce CertificationSalesforce Certification
Salesforce CertificationTIB Academy
 

Plus de TIB Academy (18)

AWS Training Institute in Bangalore | Best AWS Course In Bangalore
AWS Training Institute in Bangalore | Best AWS Course In BangaloreAWS Training Institute in Bangalore | Best AWS Course In Bangalore
AWS Training Institute in Bangalore | Best AWS Course In Bangalore
 
MySQL training in Bangalore | Best MySQL Course in Bangalore
MySQL training in Bangalore | Best MySQL Course in BangaloreMySQL training in Bangalore | Best MySQL Course in Bangalore
MySQL training in Bangalore | Best MySQL Course in Bangalore
 
CCNA Training in Bangalore | Best Networking course in Bangalore
CCNA Training in Bangalore | Best Networking course in BangaloreCCNA Training in Bangalore | Best Networking course in Bangalore
CCNA Training in Bangalore | Best Networking course in Bangalore
 
Core Java Training in Bangalore | Best Core Java Class in Bangalore
Core Java Training in Bangalore | Best Core Java Class in BangaloreCore Java Training in Bangalore | Best Core Java Class in Bangalore
Core Java Training in Bangalore | Best Core Java Class in Bangalore
 
Advance Java Training in Bangalore | Best Java Training Institute
Advance Java Training in Bangalore | Best Java Training Institute Advance Java Training in Bangalore | Best Java Training Institute
Advance Java Training in Bangalore | Best Java Training Institute
 
Best Hadoop Training in Bangalore - TIB Academy
Best Hadoop Training in Bangalore - TIB AcademyBest Hadoop Training in Bangalore - TIB Academy
Best Hadoop Training in Bangalore - TIB Academy
 
Selenium training for beginners
Selenium training for beginnersSelenium training for beginners
Selenium training for beginners
 
Python Training
Python TrainingPython Training
Python Training
 
TIB Academy provides best Oracal DBA classes in Bangalore
TIB Academy provides best Oracal DBA classes in BangaloreTIB Academy provides best Oracal DBA classes in Bangalore
TIB Academy provides best Oracal DBA classes in Bangalore
 
java tutorial for beginner - Free Download
java tutorial for beginner - Free Downloadjava tutorial for beginner - Free Download
java tutorial for beginner - Free Download
 
Aws tutorial for beginners- tibacademy.in
Aws tutorial for beginners- tibacademy.inAws tutorial for beginners- tibacademy.in
Aws tutorial for beginners- tibacademy.in
 
C C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.inC C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.in
 
Android tutorial for beginners-traininginbangalore.com
Android tutorial for beginners-traininginbangalore.comAndroid tutorial for beginners-traininginbangalore.com
Android tutorial for beginners-traininginbangalore.com
 
Hadoop tutorial for beginners-tibacademy.in
Hadoop tutorial for beginners-tibacademy.inHadoop tutorial for beginners-tibacademy.in
Hadoop tutorial for beginners-tibacademy.in
 
SoapUI Training in Bangalore
SoapUI Training in BangaloreSoapUI Training in Bangalore
SoapUI Training in Bangalore
 
R programming
R programmingR programming
R programming
 
Spring-training-in-bangalore
Spring-training-in-bangaloreSpring-training-in-bangalore
Spring-training-in-bangalore
 
Salesforce Certification
Salesforce CertificationSalesforce Certification
Salesforce Certification
 

Dernier

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 

Dernier (20)

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

Java tutorial for beginners-tibacademy.in

  • 1. INTRODUCTION TO JAVA 5/3, Varathur Road, Kundalahalli Gate, Bangalore-560066. +91-9513332301 / 02 www.tibacademy.in
  • 2. INTRODUCTION  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
  • 3. 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++
  • 4. APPLETS, SERVLETS AND APPLICATIONS  An applet is designed to be embedded in a Web page, and run by a browser  Applets run in a sandbox with numerous restrictions; for example, they can’t read files and then use the network  A servlet is designed to be run by a web server  An application is a conventional program
  • 5. 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
  • 6. 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
  • 7. 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!"); } }
  • 8. 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 */
  • 9. 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;
  • 10. 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 not have pointers or pointer arithmetic
  • 11. 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 !
  • 12. 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; }
  • 13. 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 must be only one public class per file  The file name must be the same as the name of that public class, but with a .java extension
  • 14. 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 !
  • 15. 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
  • 16. SO, WHAT IS A CLASS?  A class consists of  a collection of fields, or variables, very much like the named fields of a struct  all the operations (called methods) that can be performed on those fields  can be instantiated  A class describes objects and operations defined on those objects
  • 17. 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 very strong conventions!
  • 18. 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 inherits all the fields and methods of its (possibly numerous) superclasses
  • 19. AN EXAMPLE OF A CLASS class Person { String name; int age; void birthday ( ) { age++; System.out.println (name + ' is now ' + age); } }
  • 20. ANOTHER EXAMPLE OF A CLASS class Driver extends Person { long driversLicenseNumber; Date expirationDate; }
  • 21. 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 ( );
  • 22. 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"};