Download presentation
Presentation is loading. Please wait.
Published byHannah Dalton Modified over 8 years ago
1
An Introduction to Java – Part 1 Dylan Boltz
2
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++
3
Basic Program Structure public class ClassName { public static void main(String[] args) { program statements } user defined methods }
4
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.
5
Operators Arithmetic Operators: +, -, *, /, % Relational Operators: ==, !=,, = Logical Operators: &&, ||, !
6
Data Types Integers – int, short, long, byte Floating-Point Types – float, double Character Type – char Boolean Type – boolean (values: true, false)
7
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()
8
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);
9
Conditional Statements If/else statements similar to C++ Curly braces not required for enclosing a single instruction Example: If(…){ … }else{ … } Example: If(…) … else …
10
Loops While Loops Similar to C++ Example while(…){ … } For Loops Also similar to C++ Example for(initialization; condition; update){ … }
11
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;
12
Resources http://www.cs.drexel.edu/~knowak/cs265_fall_2010/java_l anguage_basics.pdf http://www.cs.drexel.edu/~knowak/cs265_fall_2010/java_l anguage_basics.pdf http://java.sun.com/docs/books/tutorial/java/index.html http://java.sun.com/docs/books/tutorial/java/index.html http://www.ensta.fr/~diam/java/online/notes- java/data/basic_types/21integers.html http://www.ensta.fr/~diam/java/online/notes- java/data/basic_types/21integers.html http://www.ensta.fr/~diam/java/online/notes- java/data/basic_types/22floatingpoint.html http://www.ensta.fr/~diam/java/online/notes- java/data/basic_types/22floatingpoint.html
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.