SlideShare ist ein Scribd-Unternehmen logo
1 von 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"};

Weitere ähnliche Inhalte

Was ist angesagt?

Java lec class, objects and constructors
Java lec class, objects and constructorsJava lec class, objects and constructors
Java lec class, objects and constructors
Jan Niño Acierto
 

Was ist angesagt? (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
 

Ähnlich wie 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
 

Mehr von TIB Academy

Mehr von 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
 

Kürzlich hochgeladen

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
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
kauryashika82
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 

Kürzlich hochgeladen (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet 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
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
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
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
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
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
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
 
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
 
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
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

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