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.

JAVA INTRODUCTION

319 views

Published on

Java is a general-purpose; object oriented programming language developed by Sun Microsystems of USA in 1991. This language was initially called “Oak” by James Gosling, but was renamed “Java” in 1995. Java (with a capital J) is a high-level, third generation programming language, like C, Fortran, Smalltalk, Perl, and many others.Java was initially designed to solve on a small scale could also be applied to the Internet on a large scale. This realization caused the focus of Java to switch from consumer electronic to Internet Programming.Java was designed for the development of software for consumer electronic devices like TVs, VCRs, Toasters, Microwaves ovens and such other electronics devices.Java is a first programming language that is not tied to any particular hardware or operating system. Programs developed in Java can be executed anywhere on any system.

Published in: Engineering
  • Be the first to comment

  • Be the first to like this

JAVA INTRODUCTION

  1. 1. For More : https://www.ThesisScientist.com JAVA INTRODUCTION Java is a general-purpose; object oriented programming language developed by Sun Microsystems of USA in 1991. This language was initially called “Oak” by James Gosling, but was renamed “Java” in 1995. Java (with a capital J) is a high-level, third generation programming language, like C, Fortran, Smalltalk, Perl, and many others.Java was initially designed to solve on a small scale could also be applied to the Internet on a large scale. This realization caused the focus of Java to switch from consumer electronic to Internet Programming.Java was designed for the development of software for consumer electronic devices like TVs, VCRs, Toasters, Microwaves ovens and such other electronics devices.Java is a first programming language that is not tied to any particular hardware or operating system. Programs developed in Java can be executed anywhere on any system. FEATURES OF JAVA 1 Platform Independence The concept of Write-once-run-anywhere (known as the Platform independent) is one of the important key feature of java language that makes java as the most powerful language. The programs written on one platform can run on any platform provided the platform must have the JVM. 2 Object Oriented Object oriented throughout - no coding outside of class definitions, including main(). An extensive class library available in the core language packages. 3 Compiler/Interpreter Combo Code is compiled to bytecodes that are interpreted by Java virtual machines (JVM). This provides portability to any machine for which a virtual machine has been written. The two steps of compilation and interpretation allow for extensive code checking and improved security. 4 Several dangerous features of C & C++ eliminated: No memory pointers No preprocessor Array index limit checking
  2. 2. For More : https://www.ThesisScientist.com 5 Automatic Memory Management Automatic garbage collection - memory management handled by JVM. 6 Security No memory pointers Programs run inside the virtual machine sandbox. Array index limit checking Code pathologies reduced by 1) bytecode verifier - checks classes after loading 2) class loader - confines objects to unique namespaces. Prevents loading a hacked "java.lang.SecurityManager" class, for example. 3) security manager - determines what resources a class can access such as reading and writing to the local disk. 7 Dynamic Binding The linking of data and methods to where they are located, is done at run-time. New classes can be loaded while a program is running. Linking is done on the fly. Even if libraries are recompiled, there is no need to recompile code that uses classes in those libraries. This differs from C++, which uses static binding. 8 Good Performance Interpretation of bytecodes slowed performance in early versions, but advanced virtual machines with adaptive and just-in-time compilation and other techniques now typically provide performance up to 50% to 100% the speed of C++ programs. 9 Threading Lightweight processes, called threads, can easily be spun off to perform multiprocessing. Can take advantage of multiprocessors where available Great for multimedia displays. 10 Built-in Networking Java was designed with networking in mind and comes with many classes to develop sophisticated Internet communications.
  3. 3. For More : https://www.ThesisScientist.com How Java differs from C & C++ Java was modeled after C and C++ languages, it differs from C and C++ in many ways. 1 There is no header files in Java. 2 Java does not use pointers. 3 Java does not support Global variable. 4 Java does not support operator overloading. 5 Java does not have a preprocessor, and as such, does not have #defines or macros. Constants can be created by using the final modifier when declaring class and instance variables. 6 The goto keyword does not exist in Java. You can, however, use labeled breaks and continues to break out of and continue executing complex switch or loop constructs. 7 ava does not support multiple inheritance of classes. 8 Java does not have template classes as in C++. 9 Java does not contain the data types struct and union. JAVA PROGRAMS Java can be used two types of programs: applications & applets.An application is a program that runs on your computer, under the operating system of that computer. An applets is an application designed to be transmitted over the Internet and executed by a java-compatible Web Browser. An applet is an executable program that runs inside a browser, such as Netscape or Internet Explorer. How applets is different from applications 1 Applets do not use the main() method, but when they are load automatically call certain methods like init, start, paint, stop.
  4. 4. For More : https://www.ThesisScientist.com 2 They are embedded inside a web page and executed in browsers. 3 They cannot read from or write to the files on local computers. 4 They can not communicate with the other servers on the network. 5 They can not run any program from local computers. APPLET INTRODUCTION An applet is an executable program that runs inside a browser, such as Netscape or Internet Explorer or the Applet Viewer program. An applet is a window-based program. Its architectures is different from the so-called normal, console based programs. The first browser that could show applets was introduced in 1994, as "WebRunner" - later known as "The HotJava Browser". Applets are small java programs that are embedded in web pages. They can be transmitted over the internet from one computer (web server) to another computer (client computers). They transform web into rich media and support the delivery of application via the internet. An applet can be embedded into a webpage. Usually the applet has several settings that will allow you to personalize it. When you put an applet on your page you will need to save the applet on your server as well as the HTML page the applet is embedded in. Applets are Event driven. An applet resembles a set of interrupt services routines. An applet waits until an event occurs. The AWT notifies the applet about an event by calling an event handler that has been provided by the applet. Applet class is extended by java.applet.* package. AWT(Abstract Window Toolkit) The Abstract Window Toolkit (AWT) is Java's original platform-independent windowing, graphics, and user-interface widget toolkit. The AWT is both powerful and flexible. It contains all classes to write the program that interface between the user and different windowing toolkits. You can use the AWT package to develop user interface objects like buttons, checkboxes, radio buttons and menus etc. AWT are supported by java.awt.* package. All AWT components extend class Component. Think of Component as the "root of all evil" for AWT. Having this single class is rather useful, as the library designers can put a lot of common code into it. AWT components are buttons, checkbox, label, checkbox group, choice, scrollbar, textfield, textarea, list etc. Advantages of Applet:
  5. 5. For More : https://www.ThesisScientist.com 1 Applets can work all the version of Java Plugin. 2 Applets runs in a sandbox, so the user does not need to trust the code, so it can work without security approval. 3 Applets are supported by most web browsers. 4 Applets are cached in most web browsers, so will be quick to load when returning to a web page. 6 User can also have full access to the machine if user allows 7 Applets are cross platform and can run on Windows, Mac OS and Linux platform. APPLETS LIFE CYCLE The life cycle of an applet is determined by methods that are automatically called at its birth, its death and when it is momentarily away. Applet runs in the browser and its lifecycle method are called by JVM when it is loaded and destroyed. Here are the lifecycle methods of an Applet: init() method:- This method is called to initialized an applet. The life cycle of an applet is begin on that time when the applet is first loaded into the browser and called the init() method. The init() method is called only one time in the life cycle on an applet. All the initialization such as initialization of variables and the objects like image, sound file are loaded in the init () method .After the initialization of the init() method user can interact with the Applet and mostly applet contains the init() method. start() method:- The start method of an applet is called after the initialization method init(). This method may be called multiples time when the Applet needs to be started or restarted. For Example if the user wants to return to the Applet, in this situation the start Method() of an Applet will be called by the web browser and the user will be back on the applet. In the start method user can interact within the applet.
  6. 6. For More : https://www.ThesisScientist.com paint() method:- The paint() method is called each time your applet’s output must be redrawn. This situation can occur for several reasons. For example, the window in which the applet is running may be overwritten by another window and then uncovered. Or the applet window may be minimized and then restored. paint() is also called when the applet begins execution. stop() method:- This method can be called multiple times in the life cycle of an Applet. Or should be called at least one time. There is only miner difference between the start() method and stop () method. For example the stop() method is called by the web browser on that time When the user leaves one applet to go another applet and the start() method is called on that time when the user wants to go back into the first program or Applet. destroy() method:- This method is called only once in the life cycle of the applet when applet is destroyed. This method is called only on that time when the browser needs to shut down. Applet Life Cycle Diagram:-
  7. 7. For More : https://www.ThesisScientist.com APPLETS EVENT Applets are event-driven programs. The event handling is at the core of successful applet programming. Events are supported by java.awt.event package. An event is an object that describes a state change in a source. It can be generated as a consequence of a person interacting with the elements in a Graphical User Interface(GUI). Some of the activities that causes events to be generated are pressing a button, entering a character via the keyboard, selecting an item in a list and clicking the mouse. There are mainly three steps of Event Handling : 1) Prepare to accept events import package java.awt.event 2) Start listening for events include appropriate methods 3) Respond to events implement appropriate abstract method Event Listener:- A listener is an object that is notified when an event occurs. The event listener is the feature of java that handles the several events for the several objects, Such as: MouseEvent, KeyEvent, TextEvent, InputEvent, ActionEvent etc. 1 The ActionListener Interface:- This interface defines the actionperformed( ) method that is invoked when an action event occurs. The general form is shown here: void actionPerformed(ActionEvent ae) 2 The AdjustmentListener Interface:- This interface defines the adjustmentValueChanged( ) method that is invoked when an
  8. 8. For More : https://www.ThesisScientist.com adjustment event occurs. The general form is shown here: void adjustmentValueChanged(AdjustmentsEvent ae) 3 The ItemListener Interface:- This interface defines the itemStateChanged( ) method that is invoked when the state of an item changes. Its general form is shown here: Void itemStateChanged(ItemEvent ie) 4 The KeyListener Interface:- This interface defines some methods. The keyPressed( ) and keyReleased( ) methods are invoked when a key is pressed and released respectively. The keyTyped( ) method is invoked when a character has been entered.

×