Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to JAVA Infobizzs.com.

Similar presentations


Presentation on theme: "Introduction to JAVA Infobizzs.com."— Presentation transcript:

1 Introduction to JAVA Infobizzs.com

2 Introduction Infobizzs.com History
Java is related to C++, which is a direct descendent of C. Much of the character of Java is inherited from these two languages. From C, Java derives its syntax. Many of Java’s object- oriented features were determined by C++. Java was developed by James Gosling, Patrick Naughton, Chris Warth, Ed Frank, and Mike Sheridan at Sun Microsystems, Inc.in It took 18 months to develop the first working version. This language was initially called “Oak” but was renamed “Java” in 1995. Infobizzs.com

3 Comparison between OOP and pure OOP
Unlike C++, java is pure object oriented programming language. Pure OOP organizes a program around its data (i.e. objects) and set of well defined interfaces (i.e. methods) to that data. Pure OOP means all of the data types in the language are objects and all of the operations on those objects are methods. You can’t code anything in java without declaring classes and objects. Everything in java is an object. All the program codes and data resides within classes and objects. Infobizzs.com

4 Advantages of java Infobizzs.com Simple:
If you already understand the basic concepts of object- oriented programming, moving to Java will require very little effort because Java inherits the C/C++ syntax and many of the object-oriented features of C++. Java was designed to be easy to use and is therefore easy to write, compile, debug, and learn than other programming languages. Infobizzs.com

5 Continue… Infobizzs.com Secure:
When you use a Java-compatible Web browser, you can safely download Java applets without fear of viral infection. Java achieves this protection by providing a “firewall” between a networked application and your computer. Java system not only verify all memory access but also ensure that no viruses are communicated with an applet. The absence of pointers in java ensures that programs cannot gain access to memory locations without proper authorization. Infobizzs.com

6 Continue… Infobizzs.com Portable and Platform Independent:
One of the most significant advantages of Java is its ability to move easily from one computer system to another. Today many types of computers and operating systems are in used throughout the world and many are connected to the Internet. We can download a java applet from a remote computer onto our local system via internet and execute it locally. You can run java program on any type of operating system because of its portability.   Infobizzs.com

7 Continue… Infobizzs.com Object- Oriented:
One of the most key features of java is Object Oriented. Java is object-oriented because programming in Java is centered on creating objects, manipulating objects, and making objects work together. This allows you to create modular programs and reusable code. Infobizzs.com

8 Continue… Infobizzs.com Robust: Robust means reliable.
It provides many safeguards to ensure reliable code. It has strict compile time and runtime checking for data types. In C/C++, the programmer must manually allocate and free all dynamic memory. This sometimes leads to problems, because programmers will either forget to free memory that has been previously allocated or, worse, try to free some memory that another part of their code is still using. Infobizzs.com

9 Continue… Infobizzs.com
Java virtually eliminates these problems by managing memory allocation and deallocation. Deallocation is completely automatic, because Java provides garbage collection for unused objects. Java also incorporates the concept of exception handling which captures serious errors and eliminates any risk of crashing the system. Infobizzs.com

10 Continue… Infobizzs.com Multithreaded:
Java supports multithreaded programming, which allows you to write programs that do many things simultaneously.  Architecture-Neutral: Nowadays Operating system upgrades, processor upgrades, and changes in core system resources can all combine that make a program failure and doesn’t work properly. Once you written a java program, you can run this program anywhere, anytime forever. Infobizzs.com

11 Continue… Infobizzs.com Interpreted and High Performance:
The output of a Java compiler is not executable code. Rather, it is bytecode. The Java bytecode was carefully designed so that it would be easy to translate directly into native machine code for very high performance by using a just-in-time compiler. Infobizzs.com

12 Continue… Infobizzs.com Compiled and Interpreted:
Usually, a computer language is either compiled or interpreted. Java combines both these approaches. Thus making java a two stage system. First, java compiler translates source code into bytecode. Bytecodes are not machine instructions and therefore, in the second stage, java interpreter generates machine code that can be directly executed by the machine that is running the java program. We can thus say that java is both a compiled and an interpreted language. Infobizzs.com

13 Continue… Infobizzs.com Distributed:
Distributed computing involves several computers on a network working together. Java is designed to make distributed computing easy with the networking capability that is inherently integrated into it.  Writing network programs in Java is like sending and receiving data to and from a file. For example, three programs running on three different systems, communicating with each other to perform a joint task. Infobizzs.com

14 Continue… Infobizzs.com Dynamic:
Java programs carry with them substantial amounts of run- time type information that is used to verify and resolve accesses to objects at run time. This makes it possible to dynamically link code in a safe manner. Infobizzs.com

15 Features of java Infobizzs.com Encapsulation
Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse. Or The wrapping up of data and methods into single unit is known as encapsulation. Infobizzs.com

16 Continue… Infobizzs.com Inheritance
Inheritance is the process by which one object acquires the properties of another object. This is important because it supports the concept of hierarchical classification. For example, the bird sparrow is a part of the class flying bird, which is again a part of the class bird. Infobizzs.com

17 Continue… Infobizzs.com

18 Continue… Infobizzs.com Polymorphism
Polymorphism is a feature that allows one interface to be used for a general class of actions. The concept of polymorphism is often expressed by the phrase “one interface, multiple methods.” This means that it is possible to design a generic interface to a group of related activities. Infobizzs.com

19 What is byte code? Infobizzs.com
The output of a Java compiler is not executable code. it is bytecode. Bytecode is a highly optimized set of instructions to be executed by the Java run-time system, which is called the Java Virtual Machine (JVM). JVM is an interpreter for Bytecode. Bytecodes are a set of instructions that is not specific to any one processor. When we compile a program written in C or in most other languages, the compiler translates our program into machine codes. Those instructions are specific to the processor your computer is running. Infobizzs.com

20 Continue… Infobizzs.com
So, for example, if you compile your code on a Pentium system, the resulting program will run only on other Pentium systems. If you want to use the same program on another system, you have to go back to your original source, get a compiler for that system, and recompile your code. Things are different when you write code in Java. The Java development environment has two parts: a Java compiler and a Java interpreter. The Java compiler takes your Java program and instead of generating machine codes from your source files, it generates bytecodes. Infobizzs.com

21 Traditional compiled programs
Continue… Traditional compiled programs Infobizzs.com

22 Continue… Infobizzs.com
To run a java program, you run a program called a bytecode interpreter, which in turn executes your Java program. Having your Java programs in bytecode form means that instead of being specific to any one system, your programs can be run on any platform and any operating or window system as long as the Java interpreter is available. Only the JVM needs to be implemented for each platform. once the run-time package exists for a given system, any Java program can run on it. Infobizzs.com

23 Continue… Java programs Infobizzs.com

24 Applications of java Infobizzs.com To develop web browser
To enhance capabilities of web browser. To develop web server To enhance capabilities of web server To develop protocols Java encryption/decryption algorithm implementation enables security on the internet. Infobizzs.com

25 Basic structure of java program
suggested optional optional optional optional Essential Infobizzs.com

26 Continue… Infobizzs.com Documentation Section :
The documentation section comprises a set of comment lines. In addition to two styles of comments, java also uses a third style of comment /**…..*/ known as documentation comment. Package Statement : The first statement allowed in a java file is a package statement. This statement declares a package name and informs the computer that the classes defined here belong to this package. The package statement is optional. Ex: package student Infobizzs.com

27 Continue… Infobizzs.com Import Statements:
The next thing after package statement is import statements. This is similar to the #include statement in C. Ex: import student test; This statement instructs the interpreter to load the test class contained in the package student. Using import statements, we can have access to classes that are part of other named packages. Infobizzs.com

28 Continue… Infobizzs.com Interface Statements:
An interface is like a class but includes a group of method declarations. This is also an optional section and is used only when we wish to implement the multiple inheritance feature in the program. Class Definitions: A java program may contain multiple class definitions. Classes are the primary and essential elements of a java program. Infobizzs.com

29 First simple program Infobizzs.com Example.java class Example {
public static void main (String args []) System.out.println ("Hello World."); } Infobizzs.com

30 Compiling the program Infobizzs.com
To compile the Example program, execute the compiler, javac, specifying the name of the source file on the command line, as shown here: C:\>javac Example.java The javac compiler creates a file called Example.class that contains the bytecode version of the program. The Java bytecode is the intermediate representation of your program that contains instructions the Java interpreter will execute. Thus, the output of javac is not code that can be directly executed.  Infobizzs.com

31 Run the program Infobizzs.com
To actually run the program, you must use the Java interpreter, called java. To do so, pass the class name Example as a command-line argument, as shown here: C:\>java Example When the program is run, the following output is displayed: Hello World. Infobizzs.com

32 Continue… Infobizzs.com
When Java source code is compiled, each individual class is put into its own output file named after the class and using the .class extension. When you execute the Java interpreter as just shown, you are actually specifying the name of the class that you want the interpreter to execute. It will automatically search for a file by that name that has the .class extension. If it finds the file, it will execute the code contained in the specified class. Infobizzs.com

33 Description Infobizzs.com class Example
This line uses the keyword class to declare that a new class is being defined. Example is an identifier that is the name of the class.  public static void main (String args [])  This line begins the main ( ) method. This is the line at which the program will begin executing. All Java applications begin execution by calling main ( ). Infobizzs.com

34 Continue… Infobizzs.com
The public keyword is an access specifier, which allows the programmer to control the visibility of class members. In this case, main ( ) must be declared as public, since it must be called by code outside of its class when the program is started.  The keyword static allows main ( ) to be called without having to instantiate a particular instance of the class. This is necessary since main ( ) is called by the Java interpreter before any objects are made. The keyword void simply tells the compiler that main ( ) does not return a value. Infobizzs.com

35 Continue… Infobizzs.com
In main ( ), there is only one parameter, String args [ ], which declares a parameter named args, which is an array of instances of the class String. In this case, args receives any command-line arguments present when the program is executed. System.out.println ("Hello World."); This line outputs the string “hello World.” followed by a new line on the screen. Output is actually accomplished by the built-in println ( ) method.In this case,println( ) displays the string which is passed to it. Infobizzs.com

36 Continue… Infobizzs.com
System is a predefined class that provides access to the system, and out is the output stream that is connected to the console. Infobizzs.com

37 Java input output operators
I/O streams A stream in java is a path along which data flows. It has a source and destination. Input stream reads the data from source and pass the data to program. Output stream writes the data from program to destination. Infobizzs.com

38 Java stream classes Infobizzs.com Java streams Byte Stream
Character Stream I/P Stream O/P Stream Reader Writer File I/P Stream Data I/P Stream Object I/P Stream Buffered I/P Stream File O/P Stream Data O/P Stream Object O/P Stream Buffered O/P Stream Infobizzs.com

39 Continue… Infobizzs.com
The most basic java I/O is writing to and reading from console. Java contains the built-in system, input stream and print stream classes to perform these operations. To read from the keyboard, the statement System.in.read(); It will read a sequence of characters until the end of stream, i.e.the enter key has been detected or an exception has been thrown. To write data to the screen, Sytem.out.println(“hi”); Infobizzs.com

40 Reading a data from keyboard
import java.io.*; public class Echo { public static void main(String args[]) throws IOException InputStreamReader reader; BufferedReader bufReader; reader=new InputStreamReader(System.in); bufReader=new BufferedReader(reader); String s; while(null!=(s=bufReader.readLine())) System.out.println(s); } Output: Hello world Infobizzs.com


Download ppt "Introduction to JAVA Infobizzs.com."

Similar presentations


Ads by Google