INTRODUCTION TO JAVA
Hesam Korki Presents
HISTORY OF JAVA
• 1990 : The idea generated by Patrick Naughton — an engineer of Sun Microsystems
• 1992 : The first official presentation of the language called Oak language
• 1994 : Changing the name to Java Programming Language
• 1995 : Public release of Java1.0a
• 1996 : JDK1 1998 : J2SE 1.2 (aka Java2) 2000 : J2SE 1.3
• 2006 : Java SE6
• 2011 : Java SE7
• 2017 : JDK 9
JAVA APPLICATIONS
• Java Syntax is defined in the Java language specifications
• Java Library is defined in the Java API — Application Program Interface
• JDK is the software for developing and running Java
• IDE is an integrated development environment for developing programs rapidly and readily
• Java SE stands for standard edition for client-side applications
• Java EE stands for enterprise edition for server-side applications
• Java ME stands for micro edition for mobile applications
• JDK is a toolkit which comes with every JSE version — Java Development Toolkit which contains JVM, JRE and APIs
DEFINITIONS
PROCESS CHART
ESSENTIALS• You can easily write a Java program with any text editor and compile it as
long as you have installed JDK on your machine
• You should type the postposition of .java at the end of the text name — e.g A.java
• You can even write a plain text file using command prompt to run java apps — for Unix based systems: vi, and for windows edit
• Then you should type javac A.java to compile your file and get an A.class file, and in the end type java A to execute your program
• THE JAVA FILE NAME SHOULD MATCH THE CLASS NAME
• You’re probably wondering what is a class ? — are you familiar with the constructs in C and C++ ?
• The Java motto is: everything is an object
IN JAVA
WRITING YOUR FIRST PROGRAM
• First, create a file and name it Hello.java, and start text editing it
• Now, what do you think should be the name of the class?
• public class Hello { // now we would define the main method public static void main(String[] args) { System.out.println(“ Hello World ”); } }
• Save and open your command prompt; go to the same directory which your java file is and type: javac Hello.java
• Open the directory and you should be able to detect Hello.class file; then again in terminal type: java Hello
• Remember that java is case sensitive; so, from now on we would always write String not string
• Only can you have one public class in each java file but other classes are acceptable — to be told completely in the object oriented subject
• Now, write another program and name it Calculate then try to find the answer to the equation bellow with it:
• Importing libraries can help us using prewritten classes and methods like include in C
• Error popup message: import javax.swing.*; JOptionPane.showMessageDialog(null, “an error occurred”);
PRIMITIVE TYPES
Write a program that calculates the area of a circle with radius of 10
IN JAVA
READING INPUT FROM THE CONSOLE
• We can use Scanner for reading inputs from the console
• It is in the java.util library; therefore, what should we do?
• Scanner input = new Scanner(System.in);
Write a program that would calculate area and circumference of a circle with arbitrary radius which the user enters