SlideShare uma empresa Scribd logo
1 de 20
Collaborate


Knowledge Byte
    In this section, you will learn about:


         •   Evolution and Need for Java
         •   Garbage Collection in Java Virtual Machine (JVM)
         •   Setting the CLASSPATH
         •   Significance of the Java class file




 ©NIIT                          Collaborate                     Lesson 2C / Slide 1 of 20
Collaborate


Evolution and Need for Java
•    You can use Java to develop network-oriented programs because networking
     features are inbuilt in Java.
•    In 1991, a team of software developers at Sun Microsystems, USA, was designing a
     language for consumer electronic devices.
•    The development team headed by James Gosling wanted to design a portable
     language using which programs should be developed such that they can run on
     computers with different platform.
•    The team considered C++ as the model language for designing Java language. The
     team deprecated various ambiguous features from this new language.
•    Initially, this developed language was called Oak, but was later renamed to Java.




    ©NIIT                       Collaborate                  Lesson 2C / Slide 2 of 20
Collaborate


Evolution and Need for Java (Contd.)
    •    The following table lists the various developments that took place in the
         evolution of Java:



                    Year                                  Development


  1990                                         Sun Microsystems developed software
                                               to manipulate electronic devices.


  1991                                         A new language named Oak was
                                               introduced using the most popular
                                               object-oriented language C++



 ©NIIT                           Collaborate                   Lesson 2C / Slide 3 of 20
Collaborate


Evolution and Need for Java (Contd.)
          Year                           Development


  1993                         The WWW appeared on the Internet
                               that transformed the text-based
                               Internet into graphical Internet.

  1994                         Sun Microsystems team developed a
                               Web browser called HotJava to
                               locate and run applet programs on
                               the Internet.
  1995                         Oak was renamed as Java.


  1996                         Java was established as an
                               Object-oriented programming
                               language.

 ©NIIT           Collaborate                    Lesson 2C / Slide 4 of 20
Collaborate


Garbage Collection in JVM
    •    Garbage collection is the process that is used to free the memory of the
         objects that are no longer in use.
    •    When a program stops referencing an object, it is not required any more and
         can be deleted.
    •    The space that is used by the object is released for use by another objects.
    •    The garbage collection feature implies that the new objects are created and all
         the unreferenced objects are deallocated from the memory.
    •    The different approaches used for detecting garbage objects are:
           • Reference-Counting Collectors: Store the references of the objects used
             within a program
           • Tracing Collectors: A set of roots is defined from the location where the
             objects are traced.
           • Compacting Collectors: Reduce the fragmentation of memory by moving
             all the free space to one side during garbage collection.



 ©NIIT                          Collaborate                    Lesson 2C / Slide 5 of 20
Collaborate


Setting the CLASSPATH
•      The CLASSPATH environment variable instructs the JVM class loader to find the
       classes that are directly or indirectly invoked, including the system classes.
•      The -classpath option is used when the SDK tools are called, such as java, javac
       and javadoc.
•      The following syntax shows how to set the classpath with an SDK tool:
       C:> sdktool -classpath <classpath1>;<classpath2>...
•      The following syntax shows how to set the classpath using the classpath
       environment variable:
       C:> set CLASSPATH=<classpath1>;<classpath2>...




    ©NIIT                        Collaborate                   Lesson 2C / Slide 6 of 20
Collaborate


Significance of the Java Class File
    •    The Java class file contains the Java Bytecode.
    •    The class files are platform independent therefore you can run a Java
         program by loading the class file on any system with the Java Runtime
         Environment (JRE).
    •    The following command shows how to view the contents of a class file:
          javap -c <class_filename>
    •    The javap command prints the instructions that comprise the Java Bytecode,
         for each of the methods in a class.




 ©NIIT                       Collaborate                  Lesson 2C / Slide 7 of 20
Collaborate


From the Expert’s Desk

    In this section, you will learn:


         •    Best practices on:
              • Declaring class variables as private and methods as public
              • Declaring arrays
              • Declaring class variables using the Hungarian notation
         •    Tips and Tricks on:
              • Displaying text in a Java program
              • Setting CLASSPATH
         •    FAQs on Java Fundamentals




 ©NIIT                           Collaborate              Lesson 2C / Slide 8 of 20
Collaborate


Best Practices
Declaring class variables as private and methods
as public
•      You should declare all the class variables as private because data should always
       remain hidden from the objects of other classes.
•      Methods should be declared as public because the methods provide an interface to
       the objects of the other classes.




    ©NIIT                        Collaborate                  Lesson 2C / Slide 9 of 20
Collaborate


Best Practices
Declaring arrays
•      Arrays can range from a higher minimum number to a higher maximum number,
       such as 45 to 90 but it is more efficient to begin arrays with an element 0 because
       it takes up less memory in the computer to store arrays that begin with 0.
•      If you write a Java program having the for loop that starts from array element 45
       to element 90, the compiler will still allocate the memory to the array starting
       from elements 0 to array element 44.




    ©NIIT                         Collaborate                  Lesson 2C / Slide 10 of 20
Collaborate


Best Practices
Declaring Class Variables
•      You can follow Hungarian notation to declare variables in Java.
•      The conventions followed in the Hungarian notation are:
       • The first letter of the variable should indicate the data type used. You can
            use the letters, i, f, and b to indicate an integer, float, or a boolean variable.
            For example, iAge, fPrice, and bResult.
       • The variable name should be meaningful. For example, iAge is an integer
            variable to store the age of a student.
       • In case the variable name consists of multiple words, the first letter of each
            word should be capitalized, for example iTotalMarks and fPriceOfCommodity.




    ©NIIT                          Collaborate                    Lesson 2C / Slide 11 of 20
Collaborate


Tips and Tricks
Displaying text in a Java program

•      You can also use the drawString() method to display text in addition to the
       System.out.println() method in Java. The drawString() method requires three
       arguments.
•      The first argument represents the string to be displayed on an applet. The second
       and third arguments represent the x and y coordinates of the string to be
       displayed.




    ©NIIT                        Collaborate                  Lesson 2C / Slide 12 of 20
Collaborate


Tips and Tricks
Setting CLASSPATH

•      CLASSPATH is an environment variable that enables the Java compiler javac.exe
       to locate class files to be imported.
•      You can use the SET CLASSPATH= to set the CLASSPATH variable. The following
       syntax shows how to set CLASSPATH in Java:
       SET CLASSPATH= C:j2sdk1.4.1_02bin .




    ©NIIT                       Collaborate                 Lesson 2C / Slide 13 of 20
Collaborate


FAQs
    •    Why is Java considered ideal for network communication?

         Java is considered ideal for network communication because it is a platform
         independent language. Java enables an application to be executed on any
         network. The built-in classes of Java support TCP/IP and UDP protocols used
         for network communication. Java supports the Client-Server model for
         network communication.




 ©NIIT                        Collaborate                 Lesson 2C / Slide 14 of 20
Collaborate


FAQs (Contd.)
    •    What will happen if the data type of a variable and the value assigned to the
         variable are different?

         If the data type of a variable and the value assigned to the variable are
         different then compilation error occurs. The following code shows assigning a
         character value to an integer variable:
         class datatype{
         public static void main(String a[])
         {
         int x= 'b';
         System.out.print(x);
         }
         }
         In the preceding code, the ASCII value of the character b is displayed as 98.


 ©NIIT                         Collaborate                  Lesson 2C / Slide 15 of 20
Collaborate


FAQs (Contd.)
    Similarly, if you assign a float or a double value to a character variable, an error
    message is displayed.
    The following code shows assigning a double value to a character variable:
    class datatype{
    public static void main(String a[])
    {
    char x= 5.5;
    System.out.print(x);
    }
    }
    Java is a strongly typed language and it allows the values of the specific data
    types, which are compatible with the type of variable.




 ©NIIT                          Collaborate                   Lesson 2C / Slide 16 of 20
Collaborate


FAQs (Contd.)
    •    Do all arguments sent to a Java application have to be strings?

         Yes, all the arguments sent to a Java application have to be string. If you use
         some other data type, such as int, you need to convert the value to string.


    •    Can two variables have the same letters but different capitalization, as in
         variableName and VariableName?

         No, Java is a case-sensitive language. It differentiates the two variables,
         variableName and VariableName.




 ©NIIT                         Collaborate                   Lesson 2C / Slide 17 of 20
Collaborate


Challenge
    1.      Java is a platform ______ language .
    2.      Match the following:
    a.      Variables                     i. Reserved words
    b.      Literals                     ii. Basic storage unit
    c.      Keywords                    iii. Sequence of characters
    3.      Make words from the jumbled letters in the box given below and match them
            with their description.
            a. Class members that can be accessed by the subclasses of the class in
               which they are declared.
            b. Class members that are accessible to all the classes of a package by
               default.
            c. Class members that can be accessed only by the objects of the same
                class.
            d. Class members that can be accessed anywhere in the same class.


 ©NIIT                        Collaborate                  Lesson 2C / Slide 18 of 20
Collaborate


Challenge (Contd.)
         e.   This method of the String class is used to find the length of a string.
         f.   Collection of classes that can be reused.
         g.   Are the reserved words for a language.
         h.   A method with the same name as the class name
                          IULBPC
                          DFINRE
                          ORETCDPET
                          ELHTGN
                          VPTIARE
                          CKESPAAGS
                          KRDYOESW
                          CNTCSUOORRT

 ©NIIT                             Collaborate                  Lesson 2C / Slide 19 of 20
Collaborate


Solutions to Challenge

    •    independent
    •    a-ii, b-iii, c-i
    •    a. Protected, b. Friend, c. Private, d. Public, e. length, f. packages, g.
         keywords, h. constructor




 ©NIIT                          Collaborate                    Lesson 2C / Slide 20 of 20

Mais conteúdo relacionado

Destaque

C programming session 02
C programming session 02C programming session 02
C programming session 02Dushmanta Nath
 
C programming session 03
C programming session 03C programming session 03
C programming session 03Dushmanta Nath
 
C programming session 05
C programming session 05C programming session 05
C programming session 05Dushmanta Nath
 
C programming session 04
C programming session 04C programming session 04
C programming session 04Dushmanta Nath
 
C programming session 01
C programming session 01C programming session 01
C programming session 01Dushmanta Nath
 
C language (Collected By Dushmanta)
C language  (Collected By Dushmanta)C language  (Collected By Dushmanta)
C language (Collected By Dushmanta)Dushmanta Nath
 

Destaque (7)

C programming session 02
C programming session 02C programming session 02
C programming session 02
 
C programming session 03
C programming session 03C programming session 03
C programming session 03
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
 
Niit
NiitNiit
Niit
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
C language (Collected By Dushmanta)
C language  (Collected By Dushmanta)C language  (Collected By Dushmanta)
C language (Collected By Dushmanta)
 

Semelhante a Dacj 1-2 c

Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language Hitesh-Java
 
Session 02 - Elements of Java Language
Session 02 - Elements of Java LanguageSession 02 - Elements of Java Language
Session 02 - Elements of Java LanguagePawanMM
 
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)Ankit Gupta
 
Learnadvancedjavaprogramming 131217055604-phpapp02
Learnadvancedjavaprogramming 131217055604-phpapp02Learnadvancedjavaprogramming 131217055604-phpapp02
Learnadvancedjavaprogramming 131217055604-phpapp02Hardeep Kaur
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptRajeshSukte1
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptCDSukte
 
JAVA PROGRAMMING- OOP Concept
JAVA PROGRAMMING- OOP ConceptJAVA PROGRAMMING- OOP Concept
JAVA PROGRAMMING- OOP ConceptTrinity Dwarka
 
Java Collections Framework
Java  Collections  FrameworkJava  Collections  Framework
Java Collections Frameworkguestd8c458
 

Semelhante a Dacj 1-2 c (20)

Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
Session 02 - Elements of Java Language
Session 02 - Elements of Java LanguageSession 02 - Elements of Java Language
Session 02 - Elements of Java Language
 
Comp102 lec 3
Comp102   lec 3Comp102   lec 3
Comp102 lec 3
 
Dacj 2-1 a
Dacj 2-1 aDacj 2-1 a
Dacj 2-1 a
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
Core Java
Core JavaCore Java
Core Java
 
Dacj 2-2 a
Dacj 2-2 aDacj 2-2 a
Dacj 2-2 a
 
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)
 
Learnadvancedjavaprogramming 131217055604-phpapp02
Learnadvancedjavaprogramming 131217055604-phpapp02Learnadvancedjavaprogramming 131217055604-phpapp02
Learnadvancedjavaprogramming 131217055604-phpapp02
 
1.Intro--Why Java.pptx
1.Intro--Why Java.pptx1.Intro--Why Java.pptx
1.Intro--Why Java.pptx
 
Java lab-manual
Java lab-manualJava lab-manual
Java lab-manual
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.ppt
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.ppt
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Java intro
Java introJava intro
Java intro
 
JAVA PROGRAMMING- OOP Concept
JAVA PROGRAMMING- OOP ConceptJAVA PROGRAMMING- OOP Concept
JAVA PROGRAMMING- OOP Concept
 
Java Collections Framework
Java  Collections  FrameworkJava  Collections  Framework
Java Collections Framework
 
Java introduction
Java introductionJava introduction
Java introduction
 
unit1.pptx
unit1.pptxunit1.pptx
unit1.pptx
 
Java
JavaJava
Java
 

Mais de Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 

Último

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 

Último (20)

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 

Dacj 1-2 c

  • 1. Collaborate Knowledge Byte In this section, you will learn about: • Evolution and Need for Java • Garbage Collection in Java Virtual Machine (JVM) • Setting the CLASSPATH • Significance of the Java class file ©NIIT Collaborate Lesson 2C / Slide 1 of 20
  • 2. Collaborate Evolution and Need for Java • You can use Java to develop network-oriented programs because networking features are inbuilt in Java. • In 1991, a team of software developers at Sun Microsystems, USA, was designing a language for consumer electronic devices. • The development team headed by James Gosling wanted to design a portable language using which programs should be developed such that they can run on computers with different platform. • The team considered C++ as the model language for designing Java language. The team deprecated various ambiguous features from this new language. • Initially, this developed language was called Oak, but was later renamed to Java. ©NIIT Collaborate Lesson 2C / Slide 2 of 20
  • 3. Collaborate Evolution and Need for Java (Contd.) • The following table lists the various developments that took place in the evolution of Java: Year Development 1990 Sun Microsystems developed software to manipulate electronic devices. 1991 A new language named Oak was introduced using the most popular object-oriented language C++ ©NIIT Collaborate Lesson 2C / Slide 3 of 20
  • 4. Collaborate Evolution and Need for Java (Contd.) Year Development 1993 The WWW appeared on the Internet that transformed the text-based Internet into graphical Internet. 1994 Sun Microsystems team developed a Web browser called HotJava to locate and run applet programs on the Internet. 1995 Oak was renamed as Java. 1996 Java was established as an Object-oriented programming language. ©NIIT Collaborate Lesson 2C / Slide 4 of 20
  • 5. Collaborate Garbage Collection in JVM • Garbage collection is the process that is used to free the memory of the objects that are no longer in use. • When a program stops referencing an object, it is not required any more and can be deleted. • The space that is used by the object is released for use by another objects. • The garbage collection feature implies that the new objects are created and all the unreferenced objects are deallocated from the memory. • The different approaches used for detecting garbage objects are: • Reference-Counting Collectors: Store the references of the objects used within a program • Tracing Collectors: A set of roots is defined from the location where the objects are traced. • Compacting Collectors: Reduce the fragmentation of memory by moving all the free space to one side during garbage collection. ©NIIT Collaborate Lesson 2C / Slide 5 of 20
  • 6. Collaborate Setting the CLASSPATH • The CLASSPATH environment variable instructs the JVM class loader to find the classes that are directly or indirectly invoked, including the system classes. • The -classpath option is used when the SDK tools are called, such as java, javac and javadoc. • The following syntax shows how to set the classpath with an SDK tool: C:> sdktool -classpath <classpath1>;<classpath2>... • The following syntax shows how to set the classpath using the classpath environment variable: C:> set CLASSPATH=<classpath1>;<classpath2>... ©NIIT Collaborate Lesson 2C / Slide 6 of 20
  • 7. Collaborate Significance of the Java Class File • The Java class file contains the Java Bytecode. • The class files are platform independent therefore you can run a Java program by loading the class file on any system with the Java Runtime Environment (JRE). • The following command shows how to view the contents of a class file: javap -c <class_filename> • The javap command prints the instructions that comprise the Java Bytecode, for each of the methods in a class. ©NIIT Collaborate Lesson 2C / Slide 7 of 20
  • 8. Collaborate From the Expert’s Desk In this section, you will learn: • Best practices on: • Declaring class variables as private and methods as public • Declaring arrays • Declaring class variables using the Hungarian notation • Tips and Tricks on: • Displaying text in a Java program • Setting CLASSPATH • FAQs on Java Fundamentals ©NIIT Collaborate Lesson 2C / Slide 8 of 20
  • 9. Collaborate Best Practices Declaring class variables as private and methods as public • You should declare all the class variables as private because data should always remain hidden from the objects of other classes. • Methods should be declared as public because the methods provide an interface to the objects of the other classes. ©NIIT Collaborate Lesson 2C / Slide 9 of 20
  • 10. Collaborate Best Practices Declaring arrays • Arrays can range from a higher minimum number to a higher maximum number, such as 45 to 90 but it is more efficient to begin arrays with an element 0 because it takes up less memory in the computer to store arrays that begin with 0. • If you write a Java program having the for loop that starts from array element 45 to element 90, the compiler will still allocate the memory to the array starting from elements 0 to array element 44. ©NIIT Collaborate Lesson 2C / Slide 10 of 20
  • 11. Collaborate Best Practices Declaring Class Variables • You can follow Hungarian notation to declare variables in Java. • The conventions followed in the Hungarian notation are: • The first letter of the variable should indicate the data type used. You can use the letters, i, f, and b to indicate an integer, float, or a boolean variable. For example, iAge, fPrice, and bResult. • The variable name should be meaningful. For example, iAge is an integer variable to store the age of a student. • In case the variable name consists of multiple words, the first letter of each word should be capitalized, for example iTotalMarks and fPriceOfCommodity. ©NIIT Collaborate Lesson 2C / Slide 11 of 20
  • 12. Collaborate Tips and Tricks Displaying text in a Java program • You can also use the drawString() method to display text in addition to the System.out.println() method in Java. The drawString() method requires three arguments. • The first argument represents the string to be displayed on an applet. The second and third arguments represent the x and y coordinates of the string to be displayed. ©NIIT Collaborate Lesson 2C / Slide 12 of 20
  • 13. Collaborate Tips and Tricks Setting CLASSPATH • CLASSPATH is an environment variable that enables the Java compiler javac.exe to locate class files to be imported. • You can use the SET CLASSPATH= to set the CLASSPATH variable. The following syntax shows how to set CLASSPATH in Java: SET CLASSPATH= C:j2sdk1.4.1_02bin . ©NIIT Collaborate Lesson 2C / Slide 13 of 20
  • 14. Collaborate FAQs • Why is Java considered ideal for network communication? Java is considered ideal for network communication because it is a platform independent language. Java enables an application to be executed on any network. The built-in classes of Java support TCP/IP and UDP protocols used for network communication. Java supports the Client-Server model for network communication. ©NIIT Collaborate Lesson 2C / Slide 14 of 20
  • 15. Collaborate FAQs (Contd.) • What will happen if the data type of a variable and the value assigned to the variable are different? If the data type of a variable and the value assigned to the variable are different then compilation error occurs. The following code shows assigning a character value to an integer variable: class datatype{ public static void main(String a[]) { int x= 'b'; System.out.print(x); } } In the preceding code, the ASCII value of the character b is displayed as 98. ©NIIT Collaborate Lesson 2C / Slide 15 of 20
  • 16. Collaborate FAQs (Contd.) Similarly, if you assign a float or a double value to a character variable, an error message is displayed. The following code shows assigning a double value to a character variable: class datatype{ public static void main(String a[]) { char x= 5.5; System.out.print(x); } } Java is a strongly typed language and it allows the values of the specific data types, which are compatible with the type of variable. ©NIIT Collaborate Lesson 2C / Slide 16 of 20
  • 17. Collaborate FAQs (Contd.) • Do all arguments sent to a Java application have to be strings? Yes, all the arguments sent to a Java application have to be string. If you use some other data type, such as int, you need to convert the value to string. • Can two variables have the same letters but different capitalization, as in variableName and VariableName? No, Java is a case-sensitive language. It differentiates the two variables, variableName and VariableName. ©NIIT Collaborate Lesson 2C / Slide 17 of 20
  • 18. Collaborate Challenge 1. Java is a platform ______ language . 2. Match the following: a.      Variables i. Reserved words b.      Literals ii. Basic storage unit c.      Keywords iii. Sequence of characters 3. Make words from the jumbled letters in the box given below and match them with their description. a. Class members that can be accessed by the subclasses of the class in which they are declared. b. Class members that are accessible to all the classes of a package by default. c. Class members that can be accessed only by the objects of the same class. d. Class members that can be accessed anywhere in the same class. ©NIIT Collaborate Lesson 2C / Slide 18 of 20
  • 19. Collaborate Challenge (Contd.) e. This method of the String class is used to find the length of a string. f. Collection of classes that can be reused. g. Are the reserved words for a language. h. A method with the same name as the class name IULBPC DFINRE ORETCDPET ELHTGN VPTIARE CKESPAAGS KRDYOESW CNTCSUOORRT ©NIIT Collaborate Lesson 2C / Slide 19 of 20
  • 20. Collaborate Solutions to Challenge • independent • a-ii, b-iii, c-i • a. Protected, b. Friend, c. Private, d. Public, e. length, f. packages, g. keywords, h. constructor ©NIIT Collaborate Lesson 2C / Slide 20 of 20