Warm-up Puzzle!
Homework
Take input N followed by N more numbers, find the sum of those numbers.
eg N = 4
10, 20, 30 , 50
Output : 110
Human readable description of an algorithm
Let's define our own instruction set
Read P,R,T and compute SI
Input
10, 20 , 4
Output
8
Pseudocode to check if number is prime or not.
Input
11
Output
Yes
read N i = 2 while i < N do if N is divisible by i then print “NOT PRIME” exit end i = i + 1 end print “IS PRIME” exit
Print the following pattern for a given N.
N = 4
1
2 3
4 5 6
7 8 9 10
1
2 3
4 5 6
7 8 9 10
read N Row = 1 Value = 1 while Row <= N do Col = 1 while Col <= Row do print Value Value = Value + 1 Col = Col + 1 end print “\n” Row = Row + 1 end exit
Write pseudocode to print the following pattern!
1
232
34543
4567654
567898765
N = 3
*
***
******
We humans use a decimal, or base-10, numbering system, presumably because people have 10 fingers
Early computers were designed around the decimal numbering system. This approach made the creation of computer logic capabilities unnecessarily complex and did not make efficient use of resources. (For example, 10 vacuum tubes were needed to represent one decimal digit.)
Story behind
To deal with the basic electronic states of on and off, Von Neumann suggested using the binary numbering system
What happens behind the scenes?
Why Java is Platform independent.
.java file
(source code)
.class file
(byte code)
Machine Code (0s & 1s)
compiler
interpreter
What happens behind the scenes?
Why Java is Platform independent.
.java file
(source code)
.class file
(byte code)
Machine Code (0s & 1s)
compiler
interpreter
Byte Code doesn't run directly, we need a JVM (Java Virtual Machine) to run this code
C/C++ Compiler generates a .exe file which is platform dependent.
In Java we get bytecode, JVM converts this bytecode into machine code.
To run byte-code, we need a JVM installed on a machine.
Java is platform independent but JVM is platform dependent.
Python is interpreted language, instructions are executed line by line.
Architecture
JDK = JRE + Development Tools
JRE = JVM + Library Classes
JDK = JRE + Development Tools
Java Virtual Machine (JVM)
JIT Compiler
(Just In Time)
Consists of Development tools & environment to run the Java program.
1. Development Tools
2. Compiler (javac)
3. Archiver (jar)
4. docs generator (javadoc)
5. interpreter / loader
Provides environment to only run the program.
JRE = JVM + Additional technologies & features
1. Deployment solutions
2. Development toolkits & libraries
3. Integration libraries
4. Language and utility libraries
(such as collections framework)
Java Virtual Machine
Java Virtual Machine, or JVM, loads, verifies and executes Java bytecode. It is known as the interpreter or the core of Java programming language because it executes Java code.
The JRE combines Java code created using the JDK with the necessary libraries required to run it on a JVM and then creates an instance of the JVM that executes the resulting program.
JVMs are available for multiple operating systems, and programs created with the JRE will run on all of them. In this way, the Java Runtime Environment is what enables a Java program to run in any operating system without modification.
IntelliJ Idea (IDE)
https://www.jetbrains.com/idea/download
(Free Community Edition)
JDK
https://www.oracle.com/java/technologies/downloads/#java16
ide.codingminutes.com
No Installation Required!
Directly Run | Save | Share Codes!
Boilerplate Code
//Boilerplate Code
class Main
{
public static void main (String[] args)
{
}
}
Boilerplate Code
//Boilerplate Code
class Main
{
public static void main (String[] args)
{
//Your Code goes here
}
}
Boilerplate Code
//Boilerplate Code
class Main
{
public static void main (String[] args)
{
//Your Code goes here
System.out.println("Hello World");
}
}
Let's Solve Problems & learn Java syntax!
1. Hello Java
2. Variables
3. Loops
4. Typecasting
5. Problems - Prime Numbers, Patterns, Simple Interest
variable = (condition) ? expressionTrue : expressionFalse;
Ternary Operator