Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

A begineers guide of JAVA - Getting Started


Published on

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

A begineers guide of JAVA - Getting Started

  1. 1. Module 1 Getting Started
  2. 2. <ul><ul><li>Objectives </li></ul></ul><ul><ul><li>• Describe key features of Java technology. </li></ul></ul><ul><ul><li>• Describe the Java virtual machine’s (JVM) function. </li></ul></ul><ul><ul><li>• Describe how garbage collection works. </li></ul></ul><ul><li>• Write, compile, and run a simple Java application. </li></ul><ul><li>• List the task performed by Java platform that handle </li></ul><ul><li>code security </li></ul>
  3. 3. Definition • A high-level programming language • O riginally called OAK . • In 1995 name changed to Java and also modified to take advantage of World Wide Web.
  4. 4. How Java works • A program is both compiled and interpreted. • With the compiler, first you translate a program into an intermediate language called Java bytecodes • This platform-independent code is interpreted by the interpreter • The interpreter parses and runs each Java bytecode • Compilation happens just once • Interpretation occurs each time the program is executed.
  5. 6. Key Features of Java Programming Language 1. Platform Independence Java compilers do not produce native object code for a particular platform but rather ‘byte code’ instructions for the Java Virtual Machine (JVM). 2. Object Orientation Java is a pure object-oriented language. This means that everything in a Java program is an object and everything is descended from a root object class.
  6. 7. 3. Rich Standard Library The Java environment includes hundreds of classes and methods in six major functional areas. 1. Language Support 2. Utility 3. Input/output 4. Networking 5. Abstract Window Toolkit 6. Applet 4. Familiar C++ like Syntax 5 . Garbage Collection - Java does not require programmers to explicitly free dynamically allocated memory. This makes Java programs easier to write and less prone to memory errors.
  7. 8. <ul><ul><li>6. Multithreaded </li></ul></ul><ul><ul><li>Java Support multithreaded programming,which allow you to write programs that do many things simultaneously. </li></ul></ul><ul><li> </li></ul>
  8. 12. Java Virtual Machine Functionality • Provides hardware platform specifications • Reads compiled byte codes that are platform independent • The Java interpreter installed on your computer implements the Java VM.
  9. 13. Java Platform
  10. 14. <ul><ul><li>Java Development Kit </li></ul></ul><ul><ul><li>• A Java software development environment from Sun. </li></ul></ul><ul><ul><li>• It includes the compiler, JVM, debugger and other </li></ul></ul><ul><ul><li>tools for developing Java applets and applications. </li></ul></ul><ul><ul><li>• Each new version of the JDK adds features and </li></ul></ul><ul><ul><li>enhancements to the language. </li></ul></ul><ul><ul><li>• When Java programs are developed under the </li></ul></ul><ul><ul><li>new version,the Java interpreter (Java Virtual Machine) </li></ul></ul><ul><ul><li>that executes them must also be updated to that same </li></ul></ul><ul><ul><li>version. </li></ul></ul>
  11. 15. <ul><ul><li>J ava R untime E nvironment </li></ul></ul><ul><ul><li>A subset of the Java Development Kit (JDK), provides the minimum requirements for executing a Java application . The JRE includes the Java Virtual Machine (JVM), core classes, and supporting files . </li></ul></ul>
  12. 16. <ul><ul><li>Classpath </li></ul></ul><ul><ul><li>A way to tell the JVM, where to find your </li></ul></ul><ul><ul><li>source code, as well as any other classes or objects </li></ul></ul><ul><ul><li>that are required by your application. </li></ul></ul><ul><ul><li>The CLASSPATH contains directories (or JAR files), </li></ul></ul><ul><ul><li>from where your java compiler/runtime will </li></ul></ul><ul><ul><li>look for .class files </li></ul></ul><ul><ul><li>Path The PATH variable contains directories where </li></ul></ul><ul><ul><li>binary files (e.g. EXE files in Windows) will be </li></ul></ul><ul><ul><li>looked for. </li></ul></ul>
  13. 18. Consider MyClass myRef = new MyClass(); this creates an object somewhere in the heap, it also creates a reference variable called 'myRef' that effectively points to the spot in the heap where the object is. Consider the right side indicates the heap and left side is list of references, draw an arrow to show where each ref is pointing to. MyClass ref2 = myRef; We have two things on the left, each with an arrow pointing to the single object on the right.
  14. 19. Go through the code line by line, drawing and erasing arrows as Needed, you can then see when an object has no arrows pointing to it, thus making it eligible for garbage collection. Ways to call garbage collector algorithms In reality, it is possible only to suggest to the JVM that it perform garbage collection. However, there are no guarantees the JVM will actually remove all of the unused objects from memory. The garbage collection routines that Java provides are members of the Runtime class. The Runtime class is a special class that has a single object (a Singleton) for each main program.
  15. 20. The Runtime object provides a mechanism for communicating directly with the virtual machine. To get the Runtime instance, you can use the method Runtime.getRuntime(), which returns the Singleton. Once you have the Singleton you can invoke the garbage collector using the gc() method. Alternatively, you can call the same method on the System class, which has static methods that can do the work of obtaining the Singleton for you. System.gc(); Example
  16. 23. Class Loader Loads all classes necessary for the execution of a program. Bytecode Verifier Java compilers perform extensive compile-time checking on the source code they compile. However, the Java Virtual Machine (JVM) cannot rely on compile-time checking because it has no way of determining whether the class files it interprets were produced by a trustworthy Java compiler or by a malicious user.  
  17. 24. Verifier serves to make sure that class files loaded into the JVM respect certain security-related properties like • the class file’s syntax, • the behavior of its code and • the potential interdependencies that it has with other class files.
  18. 25. Suppose If a buggy compiler generated a class file that contained a method whose bytecodes included an instruction to jump beyond the end of the method, that method could, if it were invoked, cause the virtual machine to crash. Thus, for the sake of robustness, it is important that the virtual machine verify the integrity of the bytecodes it imports.