1 / 46

PROGRAMMING IN JAVA

Explore the evolution and key features of Java programming language, from its inception by Sun Microsystems in 1995 to its widespread use today for desktop GUI, mobile, embedded systems, web applications, and more.

degraw
Download Presentation

PROGRAMMING IN JAVA

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PROGRAMMING IN JAVA SUBMITTED BY MADHU MADHAN LECTURE IN CSE GP MEHAM

  2. PROGRAMMING IN JAVA • Java is a general-purpose computer-programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible.

  3. WORK ON JAVA • Java is a programming language and computing platform first released by Sun Microsystems in 1995. There are lots of applications and websites that will not work unless you have Java installed, and more are created every day. Java is fast, secure, and reliable. From laptops to datacenters, game consoles to scientific supercomputers, cell phones to the Internet, Java is everywhere!.

  4. A Brief History of Java • In 1990, Sun Microsystems began a project called Green to develop software for consumer electronics. Developer, Gosling began writing software in C++ for embedding into such items as toasters, VCR’s, and Personal Digital Assistants (PDA’s). The embedded software makes many appliances more intelligent. Gosling’s solution to the problems of C++ was a new language called Oak. Finally in 1995, Oak was renamed Java. Since then Java has been rising in popularity.

  5. JAVA VIRTUAL MACHINE • A Java virtual machine (JVM), an implementation of the Java Virtual Machine Specification, interprets compiled Java binary code (called bytecode) for a computer's processor (or "hardware platform") so that it can perform a Java program's instructions. Java was designed to allow application programs to be built that could be run on any platform without having to be rewritten or recompiled by the programmer for each separate platform. A Java virtual machine makes this possible because it is aware of the specific instruction lengths and other particularities of the platform.

  6. FEATURES JAVA • Simple • Object-Oriented • Portable • Platform independent • Secured • Robust • Architecture neutral • Interpreted • High Performance • Multithreaded • Distributed • Dynamic

  7. NATIVE CODE • Native code is computer programming (code) that is compiled to run with a particular processor (such as an Intel x86-class processor) and its set of instructions. If the same program is run on a computer with a different processor, software can be provided so that the computer emulates the original processor. In this case, the original program runs in "emulation mode" on the new processor and almost certainly more slowly than in native mode on the original processor. (The program can be rewritten and recompiled so that it runs on the new processor in native mode.)

  8. JAVA APPLICATION TYPES

  9. 1. Desktop GUI Applications: • Java provides GUI development through various means like Abstract Windowing Toolkit (AWT), Swing and JavaFX. While AWT contains a number of pre-constructed components such as menu, button, list, and numerous third-party components, Swing, a GUI widget toolkit, additionally provides certain advanced components like trees, tables, scroll panes, tabbed panel and lists. JavaFX, a set of graphics and media packages, provides Swing interoperability, 3D graphic features and self-contained deployment model which facilitates quick scripting of Java applets and applications.

  10. 2. Mobile Applications: • Java Platform, Micro Edition (Java ME or J2ME) is a cross-platform framework to build applications that run across all Java supported devices, including feature phones and smart phones. Further, applications for Android, one of the most popular mobile operating systems, are usually scripted in Java using the Android Software Development Kit (SDK) or other environments. • 3. Embedded Systems: • Embedded systems, ranging from tiny chips to specialized computers, are components of larger electromechanical systems performing dedicated tasks. Several devices, such as SIM cards, blue-ray disk players, utility meters and televisions, use embedded Java technologies. According to Oracle, 100% of Blu-ray Disc Players and 125 million TV devices employ Java

  11. 4. Web Applications: • Java provides support for web applications through Servlets, Struts or JSPs. The easy programming and higher security offered by the programming language has allowed a large number of government applications for health, social security, education and insurance to be based on Java. Java also finds application in development of eCommerce web applications using open-source eCommerce platforms, such as Broadleaf. • 5. Web Servers and Application Servers: • The Java ecosystem today contains multiple Java web servers and application servers. While Apache Tomcat, Simple, Jo!, Rimfaxe Web Server (RWS) and Project Jigsaw dominate the web server space, WebLogic, WebSphere, and Jboss EAP dominate commercial application server space.

  12. . Enterprise Applications: • Java Enterprise Edition (Java EE) is a popular platform that provides API and runtime environment for scripting and running enterprise software, including network applications and web-services. Oracle claims Java is running in 97% of enterprise computers. The higher performance guarantee and faster computing in Java has resulted in high frequency trading systems like Murex to be scripted in the language. It is also the backbone for a variety of banking applications which have Java running from front user end to back server end. • 7. Scientific Applications: • Java is the choice of many software developers for writing applications involving scientific calculations and mathematical operations. These programs are generally considered to be fast and secure, have a higher degree of portability and low maintenance. Applications like MATLAB use Java both for interacting user interface and as part of the core system.

  13. COMPARISONS BETWEEN C and C++ • C was developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Labs. • C++ was developed by BjarneStroustrup in 1979 with C++'s predecessor "C with Classes". • When compared to C++, C is a subset of C++. • C++ is a superset of C. C++ can run most of C code while C cannot run C++ code. • C supports procedural programming paradigm for code development. • C++ supports both procedural and object oriented programming paradigms; therefore C++ is also called a hybrid language. • C does not support object oriented programming; therefore it has no support for polymorphism, encapsulation, and inheritance. • Being an object oriented programming language C++ supports polymorphism, encapsulation, and inheritance. • In C (because it is a procedural programming language), data and functions are separate and free entities. • In C++ (when it is used as object oriented programming language), data and functions are encapsulated together in form of an object. For creating objects class provides a blueprint of structure of the object.

  14. JAVA IDENTIFIERS • Identifiers in Java. Identifiers are the names of variables, methods, classes, packages and interfaces. Unlike literals they are not the things themselves, just ways of referring to them. In the HelloWorld program, HelloWorld , String , args , main and println are identifiers.

  15. Keywords,Literals • Keywords are reserved words that have a specific meaning for the compiler. They cannot be used as identifiers. Java has a rich set of keywords. Some examples are: boolean, char, if, protected, new, this, try, catch, null, threadsafe etc. • 3. Literals • Literals are variables whose values remain constant throughout the program. They are also called Constants. 

  16. Data type in java • Data type specifies the size and type of values that can be stored in an identifier. The Java language is rich in its data types. Different data types allow you to select the type appropriate to the needs of the application. • Data types in Java are classified into two types. • Primitive—which include Integer, Character, Boolean, and Floating Point. • Non-primitive—which include Classes, Interfaces, and Arrays.

  17. Primitive Data Types • Integer types can hold whole numbers such as 123 and −96. The size of the values that can be stored depends on the integer type that we choose. •  Floating Point • Floating point data types are used to represent numbers with a fractional part. Single precision floating point numbers occupy 4 bytes and Double precision floating point numbers occupy 8 bytes. •  Boolean • Boolean data types are used to store values with two states: true or false.

  18. VARIABLES • Variables • A variable has these attributes:Name   The string of letters in a program used to designate a variable. • A name should start with a letter and consist of letters and/or digits.Variables in names are case sensitive (capitalization matters).The naming convention in Java is to start a variable name with a lower case letter.New words within a name with a name start with a capital letter(example: numberOfCustomers). • Value   The binary data contained in memory. The value is interpreted according to the variable's datatype. • Address   The location in memory where the value is stored. • Size   The number of bytes that the variable occupies in memory. • Datatype   The interpretation of the value. Some important datatypes are listed in the following table. • Range   The minimum and maximum values of the variable. The range of a variable depends on its size. In general, the bigger the size in bytes, the bigger the range.

  19. CONSTANTS • A constant is a value that cannot be changed. • Examples of integer constants:354, -37, 0, 246543 (no commas). • Examples of floating point constants:4.642, -0.034, 5.98e24 (mass of earth), 9.11e-31 (mass of electron) • Examples of character constants:'A', 'y', '8', '*', ' ' (space), '\n' (new line).A character can be stored in memory using its ASCII Code. ASCII means American System of Computer Information Interchange. 

  20. OPERATERS

  21. control flow statement in java • The statements inside your source files are generally executed from top to bottom, in the order that they appear. Control flow statements, however, break up the flow of execution by employing decision making, looping, and branching, enabling your program to conditionally execute particular blocks of code. This section describes the decision-making statements (if-then, if-then-else, switch), the looping statements (for, while, do-while), and the branching statements (break, continue, return) supported by the Java programming language.

  22. Loops in Java

  23. for loop,whileloop,dowhile loop • for loop • The Java for loop is a control flow statement that iterates a part of the programs multiple times.while loop • The Java while loop is a control flow statement that executes a part of the programs repeatedly on the basis of given boolean condition. • do while loop • The Java do while loop is a control flow statement that executes a part of the programs at least once and the further execution depends upon the given boolean condition.

  24. Arrays in Java • An array is a group of like-typed variables that are referred to by a common name.Arrays in Java work differently than they do in C/C++. Following are some important point about Java arrays. • In Java all arrays are dynamically allocated.(discussed below) • Since arrays are objects in Java, we can find their length using member length. This is different from C/C++ where we find length using sizeof. • A Java array variable can also be declared like other variables with [] after the data type. • The variables in the array are ordered and each have an index beginning from 0. • Java array can be also be used as a static field, a local variable or a method parameter. • The size of an array must be specified by an int value and not long or short. • The direct superclass of an array type is Object. • Every array type implements the interfaces Cloneable and java.io.Serializable

  25. Casting ,string • Well, all casting really means is taking an Object of one particular type and “turning it into” another Object type. This process is called casting a variable. This topic is not specific to Java, as many other programming languages support casting of their variable types. • string is a sequence of characters but it's not a primitive type. When we create a string in java, it actually creates an object of type String. String is immutable object which means that it cannot be changed once it is created. String is the only class where operator overloading is supported in java.

  26. classes • A class is a user defined blueprint or prototype from which objects are created.  It represents the set of properties or methods that are common to all objects of one type. In general, class declarations can include these components, in order: • Modifiers : A class can be public or has default access (Refer this for details). • Class name: The name should begin with a initial letter (capitalized by convention). • Superclass(if any): The name of the class’s parent (superclass), if any, preceded by the keyword extends. A class can only extend (subclass) one parent. • Interfaces(if any): A comma-separated list of interfaces implemented by the class, if any, preceded by the keyword implements. A class can implement more than one interface. • Body: The class body surrounded by braces, { }.

  27. Declaring classes • This is a class declaration. The class body (the area between the braces) contains all the code that provides for the life cycle of the objects created from the class: constructors for initializing new objects, declarations for the fields that provide the state of the class and its objects, and methods to implement the behavior of the class and its objects. • The preceding class declaration is a minimal one. It contains only those components of a class declaration that are required. You can provide more information about the class, such as the name of its superclass, whether it implements any interfaces, and so on, at the start of the class declaration. For example, • class MyClass extends MySuperClass implements YourInterface { // field, constructor, and // method declarations }.

  28. Member Classes • A member class is a class that is declared as a non-static member of a containing class. If a static member class is analogous to a class field or class method, a member class is analogous to an instance field or instance method. Example 3-9 shows how a member class can be defined and used. This example extends the previous LinkedStack example to allow enumeration of the elements on the stack by defining an enumerate() method that returns an implementation of the java.util.Enumeration interface. The implementation of this interface is defined as a member class.

  29. Passing value of method • The two most prevalent modes of passing arguments to methods are “passing-by-value” and “passing-by-reference”. Different programming languages use these concepts in different ways. As far as Java is concerned, everything is strictly Pass-by-Value. • The two most prevalent modes of passing arguments to methods are “passing-by-value” and “passing-by-reference”. ... • It means that while calling a method, parameters passed to the calleemethod will be clones of original parameters.

  30. Method Overloading • Method Overloading is a feature that allows a class to have more than one method having the same name, if their argument lists are different. It is similar to constructor overloading in Java, that allows a class to have more than one constructor having different argument lists. • There are two ways to overload the method in java • By changing number of arguments • By changing the data type

  31. encapsulation, polymorphism • Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit. In encapsulation, the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class. Therefore, it is also known as data hiding. • polymorphism means many forms. There are two types of polymorphism in Java: compile-time polymorphismand runtime polymorphism. We can performpolymorphism in java by method overloading and method overriding. If you overload a static method in Java, it is the example of compile time polymorphism.

  32. Constructors, finalizers • Constructor is a block of code that initializes the newly created object. A constructor resembles an instance method in java but it’s not a method as it doesn’t have a return type. In short constructor and method are different(More on this at the end of this guide). People often refer constructor as special type of method in Java. • The java.lang.Object.finalize() is called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

  33. Garbage Collection, java modifiers • In Java, the programmers don't need to take care of destroying the objects that are out of use. ... • Garbage Collector is a Daemon thread that keeps running in the background. ... • Unreachable objects are the ones that are no longer referenced by any part of the program • Java provides a number of non-access modifiersto achieve many other functionality. • The static modifier for creating class methodsand variables. • The final modifier for finalizing the implementations of classes, methods, and variables. • The abstract modifier for creating abstract classes and methods.

  34. java packages

  35. Create PACKAGE  • A Package is a collection of related classes. It helps organize your classes into a folder structure and make it easy to locate and use them. More importantly, it helps improve re-usability. • Each package in Java has its unique name and organizes its classes and interfaces into a separate namespace, or name group. • Although interfaces and classes with the same name cannot appear in the same package, they can appear in different packages. This is possible by assigning a separate namespace to each package.

  36. Exceptions

  37. Exceptions • An exception is an unwanted or unexpected event, which occurs during the execution of a program i.e at run time, that disrupts the normal flow of the program’s instructions. • Error vs Exception • Error: An Error indicates serious problem that a reasonable application should not try to catch.Exception: Exception indicates conditions that a reasonable application might try to catch.

  38. Exception Hierarchy • All exception and errors types are sub classes of class Throwable, which is base class of hierarchy.One branch is headed by Exception. This class is used for exceptional conditions that user programs should catch. NullPointerException is an example of such an exception.Anotherbranch,Error are used by the Java run-time system(JVM) to indicate errors having to do with the run-time environment itself(JRE). StackOverflowError is an example of such an error.

  39. thread life cycle in java

  40. Thread scheduler picks one of the thread from the runnablethread pool and change it's state to Running. Then CPU starts executing this thread. Athread can change state to Runnable, Dead or Blocked from running state depends on time slicing,thread completion of run() method or waiting for some resources.

  41. synchronization • Synchronized keyword in Java is used to provide mutually exclusive access to a shared resource with multiple threads in Java. Synchronization in Javaguarantees that no two threads can execute asynchronized method which requires the same lock simultaneously or concurrently.

  42. java applets vs java applications • Anapplet is a program written in the Javaprogramming language that can be included in an HTML page, much in the same way an image is included. An application is a standalone Java program that runs as a true application, outside of a browser. Both require a JVM (Java Virtual Machine).

  43. HTML

  44. HTML tutorial or HTML 5 tutorial provides basic and advanced concepts of HTML. Our HTML tutorial is developed for beginners and professionals. In our tutorial, every topic is given step-by-step so that you can learn it in a very easy way. If you are new in learning HTML, then you can learn HTML from basic to a professional level and after learning HTML with CSS and JavaScript you will be able to create your own interactive and dynamic website. But Now We will focus on HTML only in this tutorial. • The major points of HTML are given below: • HTML stands for HyperText Markup Language. • HTML is used to create web pages and web applications. • HTML is widely used language on the web. • We can create a static website by HTML only. • Technically, HTML is a Markup language rather than a programming language.

More Related