DCIT23 1_Introduction to Java PDF

Document Details

Uploaded by Deleted User

Vanessa G. Coronado and Charlotte B. Carandang

Tags

java programming programming languages computer science introduction to programming

Summary

This document provides a lecture on introduction to Java programming. It covers topics like the Java programming language, its history, and software requirements. The document also explains basic concepts like keywords, identifiers, and input handling. This is a great introductory resource for students learning Java programming.

Full Transcript

LECTURE 1: Introduction to JAVA Programming DCIT 23 – Computer Programming II Prepared by: Prof. Vanessa G. Coronado and Prof. Charlotte B. Carandang 2 A language that doesn't affect the way you think about programming is not worth knowing. — Alan Perlis 3 JAVA PROGRAMMI...

LECTURE 1: Introduction to JAVA Programming DCIT 23 – Computer Programming II Prepared by: Prof. Vanessa G. Coronado and Prof. Charlotte B. Carandang 2 A language that doesn't affect the way you think about programming is not worth knowing. — Alan Perlis 3 JAVA PROGRAMMING LANGUAGE ▸ class-based, object- ▸ general-purpose programming oriented programming language intended to let language that is application developers write designed to have as once, run few implementation anywhere (WORA) meaning that dependencies as compiled Java code can run on possible all platforms that support Java without the need for recompilation. 4 JAVA PROGRAMMING LANGUAGE ▸ compiled to bytecode ▸ similar to C and C++, but has that can run on any fewer low-level facilities than Java virtual machine either of them (JVM) regardless of the underlying computer architecture. 5 JAVA PROGRAMMING LANGUAGE ▸ As of 2019, Java was one of the most popular programming languages in use according to GitHub, particularly for client- server web applications, with a reported 9 million developers. 6 HISTORY ▸ originally developed by James Gosling at Sun Microsystems ▸ released in 1995 as a core component of Sun Microsystems' Java platform ▸ originally designed for interactive television, but it was too advanced for the digital cable television industry at the time. 7 HISTORY ▸ the language was initially called Oak after an oak tree that stood outside Gosling's office. ▸ project went by the name Green and was finally renamed Java, from Java coffee, a type of coffee from Indonesia. ▸ Sun Microsystems released the first public implementation as Java 1.0 in 1996. 8 SOFTWARE REQUIREMENTS ▸ JDK from Sun/Oracle. (https://www.oracle.com/java/technologies/javase-jdk-7- netbeans-install.html) ▸ Netbeans IDE for Java Developers. (https://netbeans.apache.org/download/index.html) 9 FIRST JAVA PROGRAM Keywords A keyword is a dictionary word — a word that’s built right into a language. Each Java keyword has a specific meaning — a meaning that remains unchanged from one program to another. Sample keywords are class, public, static, and void. 10 FIRST JAVA PROGRAM Identifiers with agreed-upon meanings Most programming languages have identifiers with agreed-upon meanings. In Java, almost all these identifiers are defined in the Java API. main: The main starting point for execution in every Java program. String: A bunch of text; a row of characters, one after another. System: A canned program in the Java API. This program accesses some features of your computer that are outside the direct control of the Java Virtual Machine (JVM). out: The place where a text-based program displays its text. println: Display text on your computer screen. The name println comes from the words “print a line.” 11 FIRST JAVA PROGRAM Literals A literal is a chunk of text that looks like whatever value it represents. Programming languages have literals, too. System.out.println("Hello World"); 12 FIRST JAVA PROGRAM Comments A comment is text that’s outside the normal flow. The Java programming language has two kinds of comments: ✓ Traditional comments: The comment begins with. Everything between the opening is for human eyes only. Nothing between gets translated by the compiler. ✓ End-of-line comments: Here’s some code with end-of-line comments: An end-of- line comment starts with two slashes and goes to the end of a line of type. 13 GETTING INPUT FROM THE KEYBOARD Using Scanner The word Scanner is defined in the Java API which can be used for getting input. 14 GETTING INPUT FROM THE KEYBOARD Using In the statement, Scanner The word Scanner sc = new Scanner is Scanner(System.in); defined in the Java API we are declaring a variable named sc with the which can class type Scanner. be used for getting input. 15 GETTING INPUT FROM THE KEYBOARD Using In sc.nextLine(), the computer runs your program, the computer Scanner substitutes whatever you type on the keyboard in place of the text The word Meaning Method Call Scanner is A number with no decimal point in it nextInt() defined in A number with a decimal point in it nextDouble() A word (ending in a blank space, for example) next() the Java API A line (or what remains of a line after you’ve nextLine() which can already read some data from the line) be used for A single character (such as a letter, a next().charAt(0) getting digit, or a punctuation character) input. 16 GETTING INPUT FROM THE KEYBOARD Using BufferedReader The BufferedReader class found in the java.io package in order to get input from the keyboard. 17 GETTING INPUT FROM THE KEYBOARD The statements, Using BufferedReader import java.io.BufferedReader; The import java.io.InputStreamReader; BufferedReader import java.io.IOException; class found in the java.io package in order indicate that we want to use the classes BufferedReader, to get input from InputStreamReader and IOException which is inside the the keyboard. java.io package. The Java Application Programming Interface (API) contains hundreds of predefined classes that you can use in your programs. These classes are organized into what we call packages. 18 GETTING INPUT FROM THE KEYBOARD Using The statement, BufferedReader public class SampleBufferedReader The { BufferedReader class found in public static void main( String[] args ) throws the java.io IOException{ package in order to get input from means we declare a class named SampleBufferedReader and we the keyboard. declare the main method. 19 GETTING INPUT FROM THE KEYBOARD Using In the statement, BufferedReader BufferedReader dataIn = new BufferedReader(new The InputStreamReader( System.in) ); BufferedReader class found in the java.io we are declaring a variable named dataIn with the class type package in order BufferedReader. to get input from the keyboard. 20 GETTING INPUT FROM THE KEYBOARD Using The statement, BufferedReader String name = dataIn.readLine(); The BufferedReader class found in the method call, dataIn.readLine(), gets input from the user and will the java.io return a String value. This value will then be saved to our name variable, package in order which we will use in the later statement to greet the user, to get input from the keyboard. System.out.println("Hello " + name + "!"); 21 GETTING INPUT FROM THE KEYBOARD The statements, Using BufferedReader int age = Integer.parseInt(dataIn.readLine());, gets The input from the user and will return an Integer value; BufferedReader class found in double mobileNo = the java.io Double.parseDouble(dataIn.readLine());, gets input from package in order to get input from the user and will return a Double value; the keyboard. long cgpa = Long.parseLong(dataIn.readLine());, gets input from the user and will return a Long value; 22 USE OF ARITHMETIC OPERATIONS Accept 2 integers and display the sum 23 USE OF ARITHMETIC OPERATIONS Accept 2 float numbers and display the sum 24 PRIMITIVE DATA TYPE 25 JAVA ARITHMETIC OPERATORS END

Use Quizgecko on...
Browser
Browser