Creating a Program in JCreator. JCreator is then used to create our program. But the first step is to create a new file.

Similar documents
SDKs - Eclipse. SENG 403, Tutorial 2

Simple Java Programs. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Fundamentals of Programming. By Budditha Hettige

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

CSc 2010 Principles of Computer Science, Fall 2013 Practice Problems for Midterm 3* * 3 17 % 9-20 % (26 / 7) "2"

Even though we created a folder for the workspace, we still have to let JCreator do the same. So click File, New, and then Blank Workspace.

Chapter 3 Intro to Java

Introduction to Java. Java Programs Classes, Methods, and Statements Comments Strings Escape Sequences Identifiers Keywords

Chapter 2: Programming Concepts

Introduction to JAVA

Week 2: Data and Output

Programming in Java Prof. Debasis Samanta Department of Computer Science Engineering Indian Institute of Technology, Kharagpur

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

CS 231 Data Structures and Algorithms, Fall 2016

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

COMP163. Introduction to Computer Programming. Introduction and Overview of the Hardware

Welcome to CSE 142! Whitaker Brand. University of Washington, Winter 2018

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Welcome to CSE 142! Zorah Fung University of Washington, Spring Building Java Programs Chapter 1 Lecture 1: Introduction; Basic Java Programs

Entering the world of Javatar

Introduction to Computer Programming

Introduction to Computer Science I

AP Computer Science Summer Assignment (updated 5/29/2018) DUE : Sept. 4, 2018

Lesson 01 Introduction

Getting Started (1.8.7) 9/2/2009

C++ Support Classes (Data and Variables)

Getting Started with Java. Atul Prakash

Building Java Programs. Introduction to Programming and Simple Java Programs

B.V. Patel Institute of BMC & IT, UTU 2014

Java Bytecode (binary file)

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

An overview of Java, Data types and variables

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Introduction to OOP Using Java Pearson Education, Inc. All rights reserved.

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

17 Hello world 18 Type: String: literal 19 Standard API: System: out.println() 20 Hello world 21 Statement 22 Statement: simple statements are ended w

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

Lesson 04: Our First Java Program (W01D4

List of Slides 1 Title 2 Chapter 2: Sequential execution and program errors 3 Chapter aims 4 Section 2: Example:Hello world 5 Aim 6 Class: programs ar

CHAPTER 2 Java Fundamentals

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Lab # 2. For today s lab:

Section 2.2 Your First Program in Java: Printing a Line of Text

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

Java Programming. What is a program? Programs Recipes. Programs as Recipes 8/16/12. Pancakes In one bowl. mix: 1½ cup flour

NetBeans IDE Java Quick Start Tutorial

Programming with Java

CS11 Java. Fall Lecture 1

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Computer Science AP 2017 Summer Assignment Mrs. McFarland

CSE 142. Lecture 1 Course Introduction; Basic Java. Portions Copyright 2008 by Pearson Education

Building Java Programs. Chapter 1: Introduction to Java Programming

Class 1: Homework. Intro to Computer Science CSCI-UA.0101 New York University Courant Institute of Mathematical Sciences Fall 2017

Mobile App:IT. Methods & Classes

Basic Programming Language Syntax

Copyright 1999 by Deitel & Associates, Inc. All Rights Reserved.

Programming with Java

2 Getting Started. Getting Started (v1.8.6) 3/5/2007

AP Computer Science A Summer Assignment

Building Java Programs

Chapter 2: Java Fundamentals

8/23/2014. Chapter Topics. Chapter Topics (2) Parts of a Java Program. Parts of a Java Program. Analyzing The Example. Chapter 2: Java Fundamentals

CS 106 Introduction to Computer Science I

Software and Programming 1

Certified Core Java Developer VS-1036

COMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015

JAVA PROGRAMMERS GUIDE LESSON

4 Programming Fundamentals. Introduction to Programming 1 1

Getting Started With Java

COMP 110 Project 1 Programming Project Warm-Up Exercise

Lecture (01) Getting started. Dr. Ahmed ElShafee

Programming - 2. Common Errors

A Visit to the United Nations

Java Programming. What is a program? Programs as Recipes. Programs Recipes 8/20/15. Pancakes In one bowl

Basics of Java Programming

COT 3530: Data Structures. Giri Narasimhan. ECS 389; Phone: x3748

Chapter 1: A First Program Using C#

Java Basic Syntax. Java vs C++ Wojciech Frohmberg / OOP Laboratory. Poznan University of Technology

Getting Started with Command Prompts

Lecture 1: Basic Java Syntax

CHAPTER INTRODUCTION

Key Differences Between Python and Java

Building Java Programs

First Java Program - Output to the Screen

VENTURE. Section 1. Lexical Elements. 1.1 Identifiers. 1.2 Keywords. 1.3 Literals

Table of Contents Date(s) Title/Topic Page #s. Abstraction

Primitive Data, Variables, and Expressions; Simple Conditional Execution

C02: Overview of Software Development and Java

Full file at

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 9: OCT. 4TH INSTRUCTOR: JIAYIN WANG

Object-Oriented Programming

Multiple Choice Introduction Topics

Strings, Strings and characters, String class methods. JAVA Standard Edition

Chapter Goals. Chapter One: Introduction. Prerequisites. What Is Programming?

Introduction Basic elements of Java

CSCI 161: Introduction to Programming I Lab 1b: Hello, World (Eclipse, Java)

Building Java Programs Chapter 1

Tutorial 1 CSC 201. Java Programming Concepts عؾادئماظربجمةمبادؿكدامماجلاصا

Transcription:

First Program (02) Creating a Java program and understanding the basic concepts. Creating a Program in JCreator It is usually a good idea to create a folder where you re going to save your Java programs. So the first step is to create a folder. Create a folder named My Java in My Documents JCreator is then used to create our program. But the first step is to create a new file. 1. Start JCreator 2. Click on File > New File > File 3. Choose Empty Java File 4. Specify the filename in the space provided and choose the location where you want to save the file. In this case choose the previously created folder My Java. Click on Finish. Mr. A. Gatt Page 1 of 6

5. That will create the empty Java file. 6. In the space provided we re going to type our first program. 7. Now click on the Build File icon. This will compile the program. If you do not have any mistakes it will show you Process Complete in the Build Output, otherwise it will show you that you have errors. 8. Finally, the program can be executed by clicking on the Run Project. Mr. A. Gatt Page 2 of 6

9. This will execute the program and run it in a window. 10. When a program is compiled a new file is created with the class extension. This is the byte code which the JVM uses to run the program. This is the source-code file typed in JCreator. Its contents can also be viewed with a basic text editor. This is the byte code file created when the program is compiled. Mr. A. Gatt Page 3 of 6

Program Structure Comments are used to remind the programmer what the code does. //Program 1 : My First Program class TestProgram { public static void main (String args[]){ System.out.println("Hello World!"); This is the main class and where the program starts to execute. The class is created here by giving it a name. This shows a The semi-colon ends a statement. message on The curly brackets show the screen. where a scope begins and ends. Comments Comments are used to remind the programmer what the code does. They are called in-line documentation because they are found within the program itself and not as a separate document. There are two type of comments; single line and multi-line. Single line comments can only be on a single line. In order to create a single-line comment, // must be used before the comment. Multi-line comments can be spread over a number of lines, these type of comments must start with /* and then end with */. class The keyword class shows that a new class is being created. Just after the keyword, there is the name of the class, in this case TestProgram. Then the curly brackets are used to show where the code of the class begins and where it ends. Mr. A. Gatt Page 4 of 6

public static void main (String args[]) Every program must have one main method; this is where the program starts. It is made up of different parts: public this means that this method is available from outside the class static this method can be used without creating an instance of the class void this method does not return a value main the name of the method String args[] an array of type String which can accept a number of arguments in array args Curly Brackets { These show where a scope begins and ends. System.out.println( Hello World ); This statement shows the text between the quotes on the screen; in this case Hello World. Since the keyword println() is used, the cursor will then move to the next line. The println() is found in the out stream in the System class. If text must be displayed on screen and the cursor has to remain in the same line print() can be used instead of println(). Semi-colon Every statement in Java must end with a semi-colon ; Escape Characters Escape characters can be used within quotes when using the println() method to format text. Escape characters include: Escape Character Use \ Displays a single quote \ Displays a double quote \\ Dispays a backslash \n Moves to a new line \t Insert a tab Mr. A. Gatt Page 5 of 6

Activities 1. Copy the following program and try to build it. Check for the errors, fix them and build it again. class question1 { public static void main (String args[]) { System.out.println( This is the first line ) System.out.println(This is the second line); System.out.println( This is the third line ); 2. Explain the difference between println() and print(). Write a program to show the difference. 3. Write a program that shows your name, surname on one line and the address on another line but use only one println() method. 4. Write a program that displays the names and marks of a number of students. It should be displayed as follows: Name Marks Alan Borg 90 Peter Abela 23 Anna Zarb 65 5. Write a program that displays a recipe ingredients and the quantity required. The items must be neatly aligned. *** Mr. A. Gatt Page 6 of 6