Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee
Introduction to JAVA High Level Programming Language (HLL) Java, released in 1995, is a relatively new programming language. Developed by James Gosling from Sun Microsystems and his team
Creating a Java Program javac.java java.class
Java Program: a set of instructions for the computer to follow. The source code. Saved as filename.java Data: data for the Java program Java Compiler (javac): translates the program from Java to a language that the computer can understand. Byte Code Program: the compiler translates Java into a language called byte-code. Byte code is the machine language for Java Virtual Machine (JVM). filename.class Byte Code Interpreter (java): the interpreter (JVM) translates byte code into machine language (.exe) Machine Language: is the la nguage the computer understands.
Parts of a Java Program import java.io.*; public class Hello { public static void main (String[ ] args) { System.out.println(“Hello."); System.out.print(“Welcome to Java Programming!"); } } This is same as header file in C. This package is used for input and output.
Parts of a Java Program import java.io.*; public class Hello { public static void main (String[ ] args) { System.out.println(“Hello."); System.out.print(“Welcome to Java Programming!"); } } Every Java program is a class. The program starts with the name of the class. The class name must be the same as the. java file you save.
Parts of a Java Program import java.io.*; public class Hello { public static void main (String[ ] args) { System.out.println(“Hello."); System.out.print(“Welcome to Java Programming!"); } } A main method is needed for execution to start. This main method gets executed first. The array of strings parameter is must.
Parts of a Java Program import java.io.*; public class Hello { public static void main (String[ ] args) { System.out.println(“Hello."); System.out.print(“Welcome to Java Programming!"); } } Output statements: the basic output statement in Java is the System.out.println( ) or System.out.print( )
Variables Most Often Used Data Type Keyword Kind of Value Bytes of Memory Range of Values Character char 1 character2 not applicable Bytebyteinteger to127 Short integer short Integers 2 -32,768 to 32,767 (-2 15 to ) Integer int Integers4 -2,147,483,648 to 2,147,483,647 (-2 31 to ) Long Integer long Integers to (-2 63 to ) Floatfloat Decimal values to 7 decimal digit precision 4 3.4e-38 to 3.4e38 positive and negative DoubledoubleDecimal values to 15 decimal digit precision 8 1.7e-308 to 1.73e308 positive and negative Boolean bool Boolean (Logical) values True or False 1not applicable
Constant Variables Constant is a variable whose value does not change in the program. Eg: PI = 3.14 The keyword ‘final’ is used to define constant in Java Eg. final int count = 100; final double PI=3.14;