Sridhar Narayan narayans@uncw.edu Java Basics Sridhar Narayan narayans@uncw.edu.

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.
Introduction to Programming G51PRG University of Nottingham Revision 1
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
CS 225 Java Review. Java Applications A java application consists of one or more classes –Each class is in a separate file –Use the main class to start.
DAT602 Database Application Development Lecture 5 JAVA Review.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
Java Programming Presented by Daniel Rosenthal Friday, November 30 th, 2007.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
Introduction to Java Java Translation Program Structure
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6: Transition to Java Programming with Alice and Java First Edition.
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.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Developed at Sun Microsystems in 1991 James Gosling, initially named “OAK” Formally announced java in 1995 Object oriented and cant write procedural.
By Mr. Muhammad Pervez Akhtar
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
1 2. Program Construction in Java. 01 Java basics.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
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.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
C++ Lesson 1.
Information and Computer Sciences University of Hawaii, Manoa
Basic Concepts: computer, program, programming …
Lecture 2 D&D Chapter 2 & Intro to Eclipse IDE Date.
Objects as a programming concept
JAVA MULTIPLE CHOICE QUESTION.
Intro to ETEC Java.
Lecture 5: Some more Java!
Java for Android is specific
Data types and variables
Java package classes Java package classes.
Road Map Introduction to object oriented programming. Classes
Generics, Lambdas, Reflections
C Basics.
Java Virtual Machine Complete subject details are available at:
FUNDAMENTALS OF JAVA.
Engineering Innovation Center
Tutorial C#.
Introduction to Programming in Java
Arrays, For loop While loop Do while loop
Principles of Computer Programming (using Java) Chapter 2, Part 1
An Introduction to Java – Part I, language basics
IFS410 Advanced Analysis and Design
Unit 6 - Variables - Fundamental Data Types
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Recap Week 2 and 3.
Programs and Classes A program is made up from classes
CISC124 Labs start this week in JEFF 155. Fall 2018
elementary programming
Java Programming Review 1
Arrays in Java.
Chap 2. Identifiers, Keywords, and Types
Comparing Python and Java
Presentation transcript:

Sridhar Narayan narayans@uncw.edu Java Basics Sridhar Narayan narayans@uncw.edu

Java programs A Java program is a collection of classes Each class is a generic description (template) of an object being modeled Each class describes Properties of the object being modeled, i.e. structure of the object Ways in which one can interact with the object, i.e. behavior of the object. These are called methods. The main method in a class is where execution begins when that class is run

Java methods Each method is a collection of statements Each statement is terminated by a semi-colon Java is case sensitive Each variable must be declared before use int, float, double, char, boolean are primitive types Every Java class is a non-primitive type Java employs block scoping Each pair of {} defines a block Variables declared within a block are visible only within that block

Java comments // single line comment /* multi-line comment */ /** used for Java docs, similar to Python docstring comments **/

Java types Unlike Python, Java does not infer types. Types are explicitly declared int x = 10; boolean p = false; Java is strongly typed. float x = 2.5; //error, since 2.5 is a double float x = 2.5f; // ok Statically type checked All type errors are caught during compilation

Compiled and then interpreted The java compiler first compiles Java source code (.java files) into Java byte code (.class files) The byte code is then interpreted by the Java VM (virtual machine) In theory, once compiled, Java code can be run on any platform for which a JVM exists.

Iterative constructs for(int i=0; i < 10; i++) { //do something } while (condition is true) { //do something } do { //something } while (condition is true);

Selection if- else if - else Use parenthesis for conditions: if (a > b) { //do something } else if (c > d) { //do something else } else { //do a third thing } && (and), || (or) if (a > b && c < d || a == b) { //do something }

Arrays int x; //declare x as an integer. x is a primitive int [] data; // declare data as a reference to an array of integers. No array exists at this point data = new int[100]; //instantiate and assign an array of 100 integers to data Declaration and instantiation can be combined int [] data = new int[100]; Array index values start with 0. For example above, valid references are data[0]…data[99]