Basic Data Structures in Java (c) IDMS/SQL News

Slides:



Advertisements
Similar presentations
What Is Java? The name Java is a trademark of Sun Microsystems
Advertisements

Review pages for the AP CS Exam
wwwcsif.cs.ucdavis.edu/~jacksoni
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.
Final and Abstract Classes
Basic Java Constructs and Data Types – Nuts and Bolts
1 Exceptions: An OO Way for Handling Errors Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software.
1 Applets Programming Enabling Application Delivery Via the Web.
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
A Programmer's Introduction to Java - from a S/370 user (c) IDMS/SQL News
4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
3 Copyright © 2005, Oracle. All rights reserved. Basic Java Syntax and Coding Conventions.
11 Copyright © 2005, Oracle. All rights reserved. Using Arrays and Collections.
1 Copyright © 2005, Oracle. All rights reserved. Introducing the Java and Oracle Platforms.
7 Copyright © 2005, Oracle. All rights reserved. Creating Classes and Objects.
8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages.
10 Copyright © 2005, Oracle. All rights reserved. Reusing Code with Inheritance and Polymorphism.
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
1 G54PRG Programming Lecture 1 Amadeo Ascó Adam Moore G54PRG Programming Lecture 1 Amadeo Ascó 3 Java Programming Language.
© Vinny Cahill 1 Writing a Program in Java. © Vinny Cahill 2 The Hello World Program l Want to write a program to print a message on the screen.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Procedural Programming in C# Chapters Objectives You will be able to: Describe the most important data types available in C#. Read numeric values.
Programming Methodology (1). public class Hello { public static void main(String[] args) { System.out.println("Hello world"); } } Hello world.
1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual.
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Purpose : To convert this string to a new character array. Return Type : char[ ] Parameters : none Declaration : public char[ ] toCharArray() Returns.
1 Variables and Data Types. 2 Variable Definition a location in memory, referenced by a name (identifier), where data of a given type can be stored, changed,
CSci 1130 Intro to Programming in Java
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
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 of selection structures
COMP 14 Introduction to Programming
Introduction to Programming G51PRG University of Nottingham Revision 1
DATA TYPES, VARIABLES, ARITHMETIC. Variables A variable is a “named container” that holds a value. A name for a spot in the computer’s memory This value.
Today’s lecture Review of Chapter 1 Go over homework exercises for chapter 1.
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
1 pritisajja.info Unlocking the World of Java Programming….. Priti Srinivas Sajja February, 2014 Visit pritisajja.info for detail Future Technology for.
Lecture 1 Introduction to Java Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Object Oriented Programming in JAVA
1 Java Basics. 2 Compiling A “compiler” is a program that translates from one language to another Typically from easy-to-read to fast-to-run e.g. from.
Java Syntax Primitive data types Operators Control statements.
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
Hello, world! Dissect HelloWorld.java Compile it Run it.
A Short Introduction to JAVA
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
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.
The Java Programming Language
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
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.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Java development environment and Review of Java. Eclipse TM Intergrated Development Environment (IDE) Running Eclipse: Warning: Never check the “Use this.
Fall 2015CISC124 - Prof. McLeod1 CISC124 Have you filled out the lab section survey? (As of last night 54 left to fill out the survey.) TA names have been.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Copyright Curt Hill Variables What are they? Why do we need them?
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
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.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
OOP Basics Classes & Methods (c) IDMS/SQL News
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Chapter No. : 1 Introduction to Java.
Internet and Java Foundations, Programming and Practice
Data types and variables
Chapter 1: Computer Systems
Chapter 2: Java Fundamentals
Presentation transcript:

Basic Data Structures in Java (c) IDMS/SQL News

Java - Chapter 1 (c) 2 Language Features ñ Object Oriented ñ Class – the basic entity of OOP ñ Object – instance of a class ñ Methods – process code within class ñ Interpreted Lang – Bytecode ñ Builtin support for threading (concurrent execution different pieces of code)

Java - Chapter 1 (c) 3 public class HelloWorld { public static void main(String arguments[]) { System.out.println(Hello World"); } } HelloWorld Again Note: 1. Any main program must have a main method and it must be declared static. No instance is required. JVM can directly run this. 2. If a class has no main method, then the only way to use it is to call from another class. In practice, many classes are defined like this... See next page

Java - Chapter 1 (c) 4 /** * This is the template for a class */ public class test{ // instance variables - private int x; /** Constructor for objects of class test */ public test() {// initialise instance variables x = 10;} /** An example of a method – */ public int sampleMethod(int y) {// put your code here return x + y; } }

Java - Chapter 1 (c) 5 Instances We have a class test and a method sampleMethod How do we use them from another program? test test1; // declare a new variable test1 of type test test1 of type test test1 = new test(); int xyz1; xyz1 = test1.sampleMethod(30);//we get 40 This is the essence of OO programming.

Java - Chapter 1 (c) 6 OO features / conventions ñ Class name starts with Upper case ñ Variables start with lowercase, each word with uppercase ñ Method – lowercase ñ Methods must return something else declared as void

Java - Chapter 1 (c) 7 Capitalization Java is picky about capitalization; System.out.println() vs. system.out.println() are not the same HelloWorld and helloworld are not the same!

Java - Chapter 1 (c) 8 Datatypes – 8 of them ñ boolean: true or false. 1 bit size ñ char: Unicode character. 16 bits. ñ byte: very small integer number; , 8 bits ñ short: a smallish integer number, -32,768 to 32,767 ñ int: normal integer, 32 bits, -2,147,483,648 to 2,147,483,647 ñ long: a really big 64 bit integer, to ñ float: 32 bit floating point number, E+38 to E+38 ñ double: 64 bit long floating point number, ñ good for -E+308 to +E+308 and about twice the number of digits of precision as a float

Java - Chapter 1 (c) 9 ñ Variable names must start with a letter or an underscore character, _ ñ Cannot start with a number. Declaring Variables ñ Variables are declared in the C style; the type first, followed by the variables being declared int inputCount; int currentCount23, finalValue; InterCap Style

Java - Chapter 1 (c) types of variable declarations instance, class and local variables class Variables1 { double salary = ;// instance variable static int counter1; // class variable public static void main (String args[]){ int temp1 = 0; // local variable defined inside a method System.out.println ("counter1=" + counter1 + " temp1=" + temp1 ); } // end of method main } // end of class Variables1

Java - Chapter 1 (c) 11 Initialize Double initialSpeed =10.0, finalSpeed=60.0, currentSpeed = 0.0; char endChar = a; Note: Instance and static(=class) variables will be initialized to default values. Local variable will NOT be initialized automatically. You can initialize variables in a declaration.

Java - Chapter 1 (c) 12 Scope of a Variable ñ IBM doc says variable scope can be confusing in Java ñ An instance method has access to all (instance, class and local variables) ñ A class method (= defined static) has access to only class variables and local variables ñ Local variables are limited to within a method. Outside the method they do not exist.

Java - Chapter 1 (c) 13 Assignments ñ Similar to any other language… double currentSpeed = 0.0; int clock = 0; currentSpeed = currentSpeed + 1.0; clock++; // known as postincrement // clock = clock + 1; // same as above A number like is treated as double! float price1; price1 = 14.65; Gives compile error price1 = 14.65f; // ok now

Java - Chapter 1 (c) 14 if.. else if (booleanTest) { // code for Value is true. } else { // code for Value is false.} eg: int weight1 = 100, weight2=200; if ( weight1 == weight2) {System.out.print(weight1 equals weight2 ");} else {System.out.print(weight1 not equals weight2 ");} Note the difference between the equality operator ( == ) and the assignment operator ( = ) Note!

Java - Chapter 1 (c) 15 String Not a basic data type! Used as if it is ! String in Java is implemented as a class Note: not string, capital S is required String str1 = new String(string value); String str2 = string value; Char char1 = A; // String and char are not the same! More on String later

Java - Chapter 1 (c) 16 Final Variables (=constants) ñ A final variable is one that cannot be changed. Any attempt to change it, will result in a compile-time error. This is done with the keyword final in the declaration. ñ Typically they are in CAPITAL letters double final PI = ; int final SPEED_LIMIT = 70;

Java - Chapter 1 (c) 17 Other Syntax ñ while ñ do... while ñ for... loop ñ Most are simple and straightforward Switch – will be discussed later All others see syntax page at the end...

Java - Chapter 1 (c) 18 Arrays datatype arrayName [] = new datatype[25]; or datatype [] arrayName = new datatype[25]; eg: String ErrorCode [] = new String[50]; The first/last elements are ErrorCode[0]... ErrorCode[49]

Java - Chapter 1 (c) 19 Initializing Arrays Method 1 String names[]; Names = new String[3]; Names[0] = Ada; Names[1] = Byron; Names[2] = Napolean; Method 2 String names[] = {Ada; Byron; Napolean}; Here definition and initialize are done at once.

Java - Chapter 1 (c) 20 Hello World Again In the HelloWorld public static void main (String args[]) {...} The main method takes an array as input arguments. If I say Java HelloWorld John David These names are passed to args[0], args[1]... Here follows the modified program

Java - Chapter 1 (c) 21 Example class Hello2 { public static void main (String args[]) { int i; if (args.length == 0) System.out.println("Hello Nobody "); else System.out.println("Arguments length= " + args.length); for (i=0; i < args.length; i = i+1) { System.out.println("Hello " + args[i]); } } Try Java Hello2 * What do you get?

Java - Chapter 1 (c) 22 Javadoc – part of JSDK Input is Java source Output – html files with help information C:\tvg\JCourse1>Javadoc TestGreeting.java Loading source file TestGreeting.java... Constructing Javadoc information... Standard Doclet version 1.4.2_03 Generating constant-values.html... Building tree for all the packages and classes... Building index for all the packages and classes... Generating overview-tree.html... Generating index-all.html... Generating deprecated-list.html... Building index for all classes... Generating allclasses-frame.html... Generating allclasses-noframe.html... Generating index.html...Generating packages.html... Generating TestGreeting.html...Generating package-list... Generating help-doc.html...

Java - Chapter 1 (c) 23 Java Buzzwords ñ Java2 Platforms ñ - Standard Edition J2SE ñ - Enterprise Edition – J2EE ñ - Micro Edition – J2ME (PDA) Every Platform has ñ Run time – JRE (can be shipped with application) ñ Dev Kit – JDK (includes JRE) Enterprise Information System ñ Servlet, JSP, J2EE Client, Applet...Application Server ñ JDBC, Beans, JavaBeans, EJB...