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

  • Parts of AICPA Code of Professional Conduct

    Parts of AICPA Code of Professional Conduct

    D. Interpretations of Rules of Conduct. The AICPA's Division of Professional Ethics provides published interpretations of rules of conduct when practitioners have frequent questions. Before interpretations are finalized, they are sent to a large number of key people in the...
  • Outwood Academy Portland Design and Technology KS3: Food

    Outwood Academy Portland Design and Technology KS3: Food

    Watch a cooking show on TV, and record all of the good and bad health, safety and hygiene points that you see. Research 5 pieces of food manufacturing equipment that would be used in the food industry. Research how one...
  • STEM at WSU for K-12 math teachers

    STEM at WSU for K-12 math teachers

    In conjunction with the T&L department we designed this endorsement to meet the needs of middle school teachers in offering a more robust mathematics experience for their students. Algebraic reasoning, proportional reasoning, geometry, probability and statistics. High school: We offer...
  • Géneros Literarios

    Géneros Literarios

    GÉNEROS LITERARIOS GÉNEROS LITERARIOS LÍRICO Expresa sentimientos NARRATIVO Cuenta historias DRAMÁTICO Teatro: los personajes hablan GÉNERO LÍRICO (VERSO Y PROSA) Es el que usan los poetas para expresar sentimientos.
  • Weinberger/Powell Doctrine (1984)

    Weinberger/Powell Doctrine (1984)

    Political Activities Other Issues Two Regional Wars Transformation Weapons Acquisition BRAC Missile Defense U.S. Military Establishment Organizational Structure Evolution Present day Military Professionalism Doctrines Performance Patterns Military and Society U.S. Military Spending vs. the World: $ in Billions "Allies" refers...
  • Temporal Information Extraction and Shallow Temporal Reasoning Dan

    Temporal Information Extraction and Shallow Temporal Reasoning Dan

    The particularly essential, and relevant, characteristic of TimeML is the factoring out - in a non-consuming, relation-like, tag - the notion of a link between events and temporal expressions, and events and events.
  • Communication Disorders

    Communication Disorders

    I want that cookie. Syntax varies among languages. Semantics The meaning of what is expressed; meaning at the sentence level PLANT I am going to plant the tree My mother works in the coal plant. He gave me a plant...
  • Security Overview Strategic Technology Office

    Security Overview Strategic Technology Office

    Wide Area Workflow (WAWF) i-Edison. Approved for Public Release, Distribution Unlimited. 4/5/2018. ... Wide range of temporal and geospatial activities - e.g. days to years, neighborhood to state. Generate scenarios and design / execute the evaluations.