SlideServe
Menu
Préférences
© SlideServe · v2026

Java Programming Essentials: Classes, Control, and Communication

kamuzu avatar
10 diapositives · 236 Views · Sep 09, 2014

Learn Java basics: classes, control structures, static methods. Emphasize encapsulation, method calling, and library usage. Explore package organization, control flow, and object-oriented principles. Discover the utility of static methods and interact with predefined Java classes.

Java Programming Essentials: Classes, Control, and Communication - slide 1
01 / 10Java Programming Essentials: Classes, Control, and Communication
1 / 17

Télécharger la présentation

Java Programming Essentials: Classes, Control, and Communication
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Review of Java • Classes are object factories • Encapsulate state/data and behavior/methods • Ask not what you can do to an object, but what … • A program is created by using classes in libraries provided and combining these with classes you design/implement • Design classes, write methods, classes communicate • Communication is via method call

  2. Control in Java Programs • We've concentrated on control within and between methods • Data types: primitive, array, String • Control: if, for-loop, return • What are alternatives to "execute the next statement"? • Repeat this block • Execute this block when this condition holds • Return from this method

  3. Smallest of 2, 3, …,n • We want to print the lesser of two elements, e.g., comparing the lengths of two DNA strands int small = Math.min(s1.length(),s2.length()); • Where does min function live? How do we access it? • Could we write this ourselves? Why use library method? public class Math { public static int min(int x, int y) { if (x < y) return x; else return y; } }

  4. Generalize from two to three • Find the smallest of three strands: s1, s2, s3 int small = … • Choices in writing code? • Write sequence of if statements • Call library method • Advantages? Disadvantages?

  5. Generalize from three to N • Find the smallest strand length of N (any number) in array public int smallest(String[] dnaCollection) { // return shortest length in dnaCollection } • How do we write this code? Where do we start?

  6. Static methods analyzed • Typically a method invokes behavior on an object • Returns property of object, e.g., s.length(); • Create new object : s.substring(2,5); • Object changes state: dna.cleave(rna); • Sometimes we don't need an object, e.g., square-root, min, even find CG ratio! • Invoked using class-name, not object • All information passed in, no internal state • Compare to String substring, need state of internal chars

  7. How do we know about stuff? • Where is documentation for Math class? • Where does Math class live in relation to other classes? • How do we access and read documentation? • By convention Java classes include comments processed by a program called javadoc that generates web pages • Writing stylized comments facilitates browsable docs • API is application programming interface

  8. Organization of classes • Java classes are organized into packages • Keep related classes together • Facilitates conceptual use and development (from client/programmer view and developer/programmer view) • Access to classes provided by import statement • All classes in java.lang imported silently • Math, String, Object, System,… • Other packages require providing compiler with location • Packages organized hierarchically and conventionally named import java.util.Arrays; // to sort arrays import org.biojava.bio.seq.DNATools;

  9. Richard Stallman • One of world's best progammers/hackers • Difference? Pejorative? • Developed GNU software • C/C++, emacs, libraries • Basis for Linux • Awards: • Macarthur genius award • Grace Murray Hopper • Invented copyleft, free software • Free speech, not free beer • Basis for most bioinformatics tools, Perl, biojava, …

  10. What is an ORF? • See http://www.ncbi.nlm.nih.gov/gorf/gorf.html • From BD: look at AE008569 (see page 160) • Why are the six open reading frames? • How do we know which is the best ORF? • Why does graphical representation help? • What about Java programming to find them • Why do we do this when it's already done