java means coffee java coffee beans the name “java” was taken from a cup of coffee

Post on 13-Jan-2016

217 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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 language 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 UsedData Type Keyword Kind of Value Bytes of Memory Range of Values

Character char 1 character 2 not applicable

Byte byte integer 1 -128 to127

Short integer short Integers 2-32,768 to 32,767

(-215 to 215 - 1)

Integer int Integers 4 -2,147,483,648 to 2,147,483,647(-231 to 231 - 1)

Long Integer long Integers 8-9223372036854775808 to

9223372036854775807(-263 to 263 - 1)

Float float Decimal values to 7 decimal digit precision 43.4e-38 to 3.4e38

positive and negative

Double double Decimal values to 15 decimal digit precision 8

1.7e-308 to 1.73e308 positive and negative

Boolean bool Boolean (Logical) valuesTrue or False 1 not 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 JavaEg.

final int count = 100;final double PI=3.14;

top related