CSI 3125, Preliminaries, page 1 Compiling the Program.

Slides:



Advertisements
Similar presentations
2.4 Creating and Using Objects. Writing the code for classes of your own will come later. At this time it is possible to understand and correctly write.
Advertisements

Object Oriented Programming in JAVA
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Introduction to Java Programming
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes Part 1.
1 Chapter 2 Introductory Programs. 2 Getting started To create and run a Java program –Create a text file with a.java extension for the source code. For.
What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you.
Slide 1 of 40. Lecture A The Java Programming Language Invented 1995 by James Gosling at Sun Microsystems. Based on previous languages: C, C++, Objective-C,
Chapter 2: Java Fundamentals Java Program Structure.
Hello, world! Dissect HelloWorld.java Compile it Run it.
Introduction to Java.
Unit 2: Java Introduction to Programming 2.1 Initial Example.
“Introduction to Programming With Java”
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
(C) 2010 Pearson Education, Inc. All rights reserved.  Java programs normally go through five phases  edit  compile  load  verify  execute.
 Java Programming Environment  Creating Simple Java Application  Lexical Issues  Java Class Library.
CSC Programming I Lecture 8 September 9, 2002.
Welcome to the Lecture Series on “Introduction to Programming With Java”
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
© 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 means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Methods F Hello World! F Java program compilation F Introducing Methods F Declaring Methods F Calling Methods F Passing Parameters by value F Overloading.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
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().
EE2E1. JAVA Programming Lecture 3 Java Programs and Packages.
The 1 st and 2 nd tutoring session of CSc2310 Fall, 2012 Haidong Xue.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 2 – Classes and objects.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
Identifiers Identifiers in Java are composed of a series of letters and digits where the first character must be a letter. –Identifiers should help to.
Everything is an object (CH-2) Manipulating Objects with References. Manipulating Objects with References. String s; String s = “IS2550” String s = new.
Methods. Methods also known as functions or procedures. Methods are a way of capturing a sequence of computational steps into a reusable unit. Methods.
Classes and Methods. Classes Class Definition Data Fields –Variables to store data items –Differentiate multiple objects of a class –They are called.
CSI 3125, Preliminaries, page 1 Class. CSI 3125, Preliminaries, page 2 Class The most important thing to understand about a class is that it defines a.
Lecture 08. Since all Java program activity occurs within a class, we have been using classes since the start of this lecture series. A class is a template.
CSI 3125, Preliminaries, page 1 Overloading Methods In Java it is possible to define two or more methods within the same class that share the same name,
By Mr. Muhammad Pervez Akhtar
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
Programming in java Packages Access Protection Importing packages Java program structure Interfaces Why interface Defining interface Accessing impln thru.
CSI 3125, Preliminaries, page 1 Packages. CSI 3125, Preliminaries, page 2 Packages Packages are containers for classes Collection of classes Packages.
Lecture1 Instructor: Amal Hussain ALshardy. Introduce students to the basics of writing software programs including variables, types, arrays, control.
CSI 3125, Preliminaries, page 1 Inheritance. CSI 3125, Preliminaries, page 2 Inheritance Using inheritance, can create a general class that defines traits.
Classes - Intermediate
Methods.
Topics Instance variables, set and get methods Encapsulation
Lecture 6: Methods MIT-AITI Kenya © 2005 MIT-Africa Internet Technology Initiative In this lecture, you will learn… What a method is Why we use.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Introduction to java (class and object). Programming languages: –Easier to understand than CPU instructions –Needs to be translated for the CPU to understand.
Java Methods and Applications CSIS 3701: Advanced Object Oriented Programming.
The need for Programming Languages
3 Introduction to Classes and Objects.
Arrays 3/4 By Pius Nyaanga.
CompSci 230 Software Construction
An Introduction to Java – Part I, language basics
Java Intro.
JAVA Constructors.
Chapter 2: Java Fundamentals
Classes, Objects and Methods
Arrays 3/4 June 3, 2019 ICS102: The course.
Chapter 6 Arrays.
Introduction to java Part I By Shenglan Zhang.
Presentation transcript:

CSI 3125, Preliminaries, page 1 Compiling the Program

CSI 3125, Preliminaries, page 2 Compiling the Program To compile a java program, execute the compiler, javac, specifying the name of the source file on the command line Eg If the file name is POPO.JAVA C:\>javac popo.java The javac compiler creates a file called popo.class that contains the bytecode version of the program. The Java bytecode is the intermediate representation of the program that contains instructions the Java interpreter will execute. Thus, the output of javac is not code that can be directly executed. To actually run the program, must use the Java interpreter, called java. To do so, pass the class name POPO as a command-line argument, as shown here: C:\>java POPO

CSI 3125, Preliminaries, page 3 Compiling the Program When Java source code is compiled, each individual class is put into its own output file named after the class and using the.class extension. This is why it is a good idea to give your Java source files the same name as the class they contain—the name of the source file will match the name of the.class file. When you execute the Java interpreter as just shown, you are actually specifying the name of the class that you want the interpreter to execute. It will automatically search for a file by that name that has the.class extension. If it finds the file, it will execute the code contained in the specified class.

CSI 3125, Preliminaries, page 4 Compiling the Program Eg Prog class popo { public static void main(String args[]) { System.out.println("Hello popo"); }

CSI 3125, Preliminaries, page 5 Compiling the Program public static void main(String args[]) { This line begins the main( ) method. This is the line at which the program will begin executing. 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. In this case, main( ) must be declared as public, since it must be called by code outside of its class when the program is started.

CSI 3125, Preliminaries, page 6 Compiling the Program 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. As stated, main( ) is the method called when a Java application begins. Java is case-sensitive.

CSI 3125, Preliminaries, page 7 Compiling the Program Any information that need to pass to a method is received by variables specified within the set of parentheses that follow the name of the method. These variables are called parameters. If there are no parameters required for a given method, still need to include the empty parentheses. In main( ), there is only one parameter, String args[ ] declares a parameter named args, which is an array of instances of the class String. In this case, args receives any command-line arguments present when the program is executed.

CSI 3125, Preliminaries, page 8 Compiling the Program Eg Prog class popo { public static void main(String args[]) { System.out.println("Hello popo"); }

CSI 3125, Preliminaries, page 9 Compiling the Program