360 likes | 468 Views
introductory lecture on java programming. History of Java. In 1991, “Green Team” of Sun Microsystems leaded by James Gosling developed the Java programming language. First name was Oak (Oak tree) Java is an island of Indonesia where first coffee was produced (called java coffee)
E N D
History of Java • In 1991, “Green Team” of Sun Microsystems leaded by James Gosling developed the Java programming language • First name was Oak (Oak tree) • Java is an island of Indonesia where first coffee was produced (called java coffee) • In 1995, JDK Alpha and Beta versions released • JDK 1.0 released in january 23, 1996
Why JAVA ? • Simple • Object-Oriented • Platform independent • Secured • Strong memory management • Portable • Dynamic • High Performance • Multithreaded • Distributed
Where Java is used? • Desktop Applications • Web Applications • Enterprise Applications • Mobile • Embedded System • Smart Card • Robotics • Games etc.
Version • JDK 8 (18th March, 2014) • Most of the cases, we use JDK 7 in our course
Java Technologies • Core Java • Servlet • JSP • Java Frameworks • Junit • Maven
What is Java ? Why Java become famous? • Java is a programming language and a platform. • Platform indifindent
Java is platform indifindent C/C++ Windows OS
Java is platform indifindent C/C++ C/C++ Linux OS Windows OS
Java is platform indifindent JAVA JAVA Linux OS Windows OS
Java is platform indifindent JAVA JAVA JVM for Linux JVM for windows Linux OS Windows OS
Java is platform indifindent • Java program java compiler bytecode(JVM + Java API) run the program • Java programs run everwhere because java bytecode run on JRE (JVM+API)
Difference between JDK, JRE and JVM JVM • JVM (Java Virtual Machine) is an abstract machine. • Provides runtime environment. The JVM performs following main tasks: • Loads code • Verifies code • Executes code • Provides runtime environment
Difference between JDK, JRE and JVM JRE (Java Runtime Environment) • Provide runtime environment. • It is the implementation of JVM. • It physically exists. • It contains set of libraries + other files that JVM uses at runtime.
Difference between JDK, JRE and JVM JDK (Java Development Kit) • It contains JRE + development tools.
Java Installation • Check Java
How to set path in Java There are 2 ways to set java path: • Temporary • Permanent 1) How to set Temporary Path of JDK in Windows • To set the temporary path of JDK, you need to follow following steps: • write in command prompt: set path=copied_path • For Example: • set path=C:\Program Files\Java\jdk1.6.0_23\bin
How to set path in Java • How to set Permanent Path of JDK in Windows • For setting the permanent path of JDK, you need to follow these steps: • Go to MyComputer properties -> advanced tab -> environment variables -> new tab of user variable -> write path in variable name -> write path of bin folder in variable value -> ok -> ok -> ok
Java Program • class Hello{ • public static void main(String args[]){ • System.out.println("Hello World"); • } • } • Class • public • static • void • Main • String[] args • System.out.println()
Internal Details of Hello Java Program bytecode class Hello{ public static void main(String args[]){ System.out.println("Hello World"); } } Compiler Hello.java Hello.class
Java Program Q)Can you save a java source file by other name than the class name? Ans.) Yes, if the class is not public To compile:javac Hard.java To execute:java Simple
Java Program Q)Can you have multiple classes in a java source file? Ans.)Yes, like the figure given below illustrates:
Source file declaration rules • There can be only one public class per source file. • A source file can have multiple non public classes. • The public class name should be the name of the source file as well which should be appended by .java at the end. For example: the class name is public class Employee{} then the source file should be as Employee.java. • If the class is defined inside a package, then the package statement should be the first statement in the source file. • If import statements are present then they must be written between the package statement and the class declaration. If there are no package statements then the import statement should be the first line in the source file. • Import and package statements will imply to all the classes present in the source file. It is not possible to declare different import and/or package statements to different classes in the source file.
Q. What is the meaning of the words public, static and void? Q. Can a program use more than one command-line argument? A. Yes, you can put several, though we normally use only a few. You refer to the second one as args[1], the third one as args[2], and so forth. Note that we start counting from 0 in Java. Q. What exactly is a .class file? A. It's a binary file (sequence of 0s and 1s). Q. What is the wrong ? public class Hello { public static void main() { System.out.println("Doesn't execute"); } } A. forgot the String[] args. It is required.
Java Programs 1) Write a program Java Progam that prints "Hello, World" ten times. 2) ******************** *************** ********** ***** * 3) 1 2 3 4 5