An Introduction to Java - Part 1

An Introduction to Java - Part 1

An Introduction to Java Part 1 Dylan Boltz What is Java? An object-oriented programming language Developed and released by Sun in 1995 Designed to bridge the gap between digital consumer devices and computers Syntax very similar to that of C++ Basic Program Structure public class ClassName

{ public static void main(String[] args) { program statements } user defined methods } Things to Remember About the Structure

Public classes are accessible from any class. Classes, which are not declared public are accessible only within their package Public methods may be called from any class. Static methods do not operate on objects. The keyword void indicates that the method does not return a value. The array args of the main method stores command line arguments. Operators Arithmetic Operators: +, -, *, /, % Relational Operators: ==, !=, <,

>, <=, >= Logical Operators: &&, ||, ! Data Types Integers int, short, long, byte Floating-Point Types float, double Character Type char Boolean Type boolean (values: true, false) Strings Standard class in Java + used for string concatenation

Example: String greeting = hello; Member Functions: int compareTo(String other) boolean equals(Object other) int length() Variables Variables need to be declared Variables must be initialized before use

Examples: int year = 2010; System.out.println(year); String greeting = Hello; String name = Bob; System.out.println(greeting + + name);

Conditional Statements If/else statements similar to C++ Curly braces not required for enclosing a single instruction Example: If(){ }else{ } Example:

If() else Loops While Loops Similar to C++ Example while(){

} For Loops Also similar to C++ Example

for(initialization; condition; update){ } Arrays Also similar to C++ Arrays are a standard class in Java

Selected Member Functions static void sort(type [ ] a) static int binarySearch(type [ ] a, type v) static boolean equals(type [ ] a, Object other) Example: int[ ] numbers = new int[ 10 ]; for(int i = 0; i < numbers.length; i++) numbers[ i ] = i; Resources

http://www.cs.drexel.edu/~knowak/ cs265_fall_2010/java_language_basics.pdf http://java.sun.com/docs/books/tutorial/java/ index.html http://www.ensta.fr/~diam/java/online/notesjava/data/basic_types/21integers.html http://www.ensta.fr/~diam/java/online/notesjava/data/basic_types/22floatingpoint.html

Recently Viewed Presentations

  •  Neo-Freudians (NeoAnalytic)  Projective tests The Neo-Freudians (Psychodynamic) Break

    Neo-Freudians (NeoAnalytic) Projective tests The Neo-Freudians (Psychodynamic) Break

    Break from the Freudian theory of sexual desires and repressed aggression. ... Possible Sexual Imagery: Male sex organs and female breasts, right about where you would expect to find them. This is the blot that allegedly can determine sexual preference.
  • The Crucible - WordPress.com

    The Crucible - WordPress.com

    Crucible: The word crucible has many meanings. Its literal definition is a container that resists heat or the hollow at the bottom of an ore furnace. However, its connotations include melting pot, in the symbolic sense, and bearing of a...
  • #15 - What Causes Air Pollution? Section 12.1

    #15 - What Causes Air Pollution? Section 12.1

    #15 - What Causes Air Pollution? Section 12.1 Objectives: Name 5 primary air pollutants, and give sources for each. Name the 2 major sources of air pollution in urban areas. Describe how smog forms. Define "air pollution" When harmful substances...
  • Rabies in Wildlife in Texas: Spectrum of Disease and its ...

    Rabies in Wildlife in Texas: Spectrum of Disease and its ...

    Rabies in Texas Bats: Spectrum of Disease and its Impact on Humans Susan Shaffer Public Health Internship Program School of Biological Sciences The University of Texas at Austin
  • EMS-6 Update

    EMS-6 Update

    April Bassett. Simon Pang. DPH Homeless Outreach Team. Operations began on January 30, 2016. EMS High Users. Identified clients with high 911 utilization >4 calls/month or >2 calls/day or. Identified as system high users (HUMS) Work with existing resources to...
  • Case Study: Losing the Rainforest, One Tree at a Time

    Case Study: Losing the Rainforest, One Tree at a Time

    Case Study: Losing the Rainforest, One Tree at a Time Synthetic Aperture Radar (SAR) satellite images are used to study change in the Amazon rainforest. There are three great reasons for using SAR images to look at the rainforest. The...
  • A Presentation on Basic Principles (PIES) Table of Contents ...

    A Presentation on Basic Principles (PIES) Table of Contents ...

    A Presentation on PIES. Delain Hayes, Jr. Southwestern College . Picture background with textured caption (Intermediate) To reproduce the textured shape effects on this slide, do the following:
  • Dia 1 - lukio.palkane.fi

    Dia 1 - lukio.palkane.fi

    Ergonomiassa on kysymys kitkan poistamisesta ihmisen ja työn tekemisen väliltä. Ergonominen muotoilu huomioi esineiden, laitteiden ja koneiden sopivuuden ihmisen ominaisuuksiin. (Kettunen 2001, 30.) ERGONOMISET TARPEET Käytön helppous (Tuotteen monet ominaisuudet, yksi-tyiskohdat tai käytännöt voivat hämmentää ja turhaut-taa ...