CSE 252 Principles of Programming Languages Lab. Section

Slides:



Advertisements
Similar presentations
Introduction to Programming G51PRG University of Nottingham Revision 1
Advertisements

Date: Subject:Distributed Data Processing Name:Maria Br ü ckner.
Lab Information Security Using Java (Review) Lab#0 Omaima Al-Matrafi.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Lab#1 (14/3/1431h) Introduction To java programming cs425
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
Object Orientated Programming
Introduction to Java Programming
Some basic I/O.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
Introduction to Java.
Introduction to Java Programming Language Junji Zhi University of Toronto 1.
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
Programming in Java; Instructor:Moorthy Introduction, Objects, Classes, Libraries1 Programming in Java Introduction.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Introducing Java.
CSC3170 Introduction to Database Systems
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.
Session One Introduction. Personal Introduction Role of programmers Robot Examination HUD & HID Uploading Code.
1 Comp 104: Operating Systems Concepts Java Development and Run-Time Store Organisation.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Introduction to Computer Systems and the Java Programming Language.
POS 406 Java Technology And Beginning Java Code
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.
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.
Spring 09- ICE0124 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 2.
The basics of the array data structure. Storing information Computer programs (and humans) cannot operate without information. Example: The array data.
Introduction to java Prepared By:-Pragnesh Patel Lect. In Computer Dept. NSIT,Jetalpur 1.
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 Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Applied Computing Technology Laboratory QuickStart C# Learning to Program in C# Amy Roberge & John Linehan November 7, 2005.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
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.
Programming in java Lecture-2 Java Introduction. Platform Computing platform include hardware and software framework, this combination allows software.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and web applications Very rich GUI libraries Portability (machine independence) A real Object.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
WEEK 2 Introduction to Java II CSE 252 Principles of Programming Languages LAB SECTION.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
CSCI 212 Object-Oriented Programming in Java. Prerequisite: CSCI 111 variable assignment statement while loop for loop post-increment (i++) strong typing.
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
1 Introduction Read D&D Sec 1.8; Sec 1.13 THE Java tutorial -
Java Computer Industry Lab. 1 Programming Java Java Basics Incheon Paik.
OOP Basics Classes & Methods (c) IDMS/SQL News
C is a high level language (HLL)
Object Oriented Programming Lecture 2: BallWorld.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
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.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Introduction CMSC 202 Fall Instructors Mr. Ryan Bergeron – Lecture Section 01 Tues/Thu 1:00 – 2:15 am, Sondheim 111 – Lecture Section 04 Tues/Thu.
JAVA MULTIPLE CHOICE QUESTION.
Intro to ETEC Java.
Yanal Alahmad Java Workshop Yanal Alahmad
Internet and Java Foundations, Programming and Practice
Website: SSD1 Unit 2 Intro to Java Presentation 2.3 Website:
An Introduction to Java – Part I, language basics
(Computer fundamental Lab)
Chap 1. Getting Started Objectives
Computer Programming-1 CSC 111
Introduction to java Part I By Shenglan Zhang.
Review of Java Fundamentals
Presentation transcript:

CSE 252 Principles of Programming Languages Lab. Section WEEK 1 INTRODUCTION TO JAVA by: R.A. Kemal Çağrı Serdaroğlu

WEEK 1 What is Java Programming Language? Java Programming Basics: Java vs C. Using Classes at Java API.

What is Java Programming Language? Java is an high level programming language in the tradition of C and C++. Java is a platform independent programming language. Platform independence means any program written in a language can run all operating system platforms. Java is an OOP(Object Oriented Programming) Language. OOP Languages are based on objects and classes.

JVM (Java Virtual Machine) The compilation phase of Java is different than C’s. Virtual Machines are hypothetical computer platforms e.g. a design for a computer that does not really exist on any actual computer. JVM is a kind of VM that is an implementation environment of a Java Application. Java is a platform independent language so it needs JVM. JRE(Java Runtime Environment) is an emulation tool that creates a JVM environment that can execute Java programs.

JRE and JVM For running an application written in Java Language, the JRE must be installed on any computer. JRE and JVM are used for running a java program. Programs intended to run on a JVM must be compiled into a standardized portable binary format, which typically comes in the form of .class files.

JDK(Java Development Kit) SDK(Software Development Kit)s are typical set of development tools for creation of applications. JDK is an extension of a SDK which can be used for creation of java applications. JDK is used for creating .class files from .java source files. So it must be installed at a computer for creating java applications.

Basics of a Typical Java Environment Java programs normally undergo five phases - Edit (JDK):Programmer writes program(.java files) and stores program on disk - Compile(JDK):Compiler creates bytecodes (.class files) from program(.java files) - Load(JVM):Class loader stores bytecodes in memory - Verify(JVM) : Verifier ensures bytecodes do not violate security requirements -Execute(JVM):Interpreter translates bytecodes into machine language

Learning Java Two groups for learning for java. Basic Java Syntax: Variables – Loops – Conditional Statements – Class – Interface – Inheritence – Polymorphism etc… Java API (Application Programming Interface): set of classes and interfaces that comes with the JDK. Java API is the collection of libraries(packages) for java program development. Example of libraries at Java API: File IO, Swing, Math… etc You will learn how to use Java API for developing a java application with the help of Java Syntax tools and Object Oriented Programming concepts such as Classes, Inheritence and Polymorphism.

Java Programming Basics Java is an OOP (Object Oriented Programming) Language.OOP languages uses objects consisting of data fields(variables) and methods(funcitons) together with their interactions. Learning OOP concepts are not a straight-forward process and a new concept for a student who knows C language. C is a functional programming language. OOP has new programming techniques such as encapsulation, inheritence and polymorphism.

Java Programming Basics (4) Java API is an important source for developing programs. Java API consists of basic classes and the elements of JavaAPI have some OOP concepts.Hence, the basic usage of Java API requires the basic information of OOP. The developers must know OOP concepts for program development in Java. The basic learning of Java starts at learning OOP concepts !!!

Java Programming Basics Every programming languages has a syntax.. Java has a C-like syntax and there will be similarities with C. Of course there will be differences between C language.

Java vs C (1) Programming Language Structure C Java Type of language Functional, not OOP OOP Basic programming str. functions. objects. Main method int main(){ … return 0; } public class ExampleClass{ public static void main(String[] args){ It is required to define a class.

Java vs C Programming Language Structure C Java File names No constrai nt, ends with .c Ends with .java File name must be the name with class name. File Names Example: ExampleClass.java: public class ExampleClass{ public static void main(String[] args){ }

Java vs C Programming Language Structures C Java Variable declaration At the beginning of the block Before using it int main(void){ int a,b; a=5; b=3; return 0; } public class ExampleClass{ public static void main(String[] args){ int a; int b;

Java vs C Programming Language Structure C Java Accessing a library #include <stdio.h> import java.io Memory address pointer Reference

Java vs C (2) HelloWorld Application & User Interaction C Java #include<stdio. h> int main(void) {    printf("Hell o\n");    return 0; } public class HelloWorld {    public static void main(String[] args) {         System.out.println("Hello");    } }

Java vs C (2) Hello World Application and User Interaction C Java printf (Using not formatted) (1) int a; a=3; printf(“A is %d”,a); System.out.print(“A is ” + a);

Java vs C (2) HelloWorld Application and User Interaction C Java a=3; printf(Usin g not formatted) (2) int a; printf(“A is %d\n”,a); a=3; System.out.print(“A is ” + a + “\n”); ----------------- System.out.println(“A is ” + a);

Java vs C (2) Hello World Application and User Interaction C Java scanf #include <stdio.h> int main(void){ int num; scanf(“%d”,&n um); printf(“%d”,n um); } import java.util.Scanner; public class UserInteraction { public static void main(String[] args) { Scanner userIn = new Scanner(System.in); int num=userIn.nextInt(); System.out.println(num);

Java vs C (2) HelloWorld Application and User Interaction C Java C - function s int max(int a,int b){} ----------------- Example: #include <stdio.h> int max(int a,int b){ return a>b?a:b; } int main(){ int a=max(4,15); printf("%d\n",a); return 0; static int max(int a,int b){} ------- public class FunctionExample { public static void main(String[] args){ System.out.println(a); static int max(int a,int b){ Java vs C (2) HelloWorld Application and User Interaction

Java vs C C Java integer types short 16 bit. int usually 32 bit 2's complement; long usually 32 bit 2's complement int is 32 bit 2's complement; long is 64 bit 2's complement floating point types float usually 32 bit; double usually 64 bit float is 32 bit(same) double is 64 bit (same) boolean type use int: 0 for false, nonzero for true boolean is its own type - stores value true or false character type char is usually 8 bit ASCII ------------- char c; c=’a’; char is 16 bit UNICODE ------------------------

Java vs C Comments Comments are same !!!

Java vs C If-Switch Statements: C Java if(1) if(1){} if(1){} is not accepted if(true){} is used if(2) if(x==5){} İf(x==5){} if(3) if(x==5 && x!=6 || x<7){} if(x==5 && x!==6 || x<7){} if(4) No boolean expression boolean f=true; if(f){ System.out.println(“true is “ + f); }

Java vs C Loops C Java For loop int i; for(i=0;i<N;i++){} for(int i=0;i<N;i++){} While loop (1) while(1){} While(1){} is not accepted!! while(true){} -------------------------- boolean t=true; while(t){}

Java vs C Loops C Java While loop(2) int i=3; while(i<5){ i++; } break while(1){ if(x==0){break;} while(true){ continue int i=10; while(i>0){ if(i==5){continue;} i--;

Using Classes at Java API Look at this example: import java.util.Scanner;// --- (1) public class UserInteraction { public static void main(String[] args) { Scanner userIn = new Scanner(System.in); // --- (2) int num=userIn.nextInt();// -- (3) System.out.println(num); }

Using Classes at Java API (1) import java.util.Scanner; Scanner is a class which is existed in Java API and it is at java.util package under Java API. In our program, we want to use it so we must import this class. import java.util.*; If we want to use more classes at java.util package, we will use the statement above.

Using Classes at Java API (2) Scanner userIn = new Scanner(System.in); Here, we want to use a Scanner object in our program. object  the meaningful structure which has behaviours and variables for a program. Objects are allocated at the memory.We must create objects of the classes in Java API to have functionalities. class  programming structure which defines the behaviour and variable types of an object. For Java API classes, we don’t know the structure of a class. They serve functionalities for our programs so we use instances of them.

Using Classes at Java API (2) Scanner userIn = new Scanner(System.in); new Scanner(System.in)  creates an object with Scanner type. Scanner is a class. Memory is allocated for storing fields at Scanner class. If this line will be implemented without an assign operation, the program cannot access fields or methods of the object. Scanner userIn = new Scanner(System.in); This assignment operation is used for accessing object after creation of it. userIn is the accessor for created Scanner object and we can use it for accessing this object’s variables and methods.

Using Classes at Java API (3) int num=userIn.nextInt(); userIn is the accessor for our new created object. Here we want to use object’s nextInt() method. userIn is here a reference type and it is like a pointer at C. However, reference types have no pointer arithmetic and they access memory safely.

Primitive Types Primitive types at Java are : int, short, long, boolean, char, float, double Example: int a; // (1) a=500; // Assigning to a primitive type (2)

Reference Types Other types are in java are reference types. Reference types look like a pointer. You cannot access any other memory address using pointer arithmetic. In Java, objects are accessible with a reference type. Arrays are too reference types.

Reference Type Example(1) String s=“Kemal”; // alias to String s=new String(“Kemal”);

Reference Type Example(2) String s=“Kemal”; // (1) s=“Ali”; //(2)

Reference Type Example(3) Scanner s=new Scanner(System.in);// object creation (1) Scanner t=new Scaner(System.in); // object creation(2)

Reference Type Examples(4) Scanner s=new Scanner(System.in);// object creation (1) s=new Scaner(System.in); // object creation(2) // Same with example 2

Arrays Arrays are reference types at Java. Creation of an array (1): Primitive Type Array: