1 / 10

Java Language Basics

Java Language Basics. Shawn Mandik. Program Structure. Basic structure: public class ClassName { public static void main(String[] args) { program statements } user defined methods }. Class Notes. “public” classes and methods can be called from any class

tyme
Download Presentation

Java Language Basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java Language Basics Shawn Mandik

  2. Program Structure Basic structure: public class ClassName { public static void main(String[] args) { program statements } user defined methods }

  3. Class Notes • “public” classes and methods can be called from any class • Static methods incompatible with objects • Array “arg” of main method holds command line arguments

  4. File Notes • Filename must be the same as the single public class • example: file containing public class ThisClass should be named ThisClass.java • Compiled file will be given extension “.class”

  5. Variable Types • Similar to C++ • Examples: int, long, char, float • New data types: boolean (either true or false) byte (similar to int, but only 8-bit – saves memory)

  6. String Handling • Strings are a standard class in Java • Concatenation performed with “+” Example: • String s=”Hello”; • String t=”world”; • System.out.println(s+” “+t);

  7. Useful String Functions • int compareTo(String other) Returns negative or positive if strings are unequal, 0 if equal • boolean equals(Object other) Returns true if implicit and explicit arguments are equal • int length() Returns length of the string

  8. Loops/Conditional • Same as C++ • if(argument) { ... } • while(argument) { … } • for(argument) { … }

  9. Arrays • Arrays are also a standard class Syntax example: int[] numbers = new int[n]; for(int i=0; i<numbers.length; i++) numbers[i]=i;

  10. Useful Array Functions • static void sort(type[] a) Runs quicksort algorithm on array a • static int binarySearch(type[] a, type v) Runs binary search on array a to find v • static boolean equals(type[] a, Object other) Returns true if object other is an array equal to a

More Related