An Introduction to Java – Part I

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
Introduction to Computers and Programming Lecture 7:
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
CMT Programming Software Applications
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
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.
CS102--Object Oriented Programming Review 1: Chapter 1 – Chapter 7 Copyright © 2008 Xiaoyan Li.
Hello, world! Dissect HelloWorld.java Compile it Run it.
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
Programming in Java; Instructor:Moorthy Introduction, Objects, Classes, Libraries1 Programming in Java Introduction.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
 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.
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Controlling Program Flow. Data Types and Variable Declarations Controlling Program Flow.
Introduction to Java Java Translation Program Structure
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs -
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Developed at Sun Microsystems in 1991 James Gosling, initially named “OAK” Formally announced java in 1995 Object oriented and cant write procedural.
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
Java Part I By Wen Fei, HAO. Program Structure public class ClassName { public static void main(String[] args) { program statements } user defined methods.
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Object Oriented Programming Lecture 2: BallWorld.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Lecture 7: Arrays Michael Hsu CSULA 3 Opening Problem Read one hundred numbers, compute their average, and find out how many numbers are above the average.
C++ Lesson 1.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
JAVA MULTIPLE CHOICE QUESTION.
Intro to ETEC Java.
Chapter No. : 1 Introduction to Java.
Lecture 5: Some more Java!
Yanal Alahmad Java Workshop Yanal Alahmad
Introduction to programming in java
Programming Language Concepts (CIS 635)
SELECTION STATEMENTS (1)
Chapter 2.
CMSC 202 Static Methods.
Starting JavaProgramming
Introduction to Java Programming
An Introduction to Java – Part I, language basics
Java so far Week 7.
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Recap Week 2 and 3.
Classes and Objects Static Methods
Introduction to java Part I By Shenglan Zhang.
First Semester Review.
Presentation transcript:

An Introduction to Java – Part I Zachary Schoenstadt

Useful Links http://download.oracle.com/javase/tutorial/j ava/index.html http://download.oracle.com/javase/1.5.0/do cs/api/

Basic Structure public class ClassName { public static void main(String[] args) //program statements } //user defined methods Classes and methods have to be defined public private or protected. Static methods do not operate from within instanced objects. There can be only one public class in a single source file. The array args in the main method store command line arguments

Source Code, Compilation and Execution Source code uses extension .java The Source code needs to be the same name as the public class Compiled into bytecode with extension .class Executed with command “java classname” which launches into an interpreter

Primitive Data Types Integers: int, short, long, byte int foo = 1; Floating-Point Types: float, double float foo2 = 1.0f; The Character Type: char char foo3 = ‘a’; The Boolean Type: boolean (values: true, false) Boolean foo4 = true;

String Standard class (no need to import) Strings are enclosed in double quotes String words = “Hello World!”; Concatenate with: + int compareTo(String other); returns 1,0 or -1 Boolean equals(Object other); int length() int compareTo(String other) returns a negative value if the implicit argument comes before the explicit argument (in alphabetical ordering), a positive value if the explicit argument comes before the implicit argument, and 0 if the strings are equal boolean equals(Object other) returns true if the implicit argument equals the explicit argument int length() returns the length of the string

Variables Variables in Java need to be declared. You need to initialize variables before you use them. All variables/objects are passed by passed by reference, by default int n=5; System.out.println(n); String s=”Hello”; String t=”world”; System.out.println(s+” “+t);

If/else Statement Same as C++ If(…) //single statement if(…) { … } else if else

Loops Again following C++ pattern while (…) { //stuff } do{ }while(…); for(initialization; condition; update) {

Arrays Standard Class Declared like so: type [] varname = new type[n]; Ex: int[] nubers = new int[10]; Ex: char[] letters = {‘a’ , ‘b’ , ‘c’ }; arrayName.length to findlength of the array static void sort(type[] a); static int binarySearch(type [] a, type v) ; static boolean equals(type [] a, Object other) static void sort(type [] a) Argument a is an array of a type listed in Data Types. sorts an array using a QuickSort algorithm static int binarySearch(type [] a, type v) Argument a is a sorted array of a type listed in Data Types, argument v has the same type as the elements of a. applies the BinarySearch algorithm to search for v static boolean equals(type [] a, Object other) Argument a is an array of a type listed in Data Types, argument other is an object. returns true if other is an array of the same type as a, if it has the same length, and if the corresponding elements match

Last bits of Info Static functions are called through the class rather than instanciated objects Array.sort( ... ); // requires import java.util.Arrays Print to console using: System.out.print(...); // System.out.printl(…); //automaticly causes newline Use “import” to add packages akin to “#include” in c++ import java.util.Random; import java.util.*; Java has a Math.random and a Random in util with slightly different functionality