An Introduction to Java – Part I, language basics

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
Shlomo Hershkop1 Introduction to java Class 1 Fall 2003 Shlomo Hershkop.
Hello, world! Dissect HelloWorld.java Compile it Run it.
Programming in Java; Instructor:Moorthy Introduction, Objects, Classes, Libraries1 Programming in Java Introduction.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
CSC Java Programming, Fall, 2008 Week 2: Java Data Types, Control Constructs, and their C++ counterparts, September 4.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
CS591x A very brief introduction to Java. Java Developed by Sun Microsystems was intended a language for embedded applications became a general purpose.
More arrays Primitive vs. reference parameters. Arrays as parameters to functions.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Chapter 2: Java Fundamentals
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Mixing integer and floating point numbers in an arithmetic operation.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Java methods Methods break down large problems into smaller ones Your program may call the same method many times saves writing and maintaining same code.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Java Nuts and Bolts Variables and Data Types Operators Expressions Control Flow Statements Arrays and Strings.
Developed at Sun Microsystems in 1991 James Gosling, initially named “OAK” Formally announced java in 1995 Object oriented and cant write procedural.
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
CSCI S-1 Section 4. Deadlines for Homework 2 Problems 1-8 in Parts C and D – Friday, July 3, 17:00 EST Parts E and F – Tuesday, July 7, 17:00 EST.
Java Part I By Wen Fei, HAO. Program Structure public class ClassName { public static void main(String[] args) { program statements } user defined methods.
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Object Oriented Programming Lecture 2: BallWorld.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Basic concepts of C++ Presented by Prof. Satyajit De
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Crash course in the Java Programming Language
Chapter No. : 1 Introduction to Java.
Yanal Alahmad Java Workshop Yanal Alahmad
Primitive Data, Variables, Loops (Maybe)
Intro to Java.
Engineering Innovation Center
An Introduction to Java – Part I
Chapter 2.
Introduction to Programming in Java
Starting JavaProgramming
Introduction to Java Programming
Java so far Week 7.
Chapter 2: Java Fundamentals
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
elementary programming
Java Programming Review 1
Comparing Python and Java
Agenda Types and identifiers Practice Assignment Keywords in Java
Introduction to java Part I By Shenglan Zhang.
Variables and Constants
Presentation transcript:

An Introduction to Java – Part I, language basics By: Mihir Shah

Overview Basic Structrue Source code, Compilation, Execution Data Types, Operators, Strings Variables If statements, Loops Arrays

Basic Structure The basic structure of Java programs: public class ClassName { public static void main(String[] args) { program statements } User defined methods Explanations: 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.

Source code, Compilation, Execution Source code should be same name as the public class File must be saved with the extension .java Ex. Public class TestFile File name: TestFile.java To run the command type java then the file name Ex. Java TestFile

Data Types, Operators, Strings Integers: int, short, long, byte Floating-Point Types: float, double The Character Type: char The Boolean Type: boolean (values: true, false) Operators Arithmetic Operators: +, -, *, /, % Relational Operators: ==, !=, <, >, <=, >= Logical Operators: &&, ||, ! Strings Enclosed in “” Concatenate with + Int Length();

Variables Need to be declared Ex: Int n = 5; System.out.println(n); Output: 5 String s = “Hello”; String t = “World”; System.out.println(s+“ ”+t); Output: Hello World

If statements, Loops If statements While loop For Loops if(…) { … } else { … } While loop while(….) { … } For Loops for(initialization; condition; update) { … }

Arrays Standard class in java Defined by specifying the array type followed by [] Create objects with operator new Array count is from 0 to length-1 arrayName.length Examples int n = 5; int[] numbers = new int[n]; for(int i=0; i<numbers.length; i++) numbers[i]=n-i; for(int i=0; i<numbers.length; i++) system.out.println(numbers[i]);