An Introduction to Java Part 1 Dylan Boltz

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 Class. Name { public static void main(String[] args) { Basic Program Structure public class Class. Name { public static void main(String[] args) {](http://slidetodoc.com/presentation_image_h2/2e085b1d1213cda966d45b5fe1c2f2f6/image-3.jpg)
Basic Program Structure public class Class. Name { 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 compare. To(String other) boolean equals(Object other) int length()

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 binary. Search(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/cs 265_fall_2010/j ava_language_basics. pdf http: //java. sun. com/docs/books/tutorial/java/index. ht ml http: //www. ensta. fr/~diam/java/online/notesjava/data/basic_types/21 integers. html http: //www. ensta. fr/~diam/java/online/notesjava/data/basic_types/22 floatingpoint. html
- Slides: 12