Copyright © 2004-2013 Curt Hill Java Looking at our first console application in Eclipse.

Slides:



Advertisements
Similar presentations
Introduction to Programming Java Lab 1: My First Program 11 January JavaLab1.ppt Ping Brennan
Advertisements

Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
1 Microsoft Access 2002 Tutorial 9 – Automating Tasks With Macros.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
Classes  All code in a Java program is part of a class  A class has two purposes  Provide functions to do work for the programmer  Represent data.
Automating Tasks With Macros
How to Create a Java program CS115 Fall George Koutsogiannakis.
Introduction to Java Programming, 4E
©2004 Brooks/Cole Chapter 1: Getting Started Sections Covered: 1.1Introduction to Programming 1.2Constructing a Java Program 1.3The print() and println()
Tutorial 10 Programming with JavaScript
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,
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
S.W. Ma/CIM/LWL41211/2 Prog. IIA Page 1 HKIVE (Lee Wai Lee Campus) Department of CIM Course : Year 2 Module : Programming IIA Textbook : Introduction.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
1 v1.6 08/02/2006 Overview of Eclipse Lectures 1.Overview 2.Installing and Running 3.Building and Running Java Classes 4.Refactoring 5.Debugging 6.Testing.
Using Eclipse. What is Eclipse? The Eclipse Platform is an open source IDE (Integrated Development Environment), created by IBM for developing Java programs.
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures for Java William H. Ford William R. Topp Appendix E The EZJava.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 27 - Phone Book Application Introducing Multimedia.
1 JavaScript in Context. Server-Side Programming.
Tutorial 10 Programming with JavaScript
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
Introduction to Java Programming with Forte Y. Daniel Liang.
Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo Nesa Matic
Copyright © Curt Hill First Window Builder Program Easy GUIs in Eclipse.
Unit 1: Java and Eclipse The Eclipse Development Environment.
Comments in Java. When you create a New Project in NetBeans, you'll notice that some text is greyed out, with lots of slashes and asterisks:
9/2/ CS171 -Math & Computer Science Department at Emory University.
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.
Windows Builder An Eclipse Plugin for Creating Windows Graphical User Interfaces Copyright © 2014 Curt Hill.
Introduction to programming in the Java programming language.
EIE375 BlueJ: Getting Started Dr Lawrence Cheung.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
Copyright Curt Hill Variables What are they? Why do we need them?
Copyright © Curt Hill More Components Varying the input of Dev-C++ Windows Programs.
Anatomy of a Java Program. AnotherQuote.java 1 /** A basic java program 2 * 3 Nancy Harris, James Madison University 4 V1 6/2010.
3. Methods. Programming Paradigms Procedural Programming ‘Imperative’ assignment used to create state, and procedures manipulate state. E.g., C, Assembly,
Java methods Methods break down large problems into smaller ones Your program may call the same method many times saves writing and maintaining same code.
CSI 3125, Preliminaries, page 1 Compiling the Program.
Georgia Institute of Technology Creating Classes part 4 Barb Ericson Georgia Institute of Technology May 2006.
Eclipse Project. Installing Visit to download a copy for your home computerhttp:// –Get Release version 3.0 (or.
By Mr. Muhammad Pervez Akhtar
Creating a Java Application and Applet
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Lesson 28: More on the GUI button, frame and actions.
Copyright © Curt Hill Simple I/O Input and Output using the System and Scanner Objects.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program.
Introduction to Java Programming, 4E Y. Daniel Liang.
Eclipse.
Introduction to Java Import Scanner class to use in our program
The eclipse IDE IDE = “Integrated Development Environment”
Console and GUI Programs
CompSci 230 Software Construction
Intro to Java.
Java Intro.
Anatomy of a Java Program
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Java Looking at our first console application in Eclipse
Presentation transcript:

Copyright © Curt Hill Java Looking at our first console application in Eclipse

Copyright © Curt Hill A moment on paradigms Java is well suited for either the console or GUI paradigm A console program views the keyboard/screen as nearly a single device –We both read and write to it using strings A GUI program has a WIMP interface: –Windows –Input –Menus –Pointer The console paradigm is easier for starters, but we may do both

Eclipse Eclipse is the Interactive Development Environment that we will use Originally developed by IBM Donated to public domain Now maintained by the Eclipse Foundation – Copyright © Curt Hill

Terminology for Eclipse Resource –Things such as projects, directories and files Editor –A window pane that allows changes to a resource, often Java code View –A window pane that shows a resource Perspective –A group of editors and views Copyright © Curt Hill

Eclipse Construction steps Create new project Create new class Customize as needed Debug and run

Copyright © Curt Hill Create new project Click File|New|Java Project Use the New Project dialog to set some initial parameters Specify the project name This will become a directory tree The project is an XML file of name:.project in the directory The screen shots follow

Create New Project Copyright © Curt Hill

Enter Project Name Copyright © Curt Hill

A usually skipped screen Copyright © Curt Hill

Projects and Classes A project is just a tool to manage pieces We now have to add the pieces Each Java program is a class Any class might use other classes as well What we now do is add the main or root class to our project Copyright © Curt Hill

Create new class Click File|New|Class This generates a new class –This new class will be your program Use java.lang.Object as the ancestor class Specify a main method –Click on the box Copyright © Curt Hill

Add an initial class Copyright © Curt Hill

Name the class Copyright © Curt Hill

Specified names In the prior screen there were three things that were specified: –Package –Class name –Inclusion of the main method via checkbox The package name is usually all lower case The class name usually starts with a capital letter and each subsequent word is capitalized: FirstCon Copyright © Curt Hill

Generated Code Copyright © Curt Hill

Customize as needed At this point we have a Java console program with proper form, which does nothing –Now add the desired functionality Insert into main: System.out.println(“Hello world”); Java is case sensitive so System must start with a capital That doesn’t sound like much work –It will get worse

Customized Copyright © Curt Hill

Debug and run Click the run button or use menu Run|Run Run time properties are displayed –Specify the new class name –Search may be easiest Console output will appear in the bottom pane –First the command line –Next the program output

Start Run Copyright © Curt Hill

Run Copyright © Curt Hill

package firstcon; public class FirstCon { /** args */ public static void main (String[] args) { // TODO Auto-generated method stub System.out.println("Hello World"); } } Code

Copyright © Curt Hill Comments A comment explains things for people –Ignored by Java /* and */ –Enclose multiline comments // –Makes the rest of the line a comment Documentation uses special comments –Program: Javadoc

Copyright © Curt Hill Class Declaration public class FirstCon { Objects in Java are called Classes –A class binds together variables and methods This class is named FirstCon Its visibility is public –A private class in this case could not be executed

Copyright © Curt Hill Classes and files A file is the compilation unit –It must have an extension.java –Each file must have one and only one public class The file name must match the public class name –Even case, which may be a problem on MS Operating Systems Most of these issues are handled by Eclipse without our intervention

Copyright © Curt Hill Compilation Units Public class names must match file name Other private or friendly classes may be present in the file Each class will have its own object (.CLASS) file after it is compiled

Copyright © Curt Hill Main Function Most classes have both variables and methods Every application must have a method called main, which is where execution starts Main’s parameter is a string array –Command line parameters Often, in a console program most of the work occurs in the main method

Copyright © Curt Hill Main function public static void main(String args[ ]) { System.out.println("Hello World!"); } // end of main void indicates main returns nothing It is public –Accessible to system

Copyright © Curt Hill Main function It is static –A static function has limited access to class data –Can be called without having a class instance This main function has just one statement We will cover static more later

Copyright © Curt Hill Writing to the console System.out.println("Hello world"); System is an instance of a class that contains numerous predefined classes and methods out is an output stream class with methods print and println

Copyright © Curt Hill print and println Overloaded method names Accept one parameter There is a version for almost every parameter type

Classes and objects Sometimes these two terms are used interchangably A class is a type –Defines possible values and actions An object is an instance of a class Example –A person name would be a class –“Curt Hill” would be an object, an instance of a class Copyright © Curt Hill

Finally There are some other details that need to be considered: –Handing in programs These will be covered in a subsequent presentation Copyright © Curt Hill