Presentation is loading. Please wait.

Presentation is loading. Please wait.

 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.

Similar presentations


Presentation on theme: " JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data."— Presentation transcript:

1  JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data types in Java  Constants and Variables

2 Text Editor / IDE CompilerInterpreter Programmer Source Code.java file Byte Code.class file Hardware and Operating System Notepad, emacs,vi, Netbeans, Eclipse etc., javac java appletviewer

3 JAVA COMPILER JAVA BYTE CODE JAVA INTERPRETER WindowsMacintoshSolarisWindows NT (translator) (same for all platforms) (one for each different system)

4 Java Compiler - Java source code (file with extension.java) to bytecode (file with extension.class) Bytecode - an intermediate form, closer to machine representation A interpreter (virtual machine) on any target platform interprets the bytecode.

5 //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.printf(“%s”, “Welcome to Java!”); } //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.printf(“%s”, “Welcome to Java!”); } Welcome.java

6 //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.printf(“%s”, “Welcome to Java!"); } //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.printf(“%s”, “Welcome to Java!"); }  First line indicates comment. Which is not compiled by the JAVA  Public Specifies that the method is accessible from anywhere  Class is keyword and Welcome is a java identifier that specifies the name of the class to be defined.  Static is keyword, the main must always be declared as static since the interpreter uses this method before any objects are created.  Void is an modifier that states the main method does not return any value.  This is similar to the printf() statement of C.

7

8 System.out.printf  Feature added in Java SE 5.0  Displays formatted data  Format string  Fixed text  Format specifier – placeholder for a value  Format specifier %s – placeholder for a string System.out.printf( "%s\n%s\n", "Welcome to", "Java Programming!" );

9  Although complex data values are represented using objects, Java defines a set of primitive types to represent simple data. Java provides eight primitive data types, they are  boolean  char, byte, short, int, long  float, double Primitive Data TypesSize in BytesSize in Bits int432 long864 float432 double864 char216 boolean (boolean in Java)18

10 A data type is defined by a set of values called the domain and a set of operations. The following table shows the data domains and common operations for all eight of Java’s primitive types: Type short int long float double char boolean 8-bit integers in the range –128 to 127 16-bit integers in the range –32768 to 32767 32-bit integers in the range –2146483648 to 2146483647 64-bit integers in the range –9223372036754775808 to 9223372036754775807 32-bit floating-point numbers in the range ± 1.4 x 10 -45 to ± 3.4028235 x 10 -38 64-bit floating-point numbers in the range ± 4.39 x 10 -322 to ± 1.7976931348623157 x 10 308 16-bit characters encoded using Unicode the values true and false The arithmetic operators: + - * / % add subtract remainder divide multiply = == = < != <= >= equal to less than greater or equal less or equal not equal > greater than The arithmetic operators except % The relational operators: The relational operators The logical operators: && add || or ! not DomainCommon operations byte

11  The simplest terms that appear in expressions are constants and variables. The value of a constant does not change during the course of a program. A variable is a name for memory location, in which value can be stored this value may be changed at the time of execution.  Each variable has the following attributes:  A name, which enables you to differentiate one variable from another.  A type, which specifies what type of value the variable can contain.  A value, which represents the current contents of the variable.  A variable in Java is most easily envisioned as a box capable of storing a value. total 42

12  In Java, you must declare a variable before you can use it. The declaration establishes the name and type of the variable and, in most cases, specifies the initial value as well. type name = value ;  The most common form of a variable declaration is where type is the name of a Java primitive type or class, name is an identifier that indicates the name of the variable, and value is an expression specifying the initial value. RULES: 1. First character should be an alphabet and remaining characters can be alpha-numeric. 2. Keywords cannot be used for defining. 3. No special symbols are allowed expect underscore and dollar. 4. Java is case sensitive, “Num” and “NUM” are different.

13


Download ppt " JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data."

Similar presentations


Ads by Google