 Java Programming Environment  Creating Simple Java Application  Lexical Issues  Java Class Library.

Slides:



Advertisements
Similar presentations
1 pritisajja.info Unlocking the World of Java Programming….. Priti Srinivas Sajja February, 2014 Visit pritisajja.info for detail Future Technology for.
Advertisements

CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Chapter 1 Introduction to JAVA. Why Learn JAVA? Java is one of the fastest growing programming language in the world. Java is one of the fastest growing.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Object Oriented Programming in JAVA
Chapter 1: Introduction
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
Object Orientated Programming
1 Fall 2008ACS-1903 Chapter 1 Topics Java History Java Programs Why Program? Computer Systems: Hardware and Software Programming Languages What Is a Program.
Outline Java program structure Basic program elements
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Guide To UNIX Using Linux Third Edition
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Getting Started with Java
Java PAL.  Contains the development kit and the runtime environment ( aka the Java Virtual Machine )  Download Link:
Unit 2: Java Introduction to Programming 2.1 Initial Example.
Introducing Java.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Chapter 2 How to Compile and Execute a Simple Program.
Chapter 1: Creating Java Programs
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
Chapter 1 CSIS-120: Java Intro. What is Programming?  A: It is what makes computer so useful.  The flexibility of a computer is amazing  Write a term.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
JAVA BASICS: Variables and References SYNTAX, ERRORS, AND DEBUGGING.
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
POS 406 Java Technology And Beginning Java Code
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
A First Simple Program /* This is a simple Java program. Call this file "Example.java".*/ class Example { // Your program begins with a call to main().
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
CSI 3125, Preliminaries, page 1 Compiling the Program.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Creating a Java Application and Applet
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
Introducing Java Chapter 3 Review. Why Program in Java? Java, is an object-oriented programming language. OOP languages evolved out of the need to better.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
OCR A Level F453: The function and purpose of translators Translators a. describe the need for, and use of, translators to convert source code.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
What is an object?. What Makes an Object? An object has identity (it acts as a single whole). Every object has a name that identifies what it is. Ex.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Introduction to Algorithm. What is Algorithm? an algorithm is any well-defined computational procedure that takes some value, or set of values, as input.
Lecture 1b- Introduction
GC101 Introduction to computer and program
Chapter 3 GC 101 Java Fundamentals.
Console Output, Variables, Literals, and Introduction to Type
Text by: Lambert and Osborne
C# and the .NET Framework
Data types and variables
Java programming lecture one
(Computer fundamental Lab)
Chap 1. Getting Started Objectives
Computer Programming-1 CSC 111
Presentation transcript:

 Java Programming Environment  Creating Simple Java Application  Lexical Issues  Java Class Library

Java Bytecodes move locally or through network Java Source (.java) Java Compiler Java Bytecode (.class ) Java Interpreter Just in Time Compiler Runtime System Class Loader Bytecode Verifier Java Class Libraries Operating System Hardware Java Virtual machine Runtime Environment Compile-time Environment Java Environment/ Life Cycle of Java Code

Java programs are translated into an intermediate language called bytecode. Bytecode is the same no matter which computer platform it is run on. Bytecode is translated into native code that the computer can execute on a program called the Java Virtual Machine (JVM). The Bytecode can be executed on any computer that has the JVM. Hence Java’s slogan, “Write once, run anywhere”.

 The procedure followed to obtain and install a class goes as follows:  Loading includes the following tasks: ◦ locate the bytecode file in a disk file ◦ read it into the JVM's method area on the heap. ◦ parse the class data into sections for constants, methods, fields, etc.. ◦ create an instance of java.lang.Class to represent the class.  Linking proceeds through these 3 steps ◦ verification - check that the basic structure and form of the class is proper. Run bytecode verification. ◦ preparation - allocate memory for the class data such as static variables. ◦ resolution - convert the symbolic references in the class file, such as variable names, to direct references.  Initialization The static variables and constants must be set to either default or user assigned values.  ByteCode Verifier is called when class is first loaded in runtime environment. As part of the class loading process, a thorough verification of the bytecodes takes place to insure that the file holds a valid Java class and does not break any of the rules for class behavior.

 In the Java programming language and environment, a just-in-time (JIT) compiler is a program that turns Java bytecode (a program that contains instructions that must be interpreted) into instructions that can be sent directly to the processor.  After you've written a Java program, the source language statements are compiled by the Java compiler into bytecode rather than into code that contains instructions that match a particular hardware platform's processor. The bytecode is platform- independent code that can be sent to any platform and run on that platform.  In the past, most programs written in any language have had to be recompiled, and sometimes, rewritten for each computer platform. One of the biggest advantages of Java is that you only have to write and compile a program once.  The Java on any platform will interpret the compiled bytecode into instructions understandable by the particular processor. However, the virtual machine handles one bytecode instruction at a time. Using the Java just-in-time compiler (really a second compiler) at the particular system platform compiles the bytecode into the particular system code (as though the program had been compiled initially on that platform). Once the code has been (re-)compiled by the JIT compiler, it will usually run more quickly in the computer.  The just-in-time compiler comes with the virtual machine and is used optionally. It compiles the bytecode into platform-specific executable code that is immediately executed.

 List down Java Compile –time and Run-time errors.

 Java applications are stand-alone programs ◦ must be compiled into Java byte code by Java compiler, then distributed ◦ executed by an interpreter (Java Virtual Machine)  Java applets provide for client-side programming  Java servlets provide similar capabilities on the server-side

To begin developing Java programs, follow these steps:  Step 1: Obtain the Software Development Kit (SDK) for J2SE (Java 2 Platform, Standard Edition)  Step 2: Install the SDK

 Step 1: Use an editor to enter the following code for the HelloWoldApp program:  Save this code in a file called HelloWorldApp.java

 Step 2: Compile the application with the command line: > javac HelloWorldApp.java  This creates the class file (with the bytecode output): HelloWorldApp.class

 Step 3: Use the java command to run the program: > java HelloWorldApp Hello World!  The output is printed after the command line. Output

 The keyword class is used to declare that a new class is being defined.  HelloWorldApp is an identifier that is the name of the class.  The entire class definition, including all of its members, will be between the opening curly brace ({) and the closing curly brace (}).  The use of the curly braces in Java is identical to the way they are used in C, C++.  In Java, all program activity occurs within class. This is one reason why all Java programs are object- oriented.

 The next line of code is  All Java applications begin execution by calling main( ).  The public keyword is an access specifier, which allows the programmer to control the visibility of class members. When a class member is preceded by public, then that member may be accessed by code outside the class in which it is declared.  main( ) must be declared as public, since it must be called by code outside of its class when the program is started.

 The keyword static allows main( ) to be called without having to instantiate a particular instance of the class. This is necessary since main( ) is called by the Java interpreter before any objects are made.  The keyword void simply tells the compiler that main( ) does not return a value.

 main( ) is the method called when a Java application begins. Java is case-sensitive. Thus, Main is different from main.  It is important to understand that the Java compiler will compile classes that do not contain a main( ) method. But the Java interpreter has no way to run these classes. So, if you had typed Main instead of main, the compiler would still compile your program. However, the Java interpreter would report an error because it would be unable to find the main( ) method.

 String arg[ ] declares a parameter named arg, which is an array of instances of the class String. Objects of type String store character strings.  In this case, arg receives any command-line arguments present when the program is executed. This program does not make use of String arg[ ].  main( ) is simply a starting place for your program.  A complex program will have dozens of classes, only one of which will need to have a main( ) method to get things started.

 The next line of code is shown here  This line outputs string Hello World!  System is a predefined class that provides access to the system, and out is the output stream that is connected to the console.  Output is actually accomplished by the built-in println( ) method. println( ) displays the string which is passed to it.

Differences from C – In Java String is a real type – Java arrays have an associated length – The file name is not part of the command line arguments File ShowArgs.java: class ShowArgs { public static void main(String abc[]) { for(int i=0; i<abc.length; i++) { System.out.println("Argument " + i + " = " + abc[i]); }

Compiling and Running: > javac ShowArgs.java > java ShowArgs 1 2  Output Argument 0=1 Argument 1=2

Whitespace  Java is a free-form language.  For example, the program could have been written all on one line or in any other strange way you felt like typing it.  In Java, whitespace is a space, tab, or newline.

Identifiers  Identifiers are used for class names, method names, and variable names.  An identifier may be any descriptive sequence of uppercase and lowercase letters, numbers, or the underscore and dollar-sign characters.  They must not begin with a number.  Java is case-sensitive, so VALUE is a different identifier than Value.  Some examples of valid identifiers are: AvgTemp count a4 $test this_is_ok  Invalid variable names include: 2count high-temp Not/ok

Literals  A constant value in Java is created by using a literal representation of it.  For example,here are some literals: ‘X’ “This is a test”  Left to right, the first literal specifies an integer, the next is a floating-point value, the third is a character constant, and the last is a string.  A literal can be used anywhere a value of its type is allowed.

Comments  There are three types of comments defined by Java. You already know two: single-line and multiline. The third type is called a documentation comment.  This type of comment is used to produce an HTML file that documents your program.  The documentation comment begins with a /** and ends with a */.

Separators  In Java, there are a few characters that are used as separators.  The most commonly used separator in Java is the semicolon.

The Java Keywords  There are 49 reserved keywords currently defined in the Java language  The keywords const and goto are reserved but not used.

 the Java environment relies on several built-in class libraries that contain many built-in methods that provide support for such things as I/O, string handling, networking, and graphics.  The standard classes also provide support for windowed output.  Thus, Java as a totality is a combination of the Java language itself, plus its standard classes.

QUIZ!!!!!

1. What will be result of running the following program? 2. Explain this statement ”Java is platform independent language”.

1. What will be result of running the following program? 2. Why is it necessary to save file with the same name as the class holding main( ) method?

Questions? 34