• Save
Dacj 1-2 c
Upcoming SlideShare
Loading in...5
×
 

Dacj 1-2 c

on

  • 718 views

 

Statistics

Views

Total Views
718
Views on SlideShare
664
Embed Views
54

Actions

Likes
0
Downloads
0
Comments
0

4 Embeds 54

http://niitcourseslides.blogspot.in 43
http://efesto.cloudapp.net 7
http://localhost 3
http://niitcourseslides.blogspot.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Dacj 1-2 c Dacj 1-2 c Presentation Transcript

  • CollaborateKnowledge 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
  • CollaborateEvolution 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
  • CollaborateEvolution 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
  • CollaborateEvolution 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
  • CollaborateGarbage 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
  • CollaborateSetting 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
  • CollaborateSignificance 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
  • CollaborateFrom 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
  • CollaborateBest PracticesDeclaring class variables as private and methodsas 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
  • CollaborateBest PracticesDeclaring 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
  • CollaborateBest PracticesDeclaring 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
  • CollaborateTips and TricksDisplaying 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
  • CollaborateTips and TricksSetting 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
  • CollaborateFAQs • 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
  • CollaborateFAQs (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
  • CollaborateFAQs (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
  • CollaborateFAQs (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
  • CollaborateChallenge 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
  • CollaborateChallenge (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
  • CollaborateSolutions 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