SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
Connect. Collaborate. Innovate.




                               Java Programming Basic
                                      Concepts



                                    Learning Facilitator:
                                           Date:




© Copyright GlobalLogic 2009                                                    1
Connect. Collaborate. Innovate.




                                     Gentle Reminder:
                                 “Switch Off” your Mobile Phone
                                               Or
                               Switch Mobile Phone to “Silent Mode”




© Copyright GlobalLogic 2009                                                             2
Connect. Collaborate. Innovate.




                Agenda

                •     What JAVA is for?
                         –     Software Portability
                         –     Why Portability Matters
                         –     Language and Libraries


                •     Basic Concepts
                         –     JVM, Classpath
                         –     Packages
                         –     Data Types
                         –     JavaDoc/Comments
                         –     Garbage Collection


                • Example Java Application



© Copyright GlobalLogic 2009                                                           3
                                                                                       3
Connect. Collaborate. Innovate.




                What JAVA does for you?


                • Hardware Systems
                         – Processor + memory + I/O devices
                               (Platform to execute softwares)

                • Operating Systems
                         – An operating system (OS) is a set of computer programs that manage
                           the hardware and software resources of a computer.
                         – Runs on top of hardware, so tightly attached with the hardware

                • Application Softwares
                         – Runs on top of operating system, a subclass of computer software
                           which address a particular objective e.g. Word-processors ..
                         – Application made for one OS/hardware system may not run on
                           another.
© Copyright GlobalLogic 2009                                                                           4
                                                                                                       4
Connect. Collaborate. Innovate.




                Why Portability?


                • Softwares Portability

                                    “Applications that are independent of all hardware
                                                 and operating systems”

                         You can compile a Java program on any system and run the
                         resulting binary executable file on the same or any other system

                • “Software portability” refers to adapting a software to a new
                  environment, without re-developing it. This reduces the re-
                  development efforts.




© Copyright GlobalLogic 2009                                                                             5
                                                                                                         5
Connect. Collaborate. Innovate.




                Why Portability?


                • There are different hardware and operating systems
                • Even for one OS, there are numerous releases



                • Software portability is all about “Future-proofing” your
                         Software investment
                         “Future proofing” is a process of trying to anticipate future
                           developments, so that appropriate actions can be taken to minimize
                           negative consequences.
                • With application programs written in Java, you can
                         change/upgrade OS and applications independently




© Copyright GlobalLogic 2009                                                                           6
                                                                                                       6
Connect. Collaborate. Innovate.




                • Example C program
                               void main()
                               {
                                   int arr[2];
                                   printf(“%dn”, arr*3+);
                               }

                               • Run this on windows (using turbo c)
                               • Run this on Unix (using gcc)
                               • Compare the results




© Copyright GlobalLogic 2009                                                                         7
                                                                                                     7
Connect. Collaborate. Innovate.




                Language & Libraries


                • A “programming language” is about
                         – Describing DATA
                         – Describing STATEMENTS that work on DATA
                         – Describing the ways the two can be put together
                               • How expressions are formed
                               • What statements look like
                • Java is a Object-oriented, strongly typed language.
                         – Strongly typed languages specify one or more restrictions on how
                           operations involving values having different data types can be
                           intermixed.
                • Library (package)
                         – Frequently reused code
                         – Not an executable program, but contains executable code
                         – Linking with program's address space
© Copyright GlobalLogic 2009                                                                               8
                                                                                                           8
Connect. Collaborate. Innovate.




                JVM


                • A virtual machine (VM) is an abstract computer architecture
                • Software on top of a real hardware
                • Can run the same application on different machines where the VM
                  is available
                           Java program                               C program v1         C program v2


                               Compiler
                                                                   C compiler and executor 1

                         JVM 1            JVM 2    JVM 3                        C compiler and executor 2



                                      Platform 1      Platform 2   Platform 3




© Copyright GlobalLogic 2009                                                                                          9
                                                                                                                      9
Connect. Collaborate. Innovate.




                •     Java source code is compiled to byte-codes whose target architecture is
                      the Java Virtual Machine (JVM)
                •     Just-in-time (JIT) compiler provides compilation of byte-code to
                      machine code




© Copyright GlobalLogic 2009                                                                         10
                                                                                                     10
Connect. Collaborate. Innovate.




© Copyright GlobalLogic 2009                                 11
                                                             11
Connect. Collaborate. Innovate.



                Exercise


                • Write a Java program to print “Hello World!!!” on the command
                  prompt
                         (Use notepad)

                         – Compile the program
                         – Run the program




© Copyright GlobalLogic 2009                                                                 12
                                                                                             12
Connect. Collaborate. Innovate.




                Classpath


                • The Classpath is an argument (Environment variable) that tells the
                  Java Virtual Machine where to look for user-defined classes and
                  packages in Java programs.

                • Setting CLASSPATH from command-line
                               SET CLASSPATH=Dir;

                • Setting CLASSPATH in Windows via Control-panel




© Copyright GlobalLogic 2009                                                                   13
                                                                                               13
Connect. Collaborate. Innovate.



                Exercise


                • Revisit the hello world program

                • Compiling and running the program from any other directory




© Copyright GlobalLogic 2009                                                                 14
                                                                                             14
Connect. Collaborate. Innovate.




                Java Packages


                • A Java package is a mechanism for organizing Java classes into
                  namespaces.
                • A package provides a unique namespace for the types it contains.
                • Classes in the same package can access each other's protected
                  members.
                • Packages are usually defined using a hierarchical naming pattern
                               • Example – java.lang.*, com.globallogic.*




© Copyright GlobalLogic 2009                                                                              15
                                                                                                          15
Connect. Collaborate. Innovate.



                Exercise


                • Move the hello world program in a package
                                   com.globallogic.training.java

                               • Now compile and execute the program




© Copyright GlobalLogic 2009                                                                         16
                                                                                                     16
Connect. Collaborate. Innovate.




                Data Types


                • A data type is a set of values and the operations on those values
                         – For example, the Java "int" type is the set of 32-bit integers together
                           with the operations "+", "*", "%", etc that operate over integers
                • A data type describes representation, interpretation and structure
                  of values manipulated by algorithms or objects stored in computer
                  memory or other storage device
                • Java has two groups of data types, primitive data types and object
                  references.
                         – primitive data types store actual data,
                         – Java object references are variables which hold references to objects




© Copyright GlobalLogic 2009                                                                                17
                                                                                                            17
Connect. Collaborate. Innovate.



                Data Types


                • Arrays
                                    int[] anArray;
                                    anArray = new int[10];
                                          OR
                                    int[] anArray = new int[10];
                • String
                               String greeting = "Hello world!";

                         character array
                               char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.'};
                               String helloString = new String(helloArray);
                         Basic operations
                               length
                               concat
                               substr
                • int, float
© Copyright GlobalLogic 2009                                                                                        18
                                                                                                                    18
Connect. Collaborate. Innovate.



                Basic I/O


                • I/O streams
                               • An I/O Stream represents an input source or an output destination. A
                                 stream can represent many different kinds of sources and destinations,
                                 including disk files, devices, other programs, and memory arrays.
                               • Input stream
                               • Output stream

                • Writing on console
                                   System.out.println(“...”);


                • Reading from console
                               BufferedReader in = new BufferedReader(new
                                  InputStreamReader(System.in));
                               in.readLine();



© Copyright GlobalLogic 2009                                                                                    19
                                                                                                                19
Connect. Collaborate. Innovate.



                Exercise


                • To determine whether a given string is a palindrome.
                         – Input : a String to be read from console
                         – Ouptput: true/false




© Copyright GlobalLogic 2009                                                                        20
                                                                                                    20
Connect. Collaborate. Innovate.




                Garbage Collection


                • Garbage collection (GC) is a form of automatic memory
                  management.

                • The garbage collector or collector attempts to reclaim garbage, or
                  memory used by objects that will never be accessed the application

                • The basic principle of how a garbage collector works is:
                         – Determine what data objects in a program will not be accessed in the
                           future
                         – Reclaim the resources used by those objects

                • A key feature of Java is its garbage-collected heap, which takes care
                  of freeing dynamically allocated memory that is no longer
                  referenced.
© Copyright GlobalLogic 2009                                                                             21
                                                                                                         21
Connect. Collaborate. Innovate.




                JavaDoc/Comments


                Java comments are of three types
                         – Line Comment //line comment
                         – Block Comment /* block comment */
                         – JavaDoc Comment
                               /**
                               * ...
                               */

                • Javadoc is a tool for generating API documentation in HTML format
                  from doc comments in source code




© Copyright GlobalLogic 2009                                                                 22
                                                                                             22
Connect. Collaborate. Innovate.




                               Q&A


© Copyright GlobalLogic 2009                                       23
Connect. Collaborate. Innovate.




                    “Thank You” for your learning contribution!


           Please submit feedback to help L&D make continuous
           improvement……

             Dial @ Learning:
             Noida: 4444, Nagpur:333, Pune:5222, Banglore:111

             E mail: learning@globallogic.com


© Copyright GlobalLogic 2009                                                                  24

Contenu connexe

Tendances

Vsx5 getting started_guide_en
Vsx5 getting started_guide_enVsx5 getting started_guide_en
Vsx5 getting started_guide_en
Geraldo Camargo
 
Sv jug - mar 2013 - sl
Sv jug - mar 2013 - slSv jug - mar 2013 - sl
Sv jug - mar 2013 - sl
CloudBees
 

Tendances (9)

UnBBayes Plugin Framework
UnBBayes Plugin FrameworkUnBBayes Plugin Framework
UnBBayes Plugin Framework
 
Vsx5 getting started_guide_en
Vsx5 getting started_guide_enVsx5 getting started_guide_en
Vsx5 getting started_guide_en
 
Sv jug - mar 2013 - sl
Sv jug - mar 2013 - slSv jug - mar 2013 - sl
Sv jug - mar 2013 - sl
 
Squeeze more juice from jenkins
Squeeze more juice from jenkinsSqueeze more juice from jenkins
Squeeze more juice from jenkins
 
PowerPoint Presentation
PowerPoint PresentationPowerPoint Presentation
PowerPoint Presentation
 
Subversion Edge Overview
Subversion Edge OverviewSubversion Edge Overview
Subversion Edge Overview
 
Quality Best Practices & Toolkit for Enterprise Flex
Quality Best Practices & Toolkit for Enterprise FlexQuality Best Practices & Toolkit for Enterprise Flex
Quality Best Practices & Toolkit for Enterprise Flex
 
Alliance Successful Selenium Automation
Alliance Successful Selenium AutomationAlliance Successful Selenium Automation
Alliance Successful Selenium Automation
 
AD114 - Don't be afraid of curly brackets reloaded - even more JavaScript for...
AD114 - Don't be afraid of curly brackets reloaded - even more JavaScript for...AD114 - Don't be afraid of curly brackets reloaded - even more JavaScript for...
AD114 - Don't be afraid of curly brackets reloaded - even more JavaScript for...
 

En vedette (17)

Gl qtp day 3 2
Gl qtp day 3   2Gl qtp day 3   2
Gl qtp day 3 2
 
Social guide to_link_building
Social guide to_link_buildingSocial guide to_link_building
Social guide to_link_building
 
Gl qtp day 1 & 2
Gl qtp   day 1 & 2Gl qtp   day 1 & 2
Gl qtp day 1 & 2
 
How to-segment-integrate-your-emails-fin
How to-segment-integrate-your-emails-finHow to-segment-integrate-your-emails-fin
How to-segment-integrate-your-emails-fin
 
70562-Dumps
70562-Dumps70562-Dumps
70562-Dumps
 
A1
A1A1
A1
 
Index Grey (1)
Index Grey (1)Index Grey (1)
Index Grey (1)
 
32916
3291632916
32916
 
70 433
70 43370 433
70 433
 
18 octubre2007 borinbizkarra
18 octubre2007 borinbizkarra18 octubre2007 borinbizkarra
18 octubre2007 borinbizkarra
 
120 marketing-stats-charts-and-graphs
120 marketing-stats-charts-and-graphs120 marketing-stats-charts-and-graphs
120 marketing-stats-charts-and-graphs
 
After midsem-slides-1224252673846877-9 nirav
After midsem-slides-1224252673846877-9 niravAfter midsem-slides-1224252673846877-9 nirav
After midsem-slides-1224252673846877-9 nirav
 
Qtp tutorial
Qtp tutorialQtp tutorial
Qtp tutorial
 
Qtp not just for gui anymore
Qtp   not just for gui anymoreQtp   not just for gui anymore
Qtp not just for gui anymore
 
I.m.p
I.m.pI.m.p
I.m.p
 
GL_Web application testing using selenium
GL_Web application testing using seleniumGL_Web application testing using selenium
GL_Web application testing using selenium
 
1
11
1
 

Similaire à Java programming basics

Gl istqb testing fundamentals
Gl istqb testing fundamentalsGl istqb testing fundamentals
Gl istqb testing fundamentals
Pragya Rastogi
 
X pages jumpstart jmp101
X pages jumpstart jmp101X pages jumpstart jmp101
X pages jumpstart jmp101
pdhannan
 
Java Basic.pdf
Java Basic.pdfJava Basic.pdf
Java Basic.pdf
TechSearchWeb
 

Similaire à Java programming basics (20)

Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
L1 basics
L1 basicsL1 basics
L1 basics
 
Introduction To Core Java - SpringPeople
Introduction To Core Java - SpringPeopleIntroduction To Core Java - SpringPeople
Introduction To Core Java - SpringPeople
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Java training in bangalore
Java training in bangaloreJava training in bangalore
Java training in bangalore
 
130700548484460000
130700548484460000130700548484460000
130700548484460000
 
java Training in Ranchi
java Training in Ranchijava Training in Ranchi
java Training in Ranchi
 
Oops
OopsOops
Oops
 
Java (1)
Java (1)Java (1)
Java (1)
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
XebiaLabs Overview Slides
XebiaLabs Overview SlidesXebiaLabs Overview Slides
XebiaLabs Overview Slides
 
MODULE_1_The History and Evolution of Java.pptx
MODULE_1_The History and Evolution of Java.pptxMODULE_1_The History and Evolution of Java.pptx
MODULE_1_The History and Evolution of Java.pptx
 
Gl istqb testing fundamentals
Gl istqb testing fundamentalsGl istqb testing fundamentals
Gl istqb testing fundamentals
 
X pages jumpstart jmp101
X pages jumpstart jmp101X pages jumpstart jmp101
X pages jumpstart jmp101
 
Java Intro
Java IntroJava Intro
Java Intro
 
Java Basic.pdf
Java Basic.pdfJava Basic.pdf
Java Basic.pdf
 
Vb.net basics 1(vb,net--3 year)
Vb.net basics 1(vb,net--3 year)Vb.net basics 1(vb,net--3 year)
Vb.net basics 1(vb,net--3 year)
 
Introduction to Spring & Spring BootFramework
Introduction to Spring  & Spring BootFrameworkIntroduction to Spring  & Spring BootFramework
Introduction to Spring & Spring BootFramework
 
JAVA object oriented programming (oop).ppt
JAVA object oriented programming (oop).pptJAVA object oriented programming (oop).ppt
JAVA object oriented programming (oop).ppt
 
Fundamentals of JAVA
Fundamentals of JAVAFundamentals of JAVA
Fundamentals of JAVA
 

Plus de Pragya Rastogi (12)

Gl android platform
Gl android platformGl android platform
Gl android platform
 
Qtp questions
Qtp questionsQtp questions
Qtp questions
 
Qtp4 bpt
Qtp4 bptQtp4 bpt
Qtp4 bpt
 
Get ro property outputting value
Get ro property outputting valueGet ro property outputting value
Get ro property outputting value
 
Bp ttutorial
Bp ttutorialBp ttutorial
Bp ttutorial
 
Gl scrum testing_models
Gl scrum testing_modelsGl scrum testing_models
Gl scrum testing_models
 
My Sql concepts
My Sql conceptsMy Sql concepts
My Sql concepts
 
70433 Dumps DB
70433 Dumps DB70433 Dumps DB
70433 Dumps DB
 
70562 (1)
70562 (1)70562 (1)
70562 (1)
 
70 562
70 56270 562
70 562
 
Mobile testingartifacts
Mobile testingartifactsMobile testingartifacts
Mobile testingartifacts
 
Gl qtp day 3 1
Gl qtp day 3   1Gl qtp day 3   1
Gl qtp day 3 1
 

Dernier

+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@
 

Dernier (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
+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...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
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?
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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)
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Java programming basics

  • 1. Connect. Collaborate. Innovate. Java Programming Basic Concepts Learning Facilitator: Date: © Copyright GlobalLogic 2009 1
  • 2. Connect. Collaborate. Innovate. Gentle Reminder: “Switch Off” your Mobile Phone Or Switch Mobile Phone to “Silent Mode” © Copyright GlobalLogic 2009 2
  • 3. Connect. Collaborate. Innovate. Agenda • What JAVA is for? – Software Portability – Why Portability Matters – Language and Libraries • Basic Concepts – JVM, Classpath – Packages – Data Types – JavaDoc/Comments – Garbage Collection • Example Java Application © Copyright GlobalLogic 2009 3 3
  • 4. Connect. Collaborate. Innovate. What JAVA does for you? • Hardware Systems – Processor + memory + I/O devices (Platform to execute softwares) • Operating Systems – An operating system (OS) is a set of computer programs that manage the hardware and software resources of a computer. – Runs on top of hardware, so tightly attached with the hardware • Application Softwares – Runs on top of operating system, a subclass of computer software which address a particular objective e.g. Word-processors .. – Application made for one OS/hardware system may not run on another. © Copyright GlobalLogic 2009 4 4
  • 5. Connect. Collaborate. Innovate. Why Portability? • Softwares Portability “Applications that are independent of all hardware and operating systems” You can compile a Java program on any system and run the resulting binary executable file on the same or any other system • “Software portability” refers to adapting a software to a new environment, without re-developing it. This reduces the re- development efforts. © Copyright GlobalLogic 2009 5 5
  • 6. Connect. Collaborate. Innovate. Why Portability? • There are different hardware and operating systems • Even for one OS, there are numerous releases • Software portability is all about “Future-proofing” your Software investment “Future proofing” is a process of trying to anticipate future developments, so that appropriate actions can be taken to minimize negative consequences. • With application programs written in Java, you can change/upgrade OS and applications independently © Copyright GlobalLogic 2009 6 6
  • 7. Connect. Collaborate. Innovate. • Example C program void main() { int arr[2]; printf(“%dn”, arr*3+); } • Run this on windows (using turbo c) • Run this on Unix (using gcc) • Compare the results © Copyright GlobalLogic 2009 7 7
  • 8. Connect. Collaborate. Innovate. Language & Libraries • A “programming language” is about – Describing DATA – Describing STATEMENTS that work on DATA – Describing the ways the two can be put together • How expressions are formed • What statements look like • Java is a Object-oriented, strongly typed language. – Strongly typed languages specify one or more restrictions on how operations involving values having different data types can be intermixed. • Library (package) – Frequently reused code – Not an executable program, but contains executable code – Linking with program's address space © Copyright GlobalLogic 2009 8 8
  • 9. Connect. Collaborate. Innovate. JVM • A virtual machine (VM) is an abstract computer architecture • Software on top of a real hardware • Can run the same application on different machines where the VM is available Java program C program v1 C program v2 Compiler C compiler and executor 1 JVM 1 JVM 2 JVM 3 C compiler and executor 2 Platform 1 Platform 2 Platform 3 © Copyright GlobalLogic 2009 9 9
  • 10. Connect. Collaborate. Innovate. • Java source code is compiled to byte-codes whose target architecture is the Java Virtual Machine (JVM) • Just-in-time (JIT) compiler provides compilation of byte-code to machine code © Copyright GlobalLogic 2009 10 10
  • 11. Connect. Collaborate. Innovate. © Copyright GlobalLogic 2009 11 11
  • 12. Connect. Collaborate. Innovate. Exercise • Write a Java program to print “Hello World!!!” on the command prompt (Use notepad) – Compile the program – Run the program © Copyright GlobalLogic 2009 12 12
  • 13. Connect. Collaborate. Innovate. Classpath • The Classpath is an argument (Environment variable) that tells the Java Virtual Machine where to look for user-defined classes and packages in Java programs. • Setting CLASSPATH from command-line SET CLASSPATH=Dir; • Setting CLASSPATH in Windows via Control-panel © Copyright GlobalLogic 2009 13 13
  • 14. Connect. Collaborate. Innovate. Exercise • Revisit the hello world program • Compiling and running the program from any other directory © Copyright GlobalLogic 2009 14 14
  • 15. Connect. Collaborate. Innovate. Java Packages • A Java package is a mechanism for organizing Java classes into namespaces. • A package provides a unique namespace for the types it contains. • Classes in the same package can access each other's protected members. • Packages are usually defined using a hierarchical naming pattern • Example – java.lang.*, com.globallogic.* © Copyright GlobalLogic 2009 15 15
  • 16. Connect. Collaborate. Innovate. Exercise • Move the hello world program in a package com.globallogic.training.java • Now compile and execute the program © Copyright GlobalLogic 2009 16 16
  • 17. Connect. Collaborate. Innovate. Data Types • A data type is a set of values and the operations on those values – For example, the Java "int" type is the set of 32-bit integers together with the operations "+", "*", "%", etc that operate over integers • A data type describes representation, interpretation and structure of values manipulated by algorithms or objects stored in computer memory or other storage device • Java has two groups of data types, primitive data types and object references. – primitive data types store actual data, – Java object references are variables which hold references to objects © Copyright GlobalLogic 2009 17 17
  • 18. Connect. Collaborate. Innovate. Data Types • Arrays int[] anArray; anArray = new int[10]; OR int[] anArray = new int[10]; • String String greeting = "Hello world!"; character array char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.'}; String helloString = new String(helloArray); Basic operations length concat substr • int, float © Copyright GlobalLogic 2009 18 18
  • 19. Connect. Collaborate. Innovate. Basic I/O • I/O streams • An I/O Stream represents an input source or an output destination. A stream can represent many different kinds of sources and destinations, including disk files, devices, other programs, and memory arrays. • Input stream • Output stream • Writing on console System.out.println(“...”); • Reading from console BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in.readLine(); © Copyright GlobalLogic 2009 19 19
  • 20. Connect. Collaborate. Innovate. Exercise • To determine whether a given string is a palindrome. – Input : a String to be read from console – Ouptput: true/false © Copyright GlobalLogic 2009 20 20
  • 21. Connect. Collaborate. Innovate. Garbage Collection • Garbage collection (GC) is a form of automatic memory management. • The garbage collector or collector attempts to reclaim garbage, or memory used by objects that will never be accessed the application • The basic principle of how a garbage collector works is: – Determine what data objects in a program will not be accessed in the future – Reclaim the resources used by those objects • A key feature of Java is its garbage-collected heap, which takes care of freeing dynamically allocated memory that is no longer referenced. © Copyright GlobalLogic 2009 21 21
  • 22. Connect. Collaborate. Innovate. JavaDoc/Comments Java comments are of three types – Line Comment //line comment – Block Comment /* block comment */ – JavaDoc Comment /** * ... */ • Javadoc is a tool for generating API documentation in HTML format from doc comments in source code © Copyright GlobalLogic 2009 22 22
  • 23. Connect. Collaborate. Innovate. Q&A © Copyright GlobalLogic 2009 23
  • 24. Connect. Collaborate. Innovate. “Thank You” for your learning contribution! Please submit feedback to help L&D make continuous improvement…… Dial @ Learning: Noida: 4444, Nagpur:333, Pune:5222, Banglore:111 E mail: learning@globallogic.com © Copyright GlobalLogic 2009 24