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().

Slides:



Advertisements
Similar presentations
CSCI 160 Midterm Review Rasanjalee DM.
Advertisements

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 2 Getting Started with Java Program development.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Object Oriented Programming in JAVA
Chapter 1: Introduction
Numeric literals and named constants. Numeric literals Numeric literal: Example: A numeric literal is a constant value that appears in a Java program.
CMT Programming Software Applications
Getting Started with Java
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
Outline Java program structure Basic program elements
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Where are we? Programming in Java consists of creating source code in an editor. Source code is compiled to bytecode by the Java compiler – javac The bytecode.
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 Classes and Methods I Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
Introduction to C++ - How C++ Evolved Most popular languages currently: COBOL, Fortran, C, C++, Java (script) C was developed in 1970s at AT&T (Richie)
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
 Java Programming Environment  Creating Simple Java Application  Lexical Issues  Java Class Library.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Computing with C# and the.NET Framework Chapter 1 An Introduction to Computing with C# ©2003, 2011 Art Gittleman.
Arrays (Part 1) Computer Science Erwin High School Fall 2014.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
The Java Programming Language
August 6, 2009 EVENT DRIVEN PROGRAMMING WITH JAVA.
CSC204 – Programming I Lecture 4 August 28, 2002.
JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in In the Java programming language: A program is made.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Java Programming Presented by Daniel Rosenthal Friday, November 30 th, 2007.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Chapter 2: Java Fundamentals
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Neal Stublen What's a class?  A class is comprised of a set of data and the actions taken on that data  Each action is represented.
JavaScript Syntax, how to use it in a HTML document
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
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.
Chapter 3 Introduction To Java. OBJECTIVES Packages & Libraries Statements Comments Bytecode, compiler, interpreter Outputting print() & println() Formatting.
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[]
By Mr. Muhammad Pervez Akhtar
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING String and Scanner Objects.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Lecture1 Instructor: Amal Hussain ALshardy. Introduce students to the basics of writing software programs including variables, types, arrays, control.
CSC 110 – Intro to Computing - Programming
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Console Output, Variables, Literals, and Introduction to Type
C# and the .NET Framework
Lecture Note Set 1 Thursday 12-May-05
Statements, Comments & Simple Arithmetic
Introduction to Java Programming
An Introduction to Java – Part I, language basics
The Boolean (logical) data type boolean
Unit-1 Introduction to Java
Java Intro.
Anatomy of a Java Program
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Instructor: Alexander Stoytchev
ITE “A” GROUP 2 ENCAPSULATION.
Presentation transcript:

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(). public static void main(String args[]) { System.out.println("This is a simple Java program."); }

Compiling the Program C:\>javac Example.java The javac compiler creates a file called Example.class that contains the bytecode version of the program The output of javac is not code that can be directly executed

To actually run the program, you must use the Java interpreter, called java. C:\>java Example When a class member is preceded by public, then that member may be accessed by code outside the class in which it is declared

The keyword static allows main( ) to be called without having to instantiate a particular instance of the class The keyword void simply tells the compiler that main( ) does not return a value

A Second Short Program class Example2 { public static void main(String args[]) { int num; // this declares a variable called num num = 100; // this assigns num the value 100 System.out.println("This is num: " + num); num = num * 2; System.out.print("The value of num * 2 is "); System.out.println(num); }

Two Control Statements The if Statement: if(condition) statement; if(num < 100) System.out.println("num is less than 100");

The for Loop: for(initialization; condition; iteration) statement; class ForTest { public static void main(String args[]) { int x; for(x = 0; x<10; x = x+1) System.out.println("This is x: " + x); }

Using Blocks of Code: using { and } Write java programs to do the following 1.Find sum of the digits of number Find if is palindrome.

Lexical Issues Whitespace: –Java is a free-form language –In Java, whitespace is a space, tab, or newline Identifiers: - Identifiers are used for class names, method names, and variable names - Java is case-sensitive

Identifier naming rules Should not begin with a number Any descriptive sequence of uppercase,lowercase,numbers,_,$ characters

Literals: A constant value in Java is created by using a literal representation of it

Comments There are three types of comments defined by Java. 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

The Java Keywords There are 49 reserved keywords currently defined in the Java language