BASIC JAVA. Hello World n // Hello world program public class MyFirstJavaProgram { public static void main(String args[]) { char c = 'H'; String s =

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Primitives in Java Java has eight primitive types –boolean –integral types: signed: long, int, short, byte unsigned: char –floating point types: double,
CMT Programming Software Applications
Constants Variables change, constants don't final = ; final double PI = ; … area = radius * radius * PI; see Liang, p. 32 for full code.
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
Java Intro. Strings “This is a string.” –Enclosed in double quotes “This is “ + “another “ + “string” –+ concatenates strings “This is “ “ string”
1 Data types, operations, and expressions Overview l Format of a Java Application l Primitive Data Types l Variable Declaration l Arithmetic Operations.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
COMP 14: I/O and Boolean Expressions May 24, 2000 Nick Vallidis.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
1 Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class:
Java Fundamentals Expanded SE1021 Dr. Mark L. Hornick 1.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
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 means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
JAVA—Bitwise. Compiling/Executing a Java Application Source Code Java Compiler ByteCode > Java Interpreter Machine Code >
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
Chapter 2: Java Fundamentals
Java Simple Types CSIS 3701: Advanced Object Oriented Programming.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
Sun Certified Java Programmer, ©2004 Gary Lance, Chapter 3, page 1 Sun Certified Java 1.4 Programmer Chapter 3 Notes Gary Lance
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs -
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Chapter 2 Variables.
Chapter 2 topics Concept # on Java Subset Required for AP Exam print and println10. Testing of output is restricted to System.out.print and System.out.println.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
COM S 207 Literal, Operator, and Expression Instructor: Ying Cai Department of Computer Science Iowa State University
Operators in JAVA. Operator An operator is a symbol that operates on one or more arguments to produce a result. Java provides a rich set of operators.
“Great leaders are never satisfied with current levels of performance. They are restlessly driven by possibilities and potential achievements.” – Donna.
Java and C++ Transitioning. A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello.
Programming in java Lecture-3 (a). Java Data Type TypeDescription byte8 bit signed integer short16 but signed integer int32 bit signed integer long64.
Developed at Sun Microsystems in 1991 James Gosling, initially named “OAK” Formally announced java in 1995 Object oriented and cant write procedural.
1.2 Primitive Data Types and Variables
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.
Computer Programming with Java Chapter 2 Primitive Types, Assignment, and Expressions.
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
© 2007 Lawrenceville Press Slide 1 Chapter 4 Review Assignment Statement An assignment statement gives a value to a variable. Assignment can take several.
Data Types References:  Data Type:  In computer science and computer programming, a data type or simply type is a.
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.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Review by Mr. Maasz, Summary of Chapter 2: Starting Out with Java.
Lecture 2: Data Types, Variables, Operators, and Expressions
An Introduction to Java – Part I
Methods and Parameters
Chapter 2.
Introduction to Programming in Java
Escape Sequences What if we wanted to print the quote character?
5 Variables, Data Types.
Introduction to Java Programming
An Introduction to Java – Part I, language basics
Chapter 2: Java Fundamentals
Java Intro.
Recap Week 2 and 3.
Java Programming Review 1
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Java’s Central Casting
Names of variables, functions, classes
Agenda Types and identifiers Practice Assignment Keywords in Java
Presentation transcript:

BASIC JAVA

Hello World

n // Hello world program public class MyFirstJavaProgram { public static void main(String args[]) { char c = 'H'; String s = c + "ello \nWorl"; int last = 'd'; s = s + (char)last; System.out.println(s); } }

Java Comments n // for the java one liner n /* for a multi-line n comment */ n /** for a javadoc comment n */

Simple output n System.out.println(“Hello World”); n System.out.print(“No new line”); n System.out.print(6); n System.out.print(true); n System.out.println(6+10); displays 16 n System.out.println(“”+6+10); displays 610

Primitive Types n byte there are no byte literals 8 bits n short there are no short literals 16 bits n int literals(23, -98, 077, 0xAF) 32 bits n long lierals(23L, -9L) 64 bits n float literals (34F, -4.5f) 32 bits n double literals (34.0, 5e2,.4) 64 bits n char literals (‘A’, ‘\n’, ‘\377’, ‘\u0041’) 16 bits unsigned n boolean literals (true, false) 16 bits

Assignment and types n short m = 5; // int to short is ok if it fits n short m = ; // compiler error int to short not ok n float m = 50.0; // compiler error need to cast double to float n float m = (float)50.0; // ok cast the double to float n byte b = 4L; // compiler error cast to byte

More on Assignment and types n double m = 6; // int to double is fine n int m = 6.0; // compiler error need to cast the double to int n int m = (int)6.0; // works fine n double c = ‘\n’; // ok but strange n char c = ‘A’ + 1; // c now holds ‘B’ n System.out.println(‘A’ + 1); // displays 66 n System.out.println((char)(‘A’ + 1)); // displays B

The String Type n String s = "Peanut"; // or, see below n String s = new String(“Peanut”); // same as above n Use concatenation for long strings n System.out.println("This is " + "a very long string"); n Many string operations exist n System.out.println(s.length()); n System.out.println("Hello".length());