SlideShare una empresa de Scribd logo
1 de 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"};

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Similar a 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
 
Java intro
Java introJava intro
Java intro
 
Java01
Java01Java01
Java01
 

Más 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
 

Más 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
 

Último

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
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
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
 
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
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 

Último (20)

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
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
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
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
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
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

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"};