Java IVAN MAURITS What is Java Java is

  • Slides: 30
Download presentation
Java IVAN MAURITS

Java IVAN MAURITS

What is Java? Java is an object-oriented programming language developed by Sun Microsystems and

What is Java? Java is an object-oriented programming language developed by Sun Microsystems and released in 1995. Java was originally developed by James Gosling at Sun Microsystems (which has since merge into Oracle Corporation). Java programs are platform independent which means they can be run on any operating system with any type of processor as long as the Java interpreter is available on that system. Java code that runs on one platform does not need to be recompiled to run on another platform, it’s called write once, run anywhere(WORA). Java Virtual Machine (JVM) executes Java code, but is written in platform specific languages such as C/C++/ASM etc. JVM is not written in Java and hence cannot be platform independent and Java interpreter is actually a part of JVM.

Where is Java being Used? Earlier java was only used to design and program

Where is Java being Used? Earlier java was only used to design and program small computing devices but later adopted as one of the platform independent programming language and now according to Sun, 3 billion devices run java. JSP – Java is used to create web applications like PHP and ASP, JSP(Java Server Pages) used with normal HTML tags, which helps to create dynamic web pages. Applets – This is another type of Java program that used within a web page to add many new features to a web browser. J 2 EE – The software Java 2 Enterprise Edition are used by various companies to transfer data based on XML structured documents between one another. Java. Beans – This is something like Visual Basic, a reusable software component that can be easily assemble to create some new and advanced application. Mobile – Besides the above technology, Java is also used in mobile devices, many kind of games and services built-in Java. Today, all leading mobile service provider like Nokia, Siemens, Vodafone are using Java technology.

Types of Java Applications Web Application – Java is used to create server-side web

Types of Java Applications Web Application – Java is used to create server-side web applications. Currently, servlet, jsp, struts, jsf etc. technologies are used. Standalone Application – It is also known as desktop application or window-based application. An application that we need to install on every machine or server such as media player, antivirus etc. AWT and Swing are used in java for creating standalone applications. Enterprise Application – An application that is distributed in nature, such as banking applications etc. It has the advantage of high level security, load balancing and clustering. In java, EJB is used for creating enterprise applications. Mobile Application – Java is used to create application softwares for mobile devices. Currently Java ME is used for creating applications for small devices, and also Java is programming language for Google Android application development.

Facts about Java Object Oriented – In java everything is an Object. Java can

Facts about Java Object Oriented – In java everything is an Object. Java can be easily expanded since it is based on the Object model. Platform independent – C and C++ are platform dependency languages hence the application programs written in one Operating system cannot run in any other Operating system, but in platform independence language like Java application programs written in one Operating system can able to run on any Operating system. Simple – Java is designed to be easy to learn. If you understand the basic concept of OOP java would be easy to master. Secure – With Java’s secure feature it enables to develop virus-free, tamper-free systems. Authentication techniques are based on public-key encryption. Architectural-neutral – Java compiler generates an architecture-neutral object file format which makes the compiled code to be executable on many processors, with the presence Java runtime system.

 Portable – being architectural neutral and having no implementation dependent aspects of the

Portable – being architectural neutral and having no implementation dependent aspects of the specification makes Java portable. Compiler and Java is written in ANSI C with a clean portability boundary which is a POSIX subset. Robust – Java makes an effort to eliminate error prone situations by emphasizing mainly on compile time error checking and runtime checking. Multi-threaded – With Java’s multi-threaded feature it is possible to write programs that can do many tasks simultaneously. This design feature allows developers to construct smoothly running interactive applications. Interpreted – Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development process is more rapid analytical since the linking is an incremental and light weight process.

 High Performance – With the use of Just-In-Time compilers Java enables high performance.

High Performance – With the use of Just-In-Time compilers Java enables high performance. Distributed – Java is designed for the distributed environment of the internet. Dynamic – Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment. Java programs can carry an extensive amount of run-time information that can be used to verify and resolve accesses to objects on run-time.

Different Editions of Java Technology Java SE – Java SE or Java Standard Edition

Different Editions of Java Technology Java SE – Java SE or Java Standard Edition provides tools and API’s that you can use to create server applications, desktop applications, and even applets. These programs developed using Java SE can be run on almost every popular operating system, including Linux, Macintosh, Solaris, and Windows. JEE – Based on the foundation framework of the standard edition, Java Enterprise Edition helps in web application service, component model and enterprise class service oriented architecture (SOA). JME – Java Micro Edition or JME for short is an accumulation of Java APIs that are used for the development of software for devices like mobile phones, PDAs, TV set-top boxes, game programming. The platform of micro edition generally consists of an easy user interface, a robust security model and a wide variety of built-in networks for running Java based application.

What you will need to run Java You will need the Java software development

What you will need to run Java You will need the Java software development kit from http: //java. sun. com/ Follow the instructions on Sun’s website to install it. Make sure that you add the java bin directory to your PATH environment variable.

Windows 10 and Windows 8 1. In Search, search for and then select: System

Windows 10 and Windows 8 1. In Search, search for and then select: System (Control Panel) 2. Click the Advanced system settings link. 3. Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New. 4. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK. 5. Reopen Command prompt window, and run your java code.

Windows 7 1. From the desktop, right click the Computer icon. 2. Choose Properties

Windows 7 1. From the desktop, right click the Computer icon. 2. Choose Properties from the context menu. 3. Click the Advanced system settings link. 4. Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New. 5. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK. 6. Reopen Command prompt window, and run your java code.

Mac OS X To run a different version of Java, either specify the full

Mac OS X To run a different version of Java, either specify the full path, or use the java_home tool: % /usr/libexec/java_home -v 1. 8. 0_73 --exec javac -version

Popular Java Editors Notepad – On Windows machine you can use any simple text

Popular Java Editors Notepad – On Windows machine you can use any simple text editor like Notepad (Recommended for this tutorial), Text. Pad. Netbeans – is a Java IDE that is open source and free which can be downloaded from http: //www. netbeans. org/index. html Eclipse – is also a java IDE developed by the eclipse open source community and can be downloaded from http: //www. eclipse. org/

History of Java Technology James Gosling, Patrick Naughton, Chris Warth, Mike Sheridan and Ed

History of Java Technology James Gosling, Patrick Naughton, Chris Warth, Mike Sheridan and Ed Frank initiated the Java language project in June 1991. The idea was to develop a language which was platform-independent and which could create embedded softwares for consumer electronic devices. The language took 18 months to develop and had an initial name as Oak which was renamed to Java in 1995, due to copyright issues. Originally developed by James Gosling at Sun Microsystems(which has since merge into Oracle Corporation) and released in 1995. JDK 1. 0 released in(January 23, 1996). Java SE 8. 0 is a current stable release of Java, and many other previous Java versions are also available.

Basic Structure of Java Program Documentation Section Package Statement Import Statements Interface Statement Class

Basic Structure of Java Program Documentation Section Package Statement Import Statements Interface Statement Class Definition Main Method Class Main Method Defintion

Documentation Section It comprises of a comment line which gives the names program, the

Documentation Section It comprises of a comment line which gives the names program, the programmer’s name and some other brief details. In addition to the 2 other styles of comments i. e. /**/ and //, Java also provides another style of comment i. e. /**…. */ Package statement The first statement allowed in Java file is the Package statement which is used to declare a package name and it informs the compiler that the classes defined within the program belong to this package. It is declared as: package_name; Import statements The next is the number of import statements, which is equivalent to #include statement in C++. Example: import calc. add; Interface statement Interfaces are like class that includes a group of method declarations. This is an optional section and can be used only when programmers want to implement multiple inheritance(s) within a program. Class Definition A Java program may contain multiple class definitions. Classes are the main and important elements of any Java program. These classes are used to plot the objects of real world problem. Main Method Class Since every Java stand alone program requires a main method as the starting point of the program. This class is essentially a part of Java program. A simple Java program contains only this part of the program.

Sample Code of Java “Hello Java” Program public class Hello { /* Author: www.

Sample Code of Java “Hello Java” Program public class Hello { /* Author: www. w 3 schools. in Date: 2017 -08 -11 Description: Writes the words "Hello Java" on the screen */ public static void main(String[] args) { System. out. println("Hello Java"); } }

public class Hello • This creates a class called Hello. • All class names

public class Hello • This creates a class called Hello. • All class names required to start with a capital letter. • The word public means that it is accessible by any other classes. /* Comments */ Comments are a way of explaining what makes a program. Comments are ignored by the compiler and used by others to understand the code. or This is a comment block, which is ignored by the compiler. Comment is used anywhere in program to add info about program or code block, which can be helpful for programmer to understand the code easily in feature. Braces Two curly brackets {…} are used to group all the commands together so it is known that the commands belong to that class or method. public static void main • The word public means that it is accessible by any other classes. • The word static means that it is unique. • The word void means this main method has no return value. • main is a method where the program starts. You will notice that the main method code has been moved to some spaces left. This is called indentation which used to make a program easier to read and understand.

System. out. println(); • System is a final class name and cannot be instantiated.

System. out. println(); • System is a final class name and cannot be instantiated. Therefore all its members (fields and methods) will be static, and we understand that it is an utility class. As per javadoc, “…Among the facilities provided by the System class are standard input, standard output, and error output streams; access to externally defined properties and environment variables; a means of loading files and libraries; and a utility method for quickly copying a portion of an array…” • out is static member in System class which is instance of java. io. Print. Stream. Its access specifiers are public final. This gets instantiated during startup and gets mapped with standard output console of the host. This stream is open by itself immediately after its instantiation and ready to accept data. When running a program from windows command line, it is the standard console. • println method prints text on the screen with newline. There are multiple println methods with different arguments (overloading). Every println makes a call to print method and adds a newline. print calls write() and the story goes on like that. • The data that is to be printed is put inside brackets. You will also notice that the words in inverted commas because they are what is called a string. Each letter is a character and a series of characters grouped together is called a string. Strings always be put between inverted commas. You must have to put a semicolon after every command to show that it is the end of the command.

Java Virtual Machine (JVM) When we talk about the Java applications, then it works

Java Virtual Machine (JVM) When we talk about the Java applications, then it works only on those machines which have JVM stands for Java Virtual Machine. JVM is the engine that drives the java code. Mostly in other Programming Languages, compiler produce code for a particular system but Java compiler produce Bytecode for a Java Virtual Machine. Bytecode is an intermediary language between Java source and the host system. It is the medium which compile Java code to bytecode which get interpret on different machine and hence it makes it Platform/Operating system independent.

JVM generates a. class(Bytecode) file, and that file can be run in any OS,

JVM generates a. class(Bytecode) file, and that file can be run in any OS, but JVM should have in OS, because JVM is platform dependent.

Platform Independent Java is called platform independent because of Java Virtual Machine. As different

Platform Independent Java is called platform independent because of Java Virtual Machine. As different computers with different operating system have their own JVM, when we submit. class file to any operating system, JVM interpret the bytecode into machine level language. JVM is the main component of Java architecture and it is the part of the JRE (Java Runtime Environment). A program of JVM is written into “C Programming Language” and JVM is Operating System dependent. JVM is responsible to allocate the necessary memory needed by the Java program. JVM is responsible to deallocate memory space.

Java SE Development Kit (JDK) JDK (Java SE Development Kit) Includes a complete JRE

Java SE Development Kit (JDK) JDK (Java SE Development Kit) Includes a complete JRE (Java Runtime Environment) plus tools for developing, debugging, and monitoring Java applications. JDK is required to develop and run Java applications and applets. JDK tools is divided into five categories: Basic Tools Remote Method Invocation (RMI) Tools Internationalization Tools Security Tools Java IDL Tools

Basic JDK Tools These tools are the foundation of the Java Development Kit. Javac

Basic JDK Tools These tools are the foundation of the Java Development Kit. Javac javac is the compiler for the Java programming language, it’s used to compile. java file. It creates a class file which can be run by using java command. c: javac Test. File. java Java c: java Test. File. class

 Javadoc : Java. Doc is a API documentation generator for the Java language,

Javadoc : Java. Doc is a API documentation generator for the Java language, which generates documentation in HTML format from Java source code. Appletviewer : appletviewer run and debug applets without a web browser, its standalone command-line program to run Java applets. Jar : jar is (manage Java archive) a package file format that contains class, text, images and sound files for a Java application or applet gathered into a single compressed file.

Java Runtime Environment (JRE) JRE is a set of software tools for the development

Java Runtime Environment (JRE) JRE is a set of software tools for the development of Java applications. JRE consists of various components, these are listed below: Java Web Start and Java Plug-in. User Interface Toolkit, which includes Abstract Window Toolkit (AWT), Swing, Image Input / Output, Accessibility, drag and drop etc. Other different base libraries, including Input/Output, extension mechanisms, beans, JMX, JNI, networking, override mechanisms etc. Lang and util base libraries which includes lang and util, management, versioning, collections etc. Integration libraries, which includes Interface Definition Language (IDL), Java Database Connectivity (JDBC), Java Naming and Directory Interface (JNDI), Remote Method Invocation (RMI).

Java Installation Java SE(Standard Edition) is freely available on Oracle’s website, and it can

Java Installation Java SE(Standard Edition) is freely available on Oracle’s website, and it can be installed like any other software. Check whether java is installed or no In the command prompt enter command javac. If you see a screen like below, it means Java is Installed.

How to compile a java file using javac command. c: jdkappdemo> javac Testfile. java

How to compile a java file using javac command. c: jdkappdemo> javac Testfile. java Output Testfile. java compile successfully.