Download presentation
Presentation is loading. Please wait.
1
Foundations of Programming: Java
2
Introduction to Java: Why Java?
Java is one of the most used programming languages in the world and is run in over 3 billion devices. Java is platform independent programming language which means in run on any device that can run Java. Java is an object-oriented language meaning we can make different programming objects(classes) and use them with one another compared to doing everything in on single object(class). Also objects can easily be reused in different programs. Java has a vast library of predefined objects and operations making it easier for to get certain task done faster. Java also has automatic type checking, automatic garbage collection, multi-threading capabilities, and more. All this means…
3
Basics of how Java Programs Execute
First you will create a .java file(code) and then that .java file will have to be sent to a compiler which then turns that code into .class file. Once the .class file is created you can now run your java code. For the most of the school year Java code will be run through the command prompt. Instructions of how to compile and run code is below: Prepare the file foo.java using an editor Invoke the compiler: javac foo.java This creates foo.class Run the java interpreter: java foo Use the command prompt to run your java program. In your command prompt go to the location of the java file and then compile your Java program. Then after compiling with no errors, run your java program like with the examples above.
4
Make your own Java Program
Now we are going to make our own very simple Java program. Open up notepad++ and copy the code from the picture below into the editor Save file and name it hello.java; Run the code using the instructions on the previous slide. If you have trouble using the command prompt ask for instructions from me or another student. The file name must be the same as the name of the class.
5
Congratulations!! You have made your first Java program!! Although the program itself doesn’t do much, you can now say you’ve programmed in Java. The Hello World Program is the program that many computer scientists started of with. Now lets get a bit more complicated. Lets ask the user for some input and figure out the circumference and area of a circle. To do this we need to have the user give the program the radius of the circle. import java.util.Scanner; //Place this line of code at the very beginning of the program Use this code to receive input from the user
6
Scanner: To take in input from the user, you must create a scanner as done in line 7 below. In line 7 the name of the Scanner is input but you can change it to whatever you want Now when you want to take in input from the user, you must use the Scanner you created followed by a function. If you want to to take in a decimal number you may want to use the Scanner function nextDouble(). Remember to store user input in a variable like in line 7.
7
Introduction: Built-in Data Types
Last class we briefly went over different data types and today we’ll go more into depth about this topic. Java has a set of Built-in Data Types Data type: A set of values and operations defined on those values.
8
Basic Defintions Variable: A name that refers to a values
Assignment Statement: Associates a value with a variable You can declare a variable without giving it an explicit(literal) value.
9
Trace a sequence of statements
Trace: Table of variable values after each statement Java Statement : Variables and Associated Values
10
Text: String String Data Type: Useful for program input and output
11
String Concatenation Example
Try and Interpret this Java Program:
12
Integers int Data Type: Useful for expressing algorithm; A whole number that is positive/zero/negative.
13
Integer Program Example
Run this program on your own later: Try different combinations of numbers
14
Double/Float/Long/Short
There are other data types that also represent numbers: Type Decimal/No Decimal double Decimal float Decimal long No Decimal short No Decimal Each of these has a different range of numbers they can represent. For more information about the specific details of each data type go to the site: data-types.php
15
Booleans Boolean Data Type: Useful to control logic and flow of a program; True/False
16
Comparisons Comparison: Take operands of one type and produce an operand of type Boolean
17
Summary A data type is a set of values and operations on those values
String: Text Processing double, int Mathematical Calculation Boolean Decision Making In Java, you must: Declare types of values. Convert between types when necessary.
18
Assignment: Complete Java Programming Assignment #1 on my website.
You will be writing 4 programs which means you will have 4 separate java files. Look at this PowerPoint for some guidance on how to write and structure your programs. You will need to use the command prompt so pay attention on how I execute Java programs. You can also look at slide 3 for guidance.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.