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

  • Protocol T MSL deck

    Protocol T MSL deck

    Baseline CSF values were converted from the thickness value measured on a Spectralis or Cirrus OCT machine to a Stratus equivalent value for 583 scans. One-year CSF values were converted from a thickness value measured on a Spectralis or Cirrus...
  • Matching Markets - Stanford University

    Matching Markets - Stanford University

    Matching. A . matching. is a set of pairs (m,w) such that each individual has one partner. If the match includes (m,m) then m is unmatched. A matching is . stable. if. Every individual is matched with an acceptable partner....
  • Classification and Compensation Department of Human Resources  Position

    Classification and Compensation Department of Human Resources Position

    Classification groups jobs of a common nature with similar duties and responsibilities to provide structure to the organization and assigns them an appropriate pay band. East Carolina University operates under two separate classification and compensation systems for SHRA and CSS...
  • By Suri Raut (sraut@gmu.edu), Andrew S. Hahn (ahahn@gmu.edu),

    By Suri Raut ([email protected]), Andrew S. Hahn ([email protected]),

    exit PCP meeting, Alumni survey, SIS, SIB-R; QRI 8.1D: Collection of student follow-up data. ... Arial MS Pゴシック Calibri Georgia Wingdings Times New Roman Default Design Microsoft Word Document PowerPoint Presentation ...
  • Mental & Psychological health of Women What is

    Mental & Psychological health of Women What is

    Mental & Psychological health of Women What is mental & Psychological health Mental health & Women "Women all over the world are the biggest consumers of health care.
  • WWW List #3 first/second: 3.1 - Weebly

    WWW List #3 first/second: 3.1 - Weebly

    Polygamy - married to many. Polygon - many-sided figure. Hypo - under. Hypothesis - guess is "under" trial. Hypothermia -under the correct body temperature. Neuro - nerve. Neurosurgeon - brain surgeon (house of all nerves) Neurology - the science of...
  • Building Capacity in Virginia Schools: VDOE Update 2013

    Building Capacity in Virginia Schools: VDOE Update 2013

    Building Capacity in Virginia Schools: VDOE Update 2013. Debbie Pfeiffer, Ed. D., CBIS. Virginia Department of Education. Office of Special Education Instructional Services
  • Genres Of Literature Please take notes in the

    Genres Of Literature Please take notes in the

    Hatchet. Diary of a Wimpy Kid. Historical Fiction. ... Animals talk and act as humans. Moral at the end (Don't count your chickens before they're hatched) ... This book was written by Hillary Duff about her life and growing up...