Getting started with Java

Similar documents
Introduction to Programming Using Java (98-388)

Advanced Programming Introduction

Programming Language Concepts: Lecture 2

CS 11 java track: lecture 1

An overview of Java, Data types and variables

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

Java Bytecode (binary file)

CSC Java Programming, Fall Java Data Types and Control Constructs

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

PROGRAMMING FUNDAMENTALS

13 th Windsor Regional Secondary School Computer Programming Competition

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

Java Programming. Atul Prakash

1. Download the JDK 6, from

CSC 1214: Object-Oriented Programming

Array. Prepared By - Rifat Shahriyar

3. Java - Language Constructs I

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

Programming Language Concepts: Lecture 1

Program Fundamentals

Introduction to Java

CS 231 Data Structures and Algorithms, Fall 2016

Following is the general form of a typical decision making structure found in most of the programming languages:

Lec 3. Compilers, Debugging, Hello World, and Variables

Chapters 1-4 Summary. Syntax - Java or C? Syntax - Java or C?

Computer Components. Software{ User Programs. Operating System. Hardware

COMP 202 Java in one week

Goals. Java - An Introduction. Java is Compiled and Interpreted. Architecture Neutral & Portable. Compiled Languages. Introduction to Java

CompSci 125 Lecture 02

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

INFO Object-Oriented Programming

CS313D: ADVANCED PROGRAMMING LANGUAGE

Computational Expression

Lecture 1: Overview of Java

CS 61C: Great Ideas in Computer Architecture Introduction to C

Java Basic Programming Constructs

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

The Java programming environment. The Java programming environment. Java: A tiny intro. Java features

1.1 Your First Program

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

Crash Course Review Only. Please use online Jasmit Singh 2

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

CMSC131. Introduction to your Introduction to Java. Why Java?

DM550 Introduction to Programming part 2. Jan Baumbach.

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Section 2.2 Your First Program in Java: Printing a Line of Text

Introduction to Java

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

1.1 Your First Program

Selected Questions from by Nageshwara Rao

1.1 Your First Program

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

Array. Array Declaration:

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Branching and Boolean Expressions

: Primitive data types Variables Operators if, if-else do-while, while, for. // // First Java Program. public class Hello {

Programming Language Concepts: Lecture 2

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Variable initialization and assignment

2 rd class Department of Programming. OOP with Java Programming

Computer Science II (20082) Week 1: Review and Inheritance

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it.

Non-numeric types, boolean types, arithmetic. operators. Comp Sci 1570 Introduction to C++ Non-numeric types. const. Reserved words.

Computer Science is...

Java Review Outline. basics exceptions variables arrays modulo operator if statements, booleans, comparisons loops: while and for

Pace University. Fundamental Concepts of CS121 1

Branching and Boolean Expressions

CS251L REVIEW Derek Trumbo UNM

S.E. Sem. III [CMPN] Object Oriented Programming Methodology

Building Java Programs. Introduction to Programming and Simple Java Programs

COMP-202: Foundations of Programming

Introduction to Programming (Java) 2/12

Review for Test 1 (Chapter 1-5)

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

Java Classes & Primitive Types

CS313D: ADVANCED PROGRAMMING LANGUAGE

( &% class MyClass { }

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

Vendor: Oracle. Exam Code: 1Z Exam Name: Java SE 8 Programmer. Version: Demo

CMPS 134: Computer Science I Fall 2011 Test #1 October 5 Name Dr. McCloskey

Lecture 2, September 4

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

Java Classes & Primitive Types

Java in 21 minutes. Hello world. hello world. exceptions. basic data types. constructors. classes & objects I/O. program structure.

Computer Components. Software{ User Programs. Operating System. Hardware

Software Practice 1 Basic Grammar

CS2141 Software Development using C/C++ C++ Basics

Object Oriented Programming and Design in Java. Session 2 Instructor: Bert Huang

Java Intro 3. Java Intro 3. Class Libraries and the Java API. Outline

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

Lecture 1 - Introduction (Class Notes)

CIS3023: Programming Fundamentals for CIS Majors II Summer 2010

THE CONCEPT OF OBJECT

CS 106 Introduction to Computer Science I

Java language. Part 1. Java fundamentals. Yevhen Berkunskyi, NUoS

Praktische Softwaretechnologie

Transcription:

Getting started with Java by Vlad Costel Ungureanu for Learn Stuff

Programming Languages A programming language is a formal constructed language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs to control the behavior of a machine or to express algorithms. (Wikipedia) A specific series of instructions that are interpreted by the machine to produce predictable, repeatable results in a controlled environment. (Business) A sequence of code that produces the expected results. (Programmer) 2

The Java Programming Language Oracle Fast Secure Object oriented Cross platform Over 3 Billion devices Desktop, web and mobile Business accepted frameworks 3

The Java Programming Language public class MyFirstClass { // member data declaration public static void main(string[] args) { } System.out.println("Hello, world!"); // without classes (!) all operations go here // with classes (!) class instantiation and method calls go here // method declaration } 4

5

File Structure Source: HelloWorld.java Compile: javac HelloWorld.java HelloWorld.class Execution: java HelloWorld 6

Syntax Key words: class, new, interface, abstract, public, static, final, private, protected, if, then, else, for, while, break. Literals: Hello World, 10, 010, 0xA, 0b11, 12.3, 12.3d, 12.3f, 12e3, 123L, true, false, null. Separators: ( ) { } [ ] ;,. Operators: + - / % && & >> 7

Data types Primitives: Arithmetic: byte (1), short (2), int (4), long (8) Real: float (4), double (8) Character: char (2) Boolean: (true, false) Reference types: Classes Interfaces Annotations Enum (erations) 8

Variables/Fields A primitive bite: byte a; An primitive integer with the default value of 100 int somevalue= 100; A primitive double constat with the value of PI final double PI = 3.14; A primitive long with a default value long alongnumber= 12345678L; A character array String somestring= any string"; 9

Variables/Fields public class MyFirstClass { int a; // a is a class variable public void asimplemethod(int b) { // b is a method parameter a = b; int c = 10;// c is a variable only visible in the method for(int d=0; d < 10; d++) { // d is a variable visible only in the flow control structure } // control structure end here } // method ends here } // class ends here 10

Arrays Declaration: int[] a; byte b[]; Instantiation: a = new int[10]; char c = new char[100]; Initialization: String colors[] = { Red", Blue, Green }; String colors = new String[]{ Orange", Yellow"}; Size: a.length 11

Arrays Declaration int[][] atwodimensionalarray = new int[10][20]; int[][][] athreedimensionalarray = new int[10][20][30]; Accessing an element: atwodimensionalarray[0][0] = 1; Making a copy System.arrayCopy; 12

Control Structures Simple Logical control: if (boolean value) { // instructions else { } // other instructions Multiple cases logical control: switch (value) { } case 1: result= One"; // instructions break; case 2: result = Two"; // instructions break; default: result = Unknown"; break; 13

Control Structures For for (int i = initial_size; i < max_value; i++){ // instructions } While while (boolean value){ // instructions } Do-while do { // instructions } while (boolean value) 14

Control Structures Exception control: try { // instructions catch (Exception e){ // other instructions } finally { // some other instructions // usually free resources } 15

Control Structures Break Continue Return Throw 16

Equality Arrays: int a[] = {1, 2}; int b[] = {1, 2}; a == b - false a.equals(b) - false Arrays.equals(a,b) - true Characters String s1 = new String("abc"); String s2 = new String("abc"); s1 == s2 - false s1.equals(s2) - true s1.compareto(s2) - 0 17

Assignments For an array of elements count the number of occurrences of a given element. (experiment with arrays of numbers and strings) Read an array and a matrix from the keyboard Use the Random class to generate elements for a matrix for which you read the length and height from the keyboard For two given matrices implement: matrix addition, matrix scalar multiplication and matrix multiplication Generate a random array of numbers and search for a specific one. If you find it then use a named break to exit the loop 18

THANK YOU! Vlad Costel Ungureanu ungureanu_vlad_costel@yahoo.com This is a free course from LearnStuff.ro not for commercial use 19