SlideShare uma empresa Scribd logo
1 de 55
JAVA TUTORIAL Write Once, Run Anywhere
JAVA - GENERAL ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JAVA - GENERAL ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
HOW IT WORKS…! Compile-time Environment Compile-time Environment Java Bytecodes move locally or through network Java Source (.java) Java Compiler Java Bytecode (.class ) Runtime System Class Loader Bytecode Verifier Java Class Libraries Operating System Hardware Java Virtual machine Java Interpreter Just in Time Compiler
HOW IT WORKS…! ,[object Object],[object Object],[object Object],[object Object]
JAVA - SECURITY ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
OBJECT-ORIENTED ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JAVA ADVANTAGES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
BASIC JAVA SYNTAX
PRIMITIVE TYPES AND VARIABLES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
INITIALISATION ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
DECLARATIONS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ASSIGNMENT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
BASIC MATHEMATICAL OPERATORS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
STATEMENTS & BLOCKS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
FLOW OF CONTROL ,[object Object],[object Object],[object Object],[object Object],[object Object]
IF – THE CONDITIONAL STATEMENT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
RELATIONAL OPERATORS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
IF… ELSE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
NESTED IF … ELSE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ELSE IF ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
A WARNING… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
THE SWITCH STATEMENT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
THE  FOR  LOOP ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
WHILE LOOPS ,[object Object],[object Object],[object Object],[object Object],[object Object],What is the minimum number of times the loop is executed? What is the maximum number of times?
DO {… } WHILE LOOPS ,[object Object],[object Object],[object Object],[object Object],[object Object],What is the minimum number of times the loop is executed? What is the maximum number of times?
BREAK ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CONTINUE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ARRAYS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],3 6 3 1 6 3 4 1 myArray =   0 1 2 3 4 5 6 7
DECLARING ARRAYS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ASSIGNING VALUES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ITERATING THROUGH ARRAYS ,[object Object],[object Object],[object Object],[object Object]
ARRAYS OF OBJECTS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
DECLARING THE ARRAY ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JAVA METHODS & CLASSES
CLASSES ARE OBJECT DEFINITIONS ,[object Object],[object Object],[object Object],[object Object],[object Object]
THE THREE PRINCIPLES OF OOP ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],car auto- matic manual Super class Subclasses draw() draw()
SIMPLE CLASS AND METHOD ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
METHODS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
METHOD SIGNATURES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
PUBLIC/PRIVATE ,[object Object],[object Object],[object Object],[object Object],[object Object]
USING OBJECTS ,[object Object],[object Object],[object Object],[object Object],[object Object]
CONSTRUCTORS ,[object Object],[object Object],[object Object],[object Object],[object Object]
OVERLOADING ,[object Object],[object Object],[object Object],[object Object]
JAVA DEVELOPMENT KIT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
STREAM MANIPULATION
STREAMS AND I/O ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
DISPLAY FILE CONTENTS import java.io.*; public class FileToOut1 { public static void main(String args[]) { try  { FileInputStream infile = new FileInputStream("testfile.txt"); byte buffer[] = new byte[50]; int nBytesRead; do  { nBytesRead = infile.read(buffer);   System.out.write(buffer, 0, nBytesRead); } while (nBytesRead == buffer.length); } catch (FileNotFoundException e)  { System.err.println("File not found"); }  catch (IOException e) { System.err.println("Read failed"); } } }
FILTERS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
WRITING DATA TO A FILE USING FILTERS import java.io.*; public class GenerateData { public static void main(String args[]) { try  { FileOutputStream fos = new FileOutputStream("stuff.dat"); DataOutputStream dos = new DataOutputStream(fos); dos.writeInt(2); dos.writeDouble(2.7182818284590451); dos.writeDouble(3.1415926535); dos.close(); fos.close(); } catch (FileNotFoundException e) {  System.err.println("File not found"); } catch (IOException e) { System.err.println("Read or write failed"); } } }
READING DATA FROM A FILE USING FILTERS import java.io.*; public class ReadData { public static void main(String args[]) { try { FileInputStream fis = new FileInputStream(&quot;stuff.dat&quot;); DataInputStream dis = new DataInputStream(fis); int n = dis.readInt(); System.out.println(n); for( int i = 0; i < n; i++ ) { System.out.println(dis.readDouble()); } dis.close(); fis.close(); } catch (FileNotFoundException e) {  System.err.println(&quot;File not found&quot;); } catch (IOException e) { System.err.println(&quot;Read or write failed&quot;); } } }
OBJECT SERIALIZATION Write objects to a file, instead of writing primitive types. Use the  ObjectInputStream ,  ObjectOutputStream  classes, the same way that filters are used.
WRITE AN OBJECT TO A FILE import java.io.*; import java.util.*; public class WriteDate { public WriteDate () { Date d = new Date(); try { FileOutputStream f = new FileOutputStream(&quot;date.ser&quot;); ObjectOutputStream s = new ObjectOutputStream (f); s.writeObject (d); s.close (); }  catch (IOException e) { e.printStackTrace(); } public static void main (String args[]) { new WriteDate (); } }
READ AN OBJECT FROM A FILE import java.util.*; public class ReadDate { public ReadDate () { Date d = null; ObjectInputStream s = null; try {  FileInputStream f = new FileInputStream (&quot;date.ser&quot;); s = new ObjectInputStream (f); } catch (IOException e) { e.printStackTrace(); } try { d = (Date) s.readObject  (); } catch (ClassNotFoundException e) { e.printStackTrace(); }  catch (InvalidClassException e) { e.printStackTrace(); }  catch (StreamCorruptedException e) { e.printStackTrace(); }  catch (OptionalDataException e) { e.printStackTrace(); }  catch (IOException e) { e.printStackTrace(); } System.out.println (&quot;Date serialized at: &quot;+ d); } public static void main (String args[]) { new ReadDate ();  } }

Mais conteúdo relacionado

Mais procurados

Introduction to .net framework
Introduction to .net frameworkIntroduction to .net framework
Introduction to .net frameworkArun Prasad
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java ProgrammingMath-Circle
 
Control structures in java
Control structures in javaControl structures in java
Control structures in javaVINOTH R
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsMahika Tutorials
 
Basics of JAVA programming
Basics of JAVA programmingBasics of JAVA programming
Basics of JAVA programmingElizabeth Thomas
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core javamahir jain
 
Learn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarLearn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarAbir Mohammad
 
Introduction to java
Introduction to java Introduction to java
Introduction to java Sandeep Rawat
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming languageMd.Al-imran Roton
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Michelle Anne Meralpis
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVASURIT DATTA
 

Mais procurados (20)

Introduction to .net framework
Introduction to .net frameworkIntroduction to .net framework
Introduction to .net framework
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Features of java
Features of javaFeatures of java
Features of java
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Basics of JAVA programming
Basics of JAVA programmingBasics of JAVA programming
Basics of JAVA programming
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core java
 
Learn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarLearn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat Shahriyar
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Java swing
Java swingJava swing
Java swing
 
Java platform
Java platformJava platform
Java platform
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 

Destaque

Core java concepts
Core java  conceptsCore java  concepts
Core java conceptsRam132
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
Rapport PFE : Réalisation d'une application web back-office de gestion pédago...
Rapport PFE : Réalisation d'une application web back-office de gestion pédago...Rapport PFE : Réalisation d'une application web back-office de gestion pédago...
Rapport PFE : Réalisation d'une application web back-office de gestion pédago...Anas Riahi
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 
مساق الخوارزميات والبرمجة بلغة جافا (1) مفاهيم الخوارزميات ج1
مساق الخوارزميات والبرمجة بلغة جافا (1) مفاهيم الخوارزميات ج1مساق الخوارزميات والبرمجة بلغة جافا (1) مفاهيم الخوارزميات ج1
مساق الخوارزميات والبرمجة بلغة جافا (1) مفاهيم الخوارزميات ج1Mahmoud Alfarra
 
الدرس 3 من #دورة_الجافا - الادوات اللازمة للبرمجة وطريقة عمل الجافا
الدرس 3 من #دورة_الجافا - الادوات اللازمة للبرمجة وطريقة عمل الجافا الدرس 3 من #دورة_الجافا - الادوات اللازمة للبرمجة وطريقة عمل الجافا
الدرس 3 من #دورة_الجافا - الادوات اللازمة للبرمجة وطريقة عمل الجافا Nabeel Alalmai
 
Java Presentation
Java PresentationJava Presentation
Java Presentationaitrichtech
 
Java Servlets
Java ServletsJava Servlets
Java ServletsNitin Pai
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java ProgrammingRavi Kant Sahu
 
alphorm.com - Formation UML
alphorm.com - Formation UMLalphorm.com - Formation UML
alphorm.com - Formation UMLAlphorm
 

Destaque (16)

Java programming course for beginners
Java programming course for beginnersJava programming course for beginners
Java programming course for beginners
 
Java basic
Java basicJava basic
Java basic
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Core java slides
Core java slidesCore java slides
Core java slides
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Rapport PFE : Réalisation d'une application web back-office de gestion pédago...
Rapport PFE : Réalisation d'une application web back-office de gestion pédago...Rapport PFE : Réalisation d'une application web back-office de gestion pédago...
Rapport PFE : Réalisation d'une application web back-office de gestion pédago...
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
مساق الخوارزميات والبرمجة بلغة جافا (1) مفاهيم الخوارزميات ج1
مساق الخوارزميات والبرمجة بلغة جافا (1) مفاهيم الخوارزميات ج1مساق الخوارزميات والبرمجة بلغة جافا (1) مفاهيم الخوارزميات ج1
مساق الخوارزميات والبرمجة بلغة جافا (1) مفاهيم الخوارزميات ج1
 
الدرس 3 من #دورة_الجافا - الادوات اللازمة للبرمجة وطريقة عمل الجافا
الدرس 3 من #دورة_الجافا - الادوات اللازمة للبرمجة وطريقة عمل الجافا الدرس 3 من #دورة_الجافا - الادوات اللازمة للبرمجة وطريقة عمل الجافا
الدرس 3 من #دورة_الجافا - الادوات اللازمة للبرمجة وطريقة عمل الجافا
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Java Notes
Java NotesJava Notes
Java Notes
 
Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674
 
alphorm.com - Formation UML
alphorm.com - Formation UMLalphorm.com - Formation UML
alphorm.com - Formation UML
 

Semelhante a Write Once, Run Anywhere - A Java Tutorial on Platform Independence

Semelhante a Write Once, Run Anywhere - A Java Tutorial on Platform Independence (20)

Java tut1
Java tut1Java tut1
Java tut1
 
Tutorial java
Tutorial javaTutorial java
Tutorial java
 
Java Tut1
Java Tut1Java Tut1
Java Tut1
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Java tut1
Java tut1Java tut1
Java tut1
 
Java tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo CahersiveenJava tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo Cahersiveen
 
Javatut1
Javatut1 Javatut1
Javatut1
 
Java tut1
Java tut1Java tut1
Java tut1
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Java Tutorial | My Heart
Java Tutorial | My HeartJava Tutorial | My Heart
Java Tutorial | My Heart
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Unit I Advanced Java Programming Course
Unit I   Advanced Java Programming CourseUnit I   Advanced Java Programming Course
Unit I Advanced Java Programming Course
 
Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
 
Knowledge of Javascript
Knowledge of JavascriptKnowledge of Javascript
Knowledge of Javascript
 
00_Introduction to Java.ppt
00_Introduction to Java.ppt00_Introduction to Java.ppt
00_Introduction to Java.ppt
 
JAVA LOOP.pptx
JAVA LOOP.pptxJAVA LOOP.pptx
JAVA LOOP.pptx
 

Último

ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEaurabinda banchhor
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsRommel Regala
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 

Último (20)

ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSE
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World Politics
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 

Write Once, Run Anywhere - A Java Tutorial on Platform Independence

  • 1. JAVA TUTORIAL Write Once, Run Anywhere
  • 2.
  • 3.
  • 4. HOW IT WORKS…! Compile-time Environment Compile-time Environment Java Bytecodes move locally or through network Java Source (.java) Java Compiler Java Bytecode (.class ) Runtime System Class Loader Bytecode Verifier Java Class Libraries Operating System Hardware Java Virtual machine Java Interpreter Just in Time Compiler
  • 5.
  • 6.
  • 7.
  • 8.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36. JAVA METHODS & CLASSES
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 48.
  • 49. DISPLAY FILE CONTENTS import java.io.*; public class FileToOut1 { public static void main(String args[]) { try { FileInputStream infile = new FileInputStream(&quot;testfile.txt&quot;); byte buffer[] = new byte[50]; int nBytesRead; do { nBytesRead = infile.read(buffer); System.out.write(buffer, 0, nBytesRead); } while (nBytesRead == buffer.length); } catch (FileNotFoundException e) { System.err.println(&quot;File not found&quot;); } catch (IOException e) { System.err.println(&quot;Read failed&quot;); } } }
  • 50.
  • 51. WRITING DATA TO A FILE USING FILTERS import java.io.*; public class GenerateData { public static void main(String args[]) { try { FileOutputStream fos = new FileOutputStream(&quot;stuff.dat&quot;); DataOutputStream dos = new DataOutputStream(fos); dos.writeInt(2); dos.writeDouble(2.7182818284590451); dos.writeDouble(3.1415926535); dos.close(); fos.close(); } catch (FileNotFoundException e) { System.err.println(&quot;File not found&quot;); } catch (IOException e) { System.err.println(&quot;Read or write failed&quot;); } } }
  • 52. READING DATA FROM A FILE USING FILTERS import java.io.*; public class ReadData { public static void main(String args[]) { try { FileInputStream fis = new FileInputStream(&quot;stuff.dat&quot;); DataInputStream dis = new DataInputStream(fis); int n = dis.readInt(); System.out.println(n); for( int i = 0; i < n; i++ ) { System.out.println(dis.readDouble()); } dis.close(); fis.close(); } catch (FileNotFoundException e) { System.err.println(&quot;File not found&quot;); } catch (IOException e) { System.err.println(&quot;Read or write failed&quot;); } } }
  • 53. OBJECT SERIALIZATION Write objects to a file, instead of writing primitive types. Use the ObjectInputStream , ObjectOutputStream classes, the same way that filters are used.
  • 54. WRITE AN OBJECT TO A FILE import java.io.*; import java.util.*; public class WriteDate { public WriteDate () { Date d = new Date(); try { FileOutputStream f = new FileOutputStream(&quot;date.ser&quot;); ObjectOutputStream s = new ObjectOutputStream (f); s.writeObject (d); s.close (); } catch (IOException e) { e.printStackTrace(); } public static void main (String args[]) { new WriteDate (); } }
  • 55. READ AN OBJECT FROM A FILE import java.util.*; public class ReadDate { public ReadDate () { Date d = null; ObjectInputStream s = null; try { FileInputStream f = new FileInputStream (&quot;date.ser&quot;); s = new ObjectInputStream (f); } catch (IOException e) { e.printStackTrace(); } try { d = (Date) s.readObject (); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InvalidClassException e) { e.printStackTrace(); } catch (StreamCorruptedException e) { e.printStackTrace(); } catch (OptionalDataException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } System.out.println (&quot;Date serialized at: &quot;+ d); } public static void main (String args[]) { new ReadDate (); } }