SlideShare uma empresa Scribd logo
1 de 103
JAVA ESSENTIALS BY RICH HELTON (SUN CERTIFIED (SC) JAVA PROGRAMMER, SC JAVA DEVELOPER, SC ENTERPRISE ARCHITECT) January 2009
Java, the beginning … ,[object Object],[object Object],[object Object],[object Object],[object Object]
Java, the beginning … ,[object Object],[object Object],[object Object],[object Object]
Java, the history … Version Year New Features 1.0 1996 1.1 1997 Inner classes 1.2 1998 Swing, Collections 1.3 2000 Performance enhancements 1.4 2002 Assertions, XML 5 2004 Generic classes, enhanced for loop, auto-boxing, enumerations 6 2006 Library improvements
My First Java Program… public class MyFirstJavaProgram { // Start the program public static void main(String[] args){ if(args.length >0){ // If argument print name String myName = (String) args[0]; System.out.println("Hello " +myName); }else{ // Else print System.out.println("Hello there"); } } }
Find it your java program… ,[object Object]
Find the compiler… ,[object Object],[object Object]
Compile… ,[object Object]
Run the program… ,[object Object]
LET’S BREAK DOWN THE PROGRAM
Components of this application… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Comments ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reserved Words ,[object Object],[object Object],[object Object],[object Object],[object Object]
Sample Reserved Words public class  MyFirstJavaProgram { // Start the program public static void  main(String[] args){ if (args.length >0){ // If argument print name String myName = (String) args[0]; System.out.println("Hello " +myName); } else { // Else print System.out.println("Hello there"); } } }
Modifiers, or Access Modifiers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Public,  Protected and Private ,[object Object],[object Object],[object Object]
Sample Modifiers public class  MyFirstJavaProgram { // Start the program public static  void main(String[] args){ if(args.length >0){ // If argument print name String myName = (String) args[0]; System.out.println("Hello " +myName); }else{ // Else print System.out.println("Hello there"); } } }
Statements ,[object Object],[object Object],[object Object],[object Object],[object Object]
Blocks ,[object Object],[object Object]
Sample Block
Main method ,[object Object],[object Object],[object Object],[object Object]
Main method ,[object Object],[object Object],[object Object],[object Object]
What is a class? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
A BRIEF INTRODUCTION INTO OBJECT ORIENTED PROGRAMMING (OOP)
A brief introduction to OOP ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Polymorphism ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Polymorphism ,[object Object],[object Object]
Polymorphism, continuing… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Inheritance ,[object Object],[object Object],[object Object],[object Object],[object Object]
Inheritance ,[object Object],[object Object],[object Object],[object Object]
Inheritance, continuing… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Encapsulation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Putting it all together ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
2 nd  Java Sample Program with an 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]
Some new terms ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
2 nd  Java Program object creation ,[object Object],[object Object],[object Object],[object Object]
2 nd  Java Program object creation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What happened ,[object Object],[object Object],[object Object],[object Object]
Extending functionality ,[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]
Extending functionality ,[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]
Extending functionality ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SUPER ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reflection ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reflection (finding my fields/methods) class WhoAmI{ String test1 =&quot;I think&quot;; String test2 = &quot;Therefore I am&quot;; void CanYouSeeMe(){} void WhoAreYou(){ System. out.println(&quot;WhoAmI:&quot; +this.getClass().getName()); Method [] methods = this.getClass().getDeclaredMethods(); Field [] fields = this.getClass().getDeclaredFields(); for(int i =0; i < methods.length;i++)   System. out.println(&quot;Method:&quot; +methods[i].getName()); for(int i =0; i < fields.length;i++)   System. out.println(&quot;Field:&quot; +fields[i].getName()); }
Reflection ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Abstract (Must Do) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Final (Don’t Change) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Import ,[object Object],[object Object],[object Object],[object Object]
JAR ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JAR Example
Java Properties ,[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]
Java Properties ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Packages ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
INPUT/OUTPUT (I/O)
Strings ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
StringBuffer ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Strings ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
StringTokenizer ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Files ,[object Object],[object Object],[object Object],[object Object],[object Object]
Create a File import java.io.*; public class CreateAFile { public static void main(String[] argv) throws IOException { // Ensure that a filename (or something) was given in  argv[0] if (argv.length == 0) { System.err.println(&quot;Usage: CreateAFile filename&quot;); System.exit(1); } // If  arg is filled then create that file for (int i = 0; i< argv.length; i++) { new File(argv[i]).createNewFile( ); } } }
List a Directory with “ls” ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Open a File import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class FileReader { public static void main(String[] args) { try{ Scanner text = new Scanner( new File( &quot;Test.txt&quot; ) ); }catch(FileNotFoundException ex){ System. out.println(&quot;Error: &quot; +ex.getMessage()); } } }
Scanner and File ,[object Object],[object Object],[object Object],[object Object]
Regular Expressions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Regular Expressions resources http://www.regular-expressions.info/java.html http://java.sun.com/docs/books/tutorial/essential/regex/ http://www.sitepoint.com/article/java-regex-api-explained/
Sockets ,[object Object],[object Object],[object Object],[object Object]
Client Socket ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Server Socket ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Httpd (Http Server) continue ,[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]
Httpd continue ,[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]
Browsing Httpd ,[object Object]
URL (Uniform Resource Locators) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Browsing becomes simplified ,[object Object],[object Object],[object Object]
Browsing becomes simplified public static void main(String[] args) { org.eclipse.swt.widgets.Display display = org.eclipse.swt.widgets.Display .getDefault(); SimpleSWTBrowser thisClass = new SimpleSWTBrowser(); thisClass.createSShell(); thisClass.sShell.open(); while (!thisClass.sShell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } //The URL is called in the createSShell code
Browsing becomes simplified
NIO (New I/O) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Extensible Markup Language (XML) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
XML and Serialization ,[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]
XML Bean ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Now it is an XML object <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>  <java version=&quot;1.6.0_07&quot; class=&quot;java.beans.XMLDecoder&quot;>  <object class=&quot;MyData&quot;>  <void property=&quot;name&quot;>  <string>testXML</string>  </void>  </object>  </java>
SAX ,[object Object],[object Object],[object Object]
SAX import java.io.IOException; import org.xml.sax.*; public class SAXParser{ public static void main(String[] args) throws Exception { new SAXParser(args); } public SAXParser(String[] args) throws SAXException, IOException { XMLReader parser = XMLReaderFactory. createXMLReader(); parser.setContentHandler(new MyDataHandler()); parser.parse(args.length == 1 ? args[0] : &quot;Test.xml&quot;); }
SAX (handler) // Inner class provides DocumentHandler class MyDataHandler extends DefaultHandler { boolean name = false; // Set to true when string tag is found public void startElement(String nsURI, String localName, String rawName, Attributes attributes) throws SAXException { if (rawName.equalsIgnoreCase(&quot;string&quot;)) name = true; } public void characters(char[] ch, int start, int length) { if (name) {  //Will print all name strings found System. out.println(&quot;MyData name:  &quot; +  new String(ch, start, length)); name = false; }  } } }
DOM ,[object Object],[object Object],[object Object],[object Object],[object Object]
ARRAYS, LOOPS AND COLLECTIONS
Arrays, Loops and Collections ,[object Object],[object Object],[object Object],[object Object]
Arrays ,[object Object],[object Object]
Arrays, the code public class ArrayProgram { public static void main(String[] args){ String [] strArray = new String[3]; strArray[0] = &quot;One&quot;; //Java starts at 0 strArray[1] = &quot;Two&quot;; strArray[2] = &quot;Three&quot;; int [] [] intArray = new int[2][]; // 2 rows intArray[0] = new int[3];  // three columns for row 0 intArray[1] = new int[4];  // four columns for row 1 int data = 1; for(int i1 = 0; i1 < intArray.length; i1++){   for(int i2 = 0; i2 < intArray[i1].length; i2++){ intArray[i1][i2] = data++;   } }
Arrays, the code ,[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]
Conditionals ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
if, else 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],[object Object]
&& and || operators ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
switch ,[object Object],[object Object],[object Object],[object Object]
Switch demo class SwitchDemo { public static void main(String[] args) { int month = 8; switch (month) { case 1:  System.out.println(&quot;January&quot;); break; case 2:  System.out.println(&quot;February&quot;); break; case 3:  System.out.println(&quot;March&quot;); break; case 4:  System.out.println(&quot;April&quot;); break; case 5:  System.out.println(&quot;May&quot;); break; case 6:  System.out.println(&quot;June&quot;); break; case 7:  System.out.println(&quot;July&quot;); break; case 8:  System.out.println(&quot;August&quot;); break; case 9:  System.out.println(&quot;September&quot;); break; case 10: System.out.println(&quot;October&quot;); break; case 11: System.out.println(&quot;November&quot;); break; case 12: System.out.println(&quot;December&quot;); break; default: System.out.println(&quot;Invalid month.&quot;);break; }}}
The “for” loop ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The “for each” loop ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The “while” loop ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Let’s “break” and “continue ,[object Object],[object Object],[object Object],[object Object]
“ break” and “continue example public static void main(String[] args) { boolean bFirstLoop = true, boolean bBreakMe = true, bContinue = true; while(bFirstLoop){ System.out.println(&quot;While Loop&quot;); if(bBreakMe) break; // Prints only one “While Loop” } for(int i = 0; i < 3;i++){ if(bContinue){ bContinue = false; continue; } System.out.println(&quot;For Loop&quot;); //Prints twice, skips first time } }
Benefits of Collections ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Linked List ,[object Object],[object Object],[object Object],[object Object]
Linked List, some code import java.util.LinkedList; public class ListProgram {   public static void main(String[] args) { LinkedList < String>  strList = new LinkedList <String>(); strList.add(&quot;One&quot;); strList.add(&quot;Two&quot;); strList.add(&quot;Three&quot;); System. out.print(&quot;Output -> The Linked List vaues =&quot;); for(int i1 = 0; i1 < strList.size(); i1++) System. out.printf(&quot;%s &quot;, strList.get(i1));   } } Output -> The Linked List vaues =One Two Three
Labs ,[object Object],[object Object],[object Object],[object Object]

Mais conteúdo relacionado

Mais procurados

Ta Javaserverside Eran Toch
Ta Javaserverside Eran TochTa Javaserverside Eran Toch
Ta Javaserverside Eran Toch
Adil Jafri
 
Great cup of java
Great  cup of javaGreat  cup of java
Great cup of java
CIB Egypt
 

Mais procurados (18)

JSR 168 Portal - Overview
JSR 168 Portal - OverviewJSR 168 Portal - Overview
JSR 168 Portal - Overview
 
Java essential notes
Java essential notesJava essential notes
Java essential notes
 
Spring aop
Spring aopSpring aop
Spring aop
 
Flask Basics
Flask BasicsFlask Basics
Flask Basics
 
LEARNING  iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
LEARNING	 iPAD STORYBOARDS IN OBJ-­‐C LESSON 1LEARNING	 iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
LEARNING  iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
 
Flask Introduction - Python Meetup
Flask Introduction - Python MeetupFlask Introduction - Python Meetup
Flask Introduction - Python Meetup
 
B.Sc. III(VI Sem) Advance Java Unit2: Appet
B.Sc. III(VI Sem) Advance Java Unit2: AppetB.Sc. III(VI Sem) Advance Java Unit2: Appet
B.Sc. III(VI Sem) Advance Java Unit2: Appet
 
Ta Javaserverside Eran Toch
Ta Javaserverside Eran TochTa Javaserverside Eran Toch
Ta Javaserverside Eran Toch
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
IPaste SDK v.1.0
IPaste SDK v.1.0IPaste SDK v.1.0
IPaste SDK v.1.0
 
Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse
Get ready for FRC 2015: Intro to Java 5 through 8 updates and EclipseGet ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse
Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse
 
Java Programming - 01 intro to java
Java Programming - 01 intro to javaJava Programming - 01 intro to java
Java Programming - 01 intro to java
 
Class notes(week 10) on applet programming
Class notes(week 10) on applet programmingClass notes(week 10) on applet programming
Class notes(week 10) on applet programming
 
Java notes
Java notesJava notes
Java notes
 
Great cup of java
Great  cup of javaGreat  cup of java
Great cup of java
 
Hibernate Advance Interview Questions
Hibernate Advance Interview QuestionsHibernate Advance Interview Questions
Hibernate Advance Interview Questions
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
 
Corejava ratan
Corejava ratanCorejava ratan
Corejava ratan
 

Semelhante a Intro Java Rev010

Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using Reflection
Ganesh Samarthyam
 
Unit2 java
Unit2 javaUnit2 java
Unit2 java
mrecedu
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
AnkurSingh340457
 

Semelhante a Intro Java Rev010 (20)

Classes and Objects
Classes and ObjectsClasses and Objects
Classes and Objects
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using Reflection
 
Java_presesntation.ppt
Java_presesntation.pptJava_presesntation.ppt
Java_presesntation.ppt
 
Basics of java 1
Basics of java 1Basics of java 1
Basics of java 1
 
Javanotes
JavanotesJavanotes
Javanotes
 
01slide
01slide01slide
01slide
 
01slide
01slide01slide
01slide
 
Unit2 java
Unit2 javaUnit2 java
Unit2 java
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
 
Intro to programing with java-lecture 1
Intro to programing with java-lecture 1Intro to programing with java-lecture 1
Intro to programing with java-lecture 1
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
 
Introduction
IntroductionIntroduction
Introduction
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to Java
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller Columns
 
Java notes
Java notesJava notes
Java notes
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
 
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questions
 
Javascript
JavascriptJavascript
Javascript
 
ANDROID FDP PPT
ANDROID FDP PPTANDROID FDP PPT
ANDROID FDP PPT
 
java tr.docx
java tr.docxjava tr.docx
java tr.docx
 

Mais de Rich Helton (17)

Mongo db rev001.
Mongo db rev001.Mongo db rev001.
Mongo db rev001.
 
NServicebus WCF Integration 101
NServicebus WCF Integration 101NServicebus WCF Integration 101
NServicebus WCF Integration 101
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101
 
Entity frameworks101
Entity frameworks101Entity frameworks101
Entity frameworks101
 
Tumbleweed intro
Tumbleweed introTumbleweed intro
Tumbleweed intro
 
Azure rev002
Azure rev002Azure rev002
Azure rev002
 
Salesforce Intro
Salesforce IntroSalesforce Intro
Salesforce Intro
 
First Steps in Android
First Steps in AndroidFirst Steps in Android
First Steps in Android
 
NServiceBus
NServiceBusNServiceBus
NServiceBus
 
Python For Droid
Python For DroidPython For Droid
Python For Droid
 
Spring Roo Rev005
Spring Roo Rev005Spring Roo Rev005
Spring Roo Rev005
 
Python Final
Python FinalPython Final
Python Final
 
Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4
 
Jira Rev002
Jira Rev002Jira Rev002
Jira Rev002
 
Sql Injection and Entity Frameworks
Sql Injection and Entity FrameworksSql Injection and Entity Frameworks
Sql Injection and Entity Frameworks
 
Web Application Firewall intro
Web Application Firewall introWeb Application Firewall intro
Web Application Firewall intro
 
Java Web Security Class
Java Web Security ClassJava Web Security Class
Java Web Security Class
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Intro Java Rev010

  • 1. JAVA ESSENTIALS BY RICH HELTON (SUN CERTIFIED (SC) JAVA PROGRAMMER, SC JAVA DEVELOPER, SC ENTERPRISE ARCHITECT) January 2009
  • 2.
  • 3.
  • 4. Java, the history … Version Year New Features 1.0 1996 1.1 1997 Inner classes 1.2 1998 Swing, Collections 1.3 2000 Performance enhancements 1.4 2002 Assertions, XML 5 2004 Generic classes, enhanced for loop, auto-boxing, enumerations 6 2006 Library improvements
  • 5. My First Java Program… public class MyFirstJavaProgram { // Start the program public static void main(String[] args){ if(args.length >0){ // If argument print name String myName = (String) args[0]; System.out.println(&quot;Hello &quot; +myName); }else{ // Else print System.out.println(&quot;Hello there&quot;); } } }
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. LET’S BREAK DOWN THE PROGRAM
  • 11.
  • 12.
  • 13.
  • 14. Sample Reserved Words public class MyFirstJavaProgram { // Start the program public static void main(String[] args){ if (args.length >0){ // If argument print name String myName = (String) args[0]; System.out.println(&quot;Hello &quot; +myName); } else { // Else print System.out.println(&quot;Hello there&quot;); } } }
  • 15.
  • 16.
  • 17. Sample Modifiers public class MyFirstJavaProgram { // Start the program public static void main(String[] args){ if(args.length >0){ // If argument print name String myName = (String) args[0]; System.out.println(&quot;Hello &quot; +myName); }else{ // Else print System.out.println(&quot;Hello there&quot;); } } }
  • 18.
  • 19.
  • 21.
  • 22.
  • 23.
  • 24. A BRIEF INTRODUCTION INTO OBJECT ORIENTED PROGRAMMING (OOP)
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44. Reflection (finding my fields/methods) class WhoAmI{ String test1 =&quot;I think&quot;; String test2 = &quot;Therefore I am&quot;; void CanYouSeeMe(){} void WhoAreYou(){ System. out.println(&quot;WhoAmI:&quot; +this.getClass().getName()); Method [] methods = this.getClass().getDeclaredMethods(); Field [] fields = this.getClass().getDeclaredFields(); for(int i =0; i < methods.length;i++) System. out.println(&quot;Method:&quot; +methods[i].getName()); for(int i =0; i < fields.length;i++) System. out.println(&quot;Field:&quot; +fields[i].getName()); }
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 51.
  • 52.
  • 53.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60. Create a File import java.io.*; public class CreateAFile { public static void main(String[] argv) throws IOException { // Ensure that a filename (or something) was given in argv[0] if (argv.length == 0) { System.err.println(&quot;Usage: CreateAFile filename&quot;); System.exit(1); } // If arg is filled then create that file for (int i = 0; i< argv.length; i++) { new File(argv[i]).createNewFile( ); } } }
  • 61.
  • 62. Open a File import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class FileReader { public static void main(String[] args) { try{ Scanner text = new Scanner( new File( &quot;Test.txt&quot; ) ); }catch(FileNotFoundException ex){ System. out.println(&quot;Error: &quot; +ex.getMessage()); } } }
  • 63.
  • 64.
  • 65. Regular Expressions resources http://www.regular-expressions.info/java.html http://java.sun.com/docs/books/tutorial/essential/regex/ http://www.sitepoint.com/article/java-regex-api-explained/
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74. Browsing becomes simplified public static void main(String[] args) { org.eclipse.swt.widgets.Display display = org.eclipse.swt.widgets.Display .getDefault(); SimpleSWTBrowser thisClass = new SimpleSWTBrowser(); thisClass.createSShell(); thisClass.sShell.open(); while (!thisClass.sShell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } //The URL is called in the createSShell code
  • 76.
  • 77.
  • 78.
  • 79.
  • 80. Now it is an XML object <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <java version=&quot;1.6.0_07&quot; class=&quot;java.beans.XMLDecoder&quot;> <object class=&quot;MyData&quot;> <void property=&quot;name&quot;> <string>testXML</string> </void> </object> </java>
  • 81.
  • 82. SAX import java.io.IOException; import org.xml.sax.*; public class SAXParser{ public static void main(String[] args) throws Exception { new SAXParser(args); } public SAXParser(String[] args) throws SAXException, IOException { XMLReader parser = XMLReaderFactory. createXMLReader(); parser.setContentHandler(new MyDataHandler()); parser.parse(args.length == 1 ? args[0] : &quot;Test.xml&quot;); }
  • 83. SAX (handler) // Inner class provides DocumentHandler class MyDataHandler extends DefaultHandler { boolean name = false; // Set to true when string tag is found public void startElement(String nsURI, String localName, String rawName, Attributes attributes) throws SAXException { if (rawName.equalsIgnoreCase(&quot;string&quot;)) name = true; } public void characters(char[] ch, int start, int length) { if (name) { //Will print all name strings found System. out.println(&quot;MyData name: &quot; + new String(ch, start, length)); name = false; } } } }
  • 84.
  • 85. ARRAYS, LOOPS AND COLLECTIONS
  • 86.
  • 87.
  • 88. Arrays, the code public class ArrayProgram { public static void main(String[] args){ String [] strArray = new String[3]; strArray[0] = &quot;One&quot;; //Java starts at 0 strArray[1] = &quot;Two&quot;; strArray[2] = &quot;Three&quot;; int [] [] intArray = new int[2][]; // 2 rows intArray[0] = new int[3]; // three columns for row 0 intArray[1] = new int[4]; // four columns for row 1 int data = 1; for(int i1 = 0; i1 < intArray.length; i1++){ for(int i2 = 0; i2 < intArray[i1].length; i2++){ intArray[i1][i2] = data++; } }
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94. Switch demo class SwitchDemo { public static void main(String[] args) { int month = 8; switch (month) { case 1: System.out.println(&quot;January&quot;); break; case 2: System.out.println(&quot;February&quot;); break; case 3: System.out.println(&quot;March&quot;); break; case 4: System.out.println(&quot;April&quot;); break; case 5: System.out.println(&quot;May&quot;); break; case 6: System.out.println(&quot;June&quot;); break; case 7: System.out.println(&quot;July&quot;); break; case 8: System.out.println(&quot;August&quot;); break; case 9: System.out.println(&quot;September&quot;); break; case 10: System.out.println(&quot;October&quot;); break; case 11: System.out.println(&quot;November&quot;); break; case 12: System.out.println(&quot;December&quot;); break; default: System.out.println(&quot;Invalid month.&quot;);break; }}}
  • 95.
  • 96.
  • 97.
  • 98.
  • 99. “ break” and “continue example public static void main(String[] args) { boolean bFirstLoop = true, boolean bBreakMe = true, bContinue = true; while(bFirstLoop){ System.out.println(&quot;While Loop&quot;); if(bBreakMe) break; // Prints only one “While Loop” } for(int i = 0; i < 3;i++){ if(bContinue){ bContinue = false; continue; } System.out.println(&quot;For Loop&quot;); //Prints twice, skips first time } }
  • 100.
  • 101.
  • 102. Linked List, some code import java.util.LinkedList; public class ListProgram { public static void main(String[] args) { LinkedList < String> strList = new LinkedList <String>(); strList.add(&quot;One&quot;); strList.add(&quot;Two&quot;); strList.add(&quot;Three&quot;); System. out.print(&quot;Output -> The Linked List vaues =&quot;); for(int i1 = 0; i1 < strList.size(); i1++) System. out.printf(&quot;%s &quot;, strList.get(i1)); } } Output -> The Linked List vaues =One Two Three
  • 103.