SlideShare a Scribd company logo
Origin of Java 
• World War-2 need of a platform independent 
language 
• Green by Sun Micro Systems comes up 
• Fails due to marketing issues et al 
• Analog-to-Digital Transit, Computer H/W 
advancement, Concept of World Wide Web and 
Internet, Need of security 
• Green transformed to Oak 
• 1994 Java makes official release 
sohamsengupta@yahoo.com1
Three Editions of Java 
• J2SE (Java 2 Standard Edititon) 
• J2EE (Java 2 Enterprise Edition) 
• J2ME (Java 2 Micro Edition) 
sohamsengupta@yahoo.com2
Java Data Types 
Numeric: 1. Whole Numbers 
sohamsengupta@yahoo.com3 
2. Fractions 
Whole Numbers: byte 1 byte default value 0 
short2 bytes default value 0 
int  4 bytes default value 0 
long 8 bytes default value 0 
Fractions: float 4 bytes default value 0.0f 
double 8 bytes default value 0 .0 
Symbolic: char  2 bytes (Sun Unicode Character) default 
value‘u0000’ 
Logical : boolean 1 byte default value false 
User Defined: class and interface (to be described later on)
Your First Java Program 
• In C consider the code snippet… 
#include<stdio.h> 
void main(){ 
printf(“Hello From Soham”); 
sohamsengupta@yahoo.com4 
}• 
The corresponding Java Code would be… 
class A 
{ 
public static void main(String[] args){ 
System.out.print(“Hello from Soham”); 
}}
Before I say more on Java some Do’s 
Soham was writing a program as on LHS. After typing out 1000 lines he 
felt he needed an extra statement in if branch, but poor Soham! What he 
did was 
sohamsengupta@yahoo.com5 
• if(condition) 
statement-1; 
statement-2; 
. 
. 
. 
Statement-1000; 
• if(condition) 
statement-1; 
ssttaatteemmeenntt--11AA;; 
statement-2; 
. 
. 
. 
Statement-1000
Poor Me! I intended something else 
I was supposed to type… 
• if(condition){ 
sohamsengupta@yahoo.com6 
statement-1; 
ssttaatteemmeenntt--11AA;; 
}} 
statement-2; 
. 
. 
. 
statement-1000 
• Moral: 
1. When you come across some 
if-else branch, or for, while, 
switch, or any method or 
block, at once type out the 
braces and then carry on with 
your code 
2. It’ll not only save you from 
my condition, but also it’ll 
save you quite a lot of time of 
compilation errors saying… 
“ } required”
More on Java 
Answers to some FAQ about Java 2 
• A java file is saved in .java extension 
• A java file, if successfully compiled, produces x+y number of .class 
files where x and y are the number of classes and interfaces in that 
file 
• In java, you can’t put anything except comments outside a class or 
sohamsengupta@yahoo.com7 
interface block 
• To run java program you need Java Virtual Machine(JVM) which 
comes as a part of JDK. 
• Successful compilation generates .class files which contain byte 
codes that is interpreted by JVM. So, java development generally 
uses both compiler and interpreter. 
• Java Byte codes are platform independent but JVM is different for 
different Operating Systems.
Features of Java 2 (J2SE 1.4) 
1. Platform independent…means runs on any HW+OS environment 
2. Java was developed using C++ but excludes the features like 
sohamsengupta@yahoo.com8 
pointers. 
3. Java is a purely typed language as it does not allow automatic type 
demotion (More on this later on) 
4. Java is object oriented, secure due to its various security features, 
reusable and portable,form-free and case sensitive and supports 
general logical statements like C/C++ 
5. Java is not only platform friendly but also is very much developer 
friendly. As support of this statement, Java does not have concept of 
garbage value. It will never let the program perform read operation 
on a non initialized local variable .Also, it saves you from getting 
tampered data due to overflow and/or underflow since it doesn’t 
allow automatic type demotion
Java Source File Name & Class Name 
1. A java source file may contain any number of classes and interfaces 
and there is no such hard-and-first rule that file name and class/ 
interface name should have relation…. But wait friends, this is 
applicable as long as the file contains no public class/interface. 
More concisely, a java source file must have the same name as that 
of the public class/interface in it. It’s thus implied that a java source 
file can contain one and only one public class/interface 
2. To compile a Java file, say, A.java you have to give the command 
sohamsengupta@yahoo.com9 
…>javac A.java 
3. If successful compilation occurs, you will surely want to run it. And 
your command is going to be …> java MyClass where MyClass is 
the class inside A.java that has then main method. 
4. Remember, MyClass need not always have the main method.
My Second Java Program 
#include<stdio.h> 
void main() 
{ 
int x=940; 
printf(“U scored good marksn”); 
printf(“Your marks is %d”,x); 
sohamsengupta@yahoo.com10 
} 
class A 
{ 
public static void main(String[] ar) 
{ 
int x=940; 
System.out.println(“U scored good 
marks”); 
System.out.print(“Your marks is ”+x); 
} 
}
Printing an output on the console 
• We generally use the syntax System.out.print() or System.out.println() 
to output text on the console. Difference between them is that println() 
can be used with no arguments where as print() can’t be used without 
an argument. Also, println() automatically appends a trailing new line 
character (‘n’) 
• Don’t ask me more about System.out because my plan is to climb up 
the Java tree step by step and I don’t want to stumble down the stairs. 
Yet, FYI, System is class under java.lang package and out is an static 
object belonging to System class and of type java.io.PrintStream. 
• Note the syntax: System.out.print(“Your marks is ”+x); 
• Here + is concatenation operator instead and apart 
from being the traditional addition operator. 
sohamsengupta@yahoo.com11
Dual Nature of + operator 
Look at the code snippet below and see the outputs 
int x=9; int y=6; 
15 
System.out.println(x+y); 
int x=9; int y=6; 
System.out.println(“Sum is ”+x+y); 
Sum is 96 
int x=9; int y=6; 
System.out.println(“Sum is ”+(x+y)); 
Sum is 15 
int x=9; int y=6; 
System.out.println(“Product is ”+x*y); 
Product is 54 
int x=9; int y=6; 
System.out.println(x+y+ “ is the sum”); 
15 is the sum 
int x=9; int y=6; 
System.out.println(x-y+ “ is difference”); 
3 is difference 
int x=9; int y=6; 
System.out.println(“Difference is”+x-y); 
Compilation error: 
Operator – cannot be applied to 
java.lang.String,int 
sohamsengupta@yahoo.com12
From the Experts’ Desk 
1. Since you can’t always afford to remember all the precedence rules and 
this sort of things, the Java Guru recommends that you should always 
use parentheses while using arithmetic expressions in the simplest way 
2. As you are mostly accustomed to C/C++, first you’ll ask for a 
counterpart of scanf() and cin>>. Yes. You can take input from console 
through keyboard. But as I’ve told you, wait till I make you climb to 
that level! Java, unlike C/C++ is not meant to be used as a mere 
programming language with console as you did with Turbo C++, 
generating Pascal triangles or Fibonacci Series et al. 
3. Today java is more of a technology than of a language itself. Java can 
carry out robust networking, enterprise web development to small 
mobile device programming. 
4. Note that Java handles all inputs as String, unlike C then tries to 
convert to the intended type. 
sohamsengupta@yahoo.com13
Java As a Typed language: code snippet 
sohamsengupta@yahoo.com14 
byte x=9; 
System.out.println(x); 
Here output will be 9 It’s OK to assign a value to 
a type within range 
byte x=129; 
System.out.println(x); 
Error: Possible loss of 
precision: found int , 
required byte 
Value beyond range. Range 
of byte –128 to +127 
byte x=(byte)129; 
System.out.println(x); 
Output: -127 (data 
tampered due to overflow) 
Explicit type casting may 
cost you to worry later 
int y=5; byte x=y; 
System.out.println(x); 
Error: Possible loss of 
precision: found int , 
required byte 
Though value is in range, 
type int can’t be 
automatically demoted. 
int y=5; byte x=(byte)y; 
System.out.println(x); 
OK. Output: 5 Explicit type demotion ok 
here but can cause OF/UF 
long y=8; int x=y; 
System.out.println(x); 
Guess yourself Automatica type demotion 
not allowed so error. 
float x=9.8; // Error 
Should be float x=9.8f; 
Error: possible loss of 
precision: found double 
required float 
9.8 is double and 9.8f/9.8F 
is float. This is because java 
is memory efficient
Java A Typed Language: Contd. 
1. boolean is the only data type that can’t be converted to 
any type nor any other type be converted to boolean. 
2. Implicit type demotion is not allowed in java. You have 
to do it explicitly. But before that make sure that it 
causes no overflow and/or underflow or both. 
3. Although char is 2 bytes and so is short, yet they are not 
compatible. char is automatically converted to int or 
higher. For hierarchy consult any standard book. 
4. char is unsigned strictly in java and note the following. 
char ch=-90; // Error 
char ch=90; System.out.println(ch); // output : Z 
char ch=90; System.out.println((int)ch);// output 90 
sohamsengupta@yahoo.com15
Operators: Unary & Binary 
1. Rule for Unary Operator: 
“If the operand is of a type which is below int in the hierarchy, the 
output is converted to int, else the type of the output is the type of 
the operand.” 
2. Rule for Binary Operator: 
“ If the Binary operator takes 2 operators one of type T1 and the 
other of type T2, and max(T1,T2) is less than or equal to int, the 
output is converted to int itself, else the output is of type 
max(T1,T2)” 
This rule is not applicable to increment and decrement operators 
Hold your breath dears! Lots of surprises await you in the next 
slide. 
sohamsengupta@yahoo.com16
Look at the code snippets below 
sohamsengupta@yahoo.com17 
byte x=9; x=-x; 
System.out.println(x); 
Error: Possible loss of 
precision found: int 
required: byte 
Rule-1: inputbyte 
Output int 
byte x=9; byte y=x+1; 
System.out.println(x); 
Same Error Rule:2 i/p byte, int 
O/p int 
byte x=7; byte y=2; 
short z=x+y; 
Same Error! Apply Rule-2 
long x=89; byte y=8; 
int z=x+y; 
Error! Apply Rule-2. Output is 
of type long 
byte x=9; x=x+8; Error Apply Rule-2: Output is 
of type int 
byte x=9; x+=8; x++; OK Rule-2 Not applicable 
for += and ++ operator 
char ch=‘%’; int x=100 
System.out.println(x+ch 
+ “ pure am I”); 
Output 137 pure am I Be careful. To avoid 
this, use parentheses or 
String ch=“%”;
Note the Following 
• byte x=‘c’; // is OK 
• int x=12; 
byte y=x; // Error 
• final int x=12; byte y=x; // IS OK 
• final int x=134; byte y=x; // Error out of range 
• This holds only when source data is less than or 
equal to int. 
• Adding the keyword “final” before a variable 
makes it constant. It can’t be changed and any 
code to change this will result in compilation error 
sohamsengupta@yahoo.com18
Note the following code snippets 
public static void main(String[] args){ 
int x; 
x++; 
System.out.println(x); 
} 
Error: variable 
x might not 
have been 
initialized. 
In Java there is no concept 
of garbage value. Without 
initializing a local variable 
u can’t perform read 
operation on it. 
sohamsengupta@yahoo.com19 
int x; 
if(6>4){x=8; } 
System.out.println(x); 
OK. Output will 
be 8 
6>4 is evaluated at compile 
time. So, since it’s true 
always, x must be 
initialized. 
int x; 
if(6<4){ x=8;} 
System.out.println(x); 
Error:variable 
x might not 
have been 
initialized. 
6<4 is evaluated at compile 
time. So, since it’s false 
always, x must not be 
initialized. 
Replace numerics by variables say, a & 
b. Observe the result, it’s error 
if(a>b){ x=8;} System.out.print(x); 
But making them final will be ok if a>b 
is true 
Error:variable 
x might not 
have been 
initialized. 
a>b or a<b is not evaluated 
during compilation time. 
So, it’s not sure if x is 
initialized or not. Hence 
Error
Ad

More Related Content

What's hot (20)

Java programming basics
Java programming basicsJava programming basics
Java programming basics
Hamid Ghorbani
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
Monika Mishra
 
FaCoY – A Code-to-Code Search Engine
FaCoY – A Code-to-Code Search EngineFaCoY – A Code-to-Code Search Engine
FaCoY – A Code-to-Code Search Engine
Dongsun Kim
 
Java Threads
Java ThreadsJava Threads
Java Threads
Hamid Ghorbani
 
Reverse-engineering: Using GDB on Linux
Reverse-engineering: Using GDB on LinuxReverse-engineering: Using GDB on Linux
Reverse-engineering: Using GDB on Linux
Rick Harris
 
Taking User Input in Java
Taking User Input in JavaTaking User Input in Java
Taking User Input in Java
Eftakhairul Islam
 
Threads c sharp
Threads c sharpThreads c sharp
Threads c sharp
Karthick Suresh
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
Kuntal Bhowmick
 
Java Notes
Java Notes Java Notes
Java Notes
Sreedhar Chowdam
 
What's New In Python 2.4
What's New In Python 2.4What's New In Python 2.4
What's New In Python 2.4
Richard Jones
 
Threading in C#
Threading in C#Threading in C#
Threading in C#
Medhat Dawoud
 
advanced java ppt
advanced java pptadvanced java ppt
advanced java ppt
PreetiDixit22
 
Threads And Synchronization in C#
Threads And Synchronization in C#Threads And Synchronization in C#
Threads And Synchronization in C#
Rizwan Ali
 
Std 12 Computer Chapter 7 Java Basics (Part 1)
Std 12 Computer Chapter 7 Java Basics (Part 1)Std 12 Computer Chapter 7 Java Basics (Part 1)
Std 12 Computer Chapter 7 Java Basics (Part 1)
Nuzhat Memon
 
Socket Programming In Python
Socket Programming In PythonSocket Programming In Python
Socket Programming In Python
didip
 
Php interview questions with answer
Php interview questions with answerPhp interview questions with answer
Php interview questions with answer
Soba Arjun
 
Python session.11 By Shanmugam
Python session.11 By ShanmugamPython session.11 By Shanmugam
Python session.11 By Shanmugam
Navaneethan Naveen
 
Java Concurrency by Example
Java Concurrency by ExampleJava Concurrency by Example
Java Concurrency by Example
Ganesh Samarthyam
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
Akhil Kaushik
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
Raghu nath
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
Hamid Ghorbani
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
Monika Mishra
 
FaCoY – A Code-to-Code Search Engine
FaCoY – A Code-to-Code Search EngineFaCoY – A Code-to-Code Search Engine
FaCoY – A Code-to-Code Search Engine
Dongsun Kim
 
Reverse-engineering: Using GDB on Linux
Reverse-engineering: Using GDB on LinuxReverse-engineering: Using GDB on Linux
Reverse-engineering: Using GDB on Linux
Rick Harris
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
Kuntal Bhowmick
 
What's New In Python 2.4
What's New In Python 2.4What's New In Python 2.4
What's New In Python 2.4
Richard Jones
 
Threads And Synchronization in C#
Threads And Synchronization in C#Threads And Synchronization in C#
Threads And Synchronization in C#
Rizwan Ali
 
Std 12 Computer Chapter 7 Java Basics (Part 1)
Std 12 Computer Chapter 7 Java Basics (Part 1)Std 12 Computer Chapter 7 Java Basics (Part 1)
Std 12 Computer Chapter 7 Java Basics (Part 1)
Nuzhat Memon
 
Socket Programming In Python
Socket Programming In PythonSocket Programming In Python
Socket Programming In Python
didip
 
Php interview questions with answer
Php interview questions with answerPhp interview questions with answer
Php interview questions with answer
Soba Arjun
 
Python session.11 By Shanmugam
Python session.11 By ShanmugamPython session.11 By Shanmugam
Python session.11 By Shanmugam
Navaneethan Naveen
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
Akhil Kaushik
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
Raghu nath
 

Similar to Core java day1 (20)

00_Introduction to Java.ppt
00_Introduction to Java.ppt00_Introduction to Java.ppt
00_Introduction to Java.ppt
HongAnhNguyn285885
 
Java
Java Java
Java
Aashish Jain
 
Introduction to Java Programming Part 2
Introduction to Java Programming Part 2Introduction to Java Programming Part 2
Introduction to Java Programming Part 2
university of education,Lahore
 
Java Tut1
Java Tut1Java Tut1
Java Tut1
guest5c8bd1
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
Vijay A Raj
 
Java tut1
Java tut1Java tut1
Java tut1
Ajmal Khan
 
Tutorial java
Tutorial javaTutorial java
Tutorial java
Abdul Aziz
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPREC
Sreedhar Chowdam
 
Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction
AKR Education
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
sanjeeviniindia1186
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
Sanjeev Tripathi
 
Beyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software ArchitectureBeyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software Architecture
Jayaram Sankaranarayanan
 
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
AssignmentjsnsnshshusjdnsnshhzudjdndndjdAssignmentjsnsnshshusjdnsnshhzudjdndndjd
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
tusharjain613841
 
Knowledge of Javascript
Knowledge of JavascriptKnowledge of Javascript
Knowledge of Javascript
Samuel Abraham
 
Core Java
Core JavaCore Java
Core Java
christ university
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
caswenson
 
Java programing language unit 1 introduction
Java programing language unit 1 introductionJava programing language unit 1 introduction
Java programing language unit 1 introduction
chnrketan
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8
Bansilal Haudakari
 
Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
Akash Pandey
 
Unit 1
Unit 1Unit 1
Unit 1
LOVELY PROFESSIONAL UNIVERSITY
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPREC
Sreedhar Chowdam
 
Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction
AKR Education
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
sanjeeviniindia1186
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
Sanjeev Tripathi
 
Beyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software ArchitectureBeyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software Architecture
Jayaram Sankaranarayanan
 
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
AssignmentjsnsnshshusjdnsnshhzudjdndndjdAssignmentjsnsnshshusjdnsnshhzudjdndndjd
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
tusharjain613841
 
Knowledge of Javascript
Knowledge of JavascriptKnowledge of Javascript
Knowledge of Javascript
Samuel Abraham
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
caswenson
 
Java programing language unit 1 introduction
Java programing language unit 1 introductionJava programing language unit 1 introduction
Java programing language unit 1 introduction
chnrketan
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8
Bansilal Haudakari
 
Ad

More from Soham Sengupta (20)

Spring method-level-secuirty
Spring method-level-secuirtySpring method-level-secuirty
Spring method-level-secuirty
Soham Sengupta
 
Spring security mvc-1
Spring security mvc-1Spring security mvc-1
Spring security mvc-1
Soham Sengupta
 
JavaScript event handling assignment
JavaScript  event handling assignment JavaScript  event handling assignment
JavaScript event handling assignment
Soham Sengupta
 
Networking assignment 2
Networking assignment 2Networking assignment 2
Networking assignment 2
Soham Sengupta
 
Networking assignment 1
Networking assignment 1Networking assignment 1
Networking assignment 1
Soham Sengupta
 
Sohams cryptography basics
Sohams cryptography basicsSohams cryptography basics
Sohams cryptography basics
Soham Sengupta
 
Network programming1
Network programming1Network programming1
Network programming1
Soham Sengupta
 
JSR-82 Bluetooth tutorial
JSR-82 Bluetooth tutorialJSR-82 Bluetooth tutorial
JSR-82 Bluetooth tutorial
Soham Sengupta
 
Core java day2
Core java day2Core java day2
Core java day2
Soham Sengupta
 
Core java day4
Core java day4Core java day4
Core java day4
Soham Sengupta
 
Core java day5
Core java day5Core java day5
Core java day5
Soham Sengupta
 
Exceptions
ExceptionsExceptions
Exceptions
Soham Sengupta
 
Java.lang.object
Java.lang.objectJava.lang.object
Java.lang.object
Soham Sengupta
 
Jsp1
Jsp1Jsp1
Jsp1
Soham Sengupta
 
Soham web security
Soham web securitySoham web security
Soham web security
Soham Sengupta
 
Html tables and_javascript
Html tables and_javascriptHtml tables and_javascript
Html tables and_javascript
Soham Sengupta
 
Html javascript
Html javascriptHtml javascript
Html javascript
Soham Sengupta
 
Java script
Java scriptJava script
Java script
Soham Sengupta
 
Sohamsg ajax
Sohamsg ajaxSohamsg ajax
Sohamsg ajax
Soham Sengupta
 
Dhtml
DhtmlDhtml
Dhtml
Soham Sengupta
 
Ad

Recently uploaded (20)

How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 

Core java day1

  • 1. Origin of Java • World War-2 need of a platform independent language • Green by Sun Micro Systems comes up • Fails due to marketing issues et al • Analog-to-Digital Transit, Computer H/W advancement, Concept of World Wide Web and Internet, Need of security • Green transformed to Oak • 1994 Java makes official release [email protected]
  • 2. Three Editions of Java • J2SE (Java 2 Standard Edititon) • J2EE (Java 2 Enterprise Edition) • J2ME (Java 2 Micro Edition) [email protected]
  • 3. Java Data Types Numeric: 1. Whole Numbers [email protected] 2. Fractions Whole Numbers: byte 1 byte default value 0 short2 bytes default value 0 int  4 bytes default value 0 long 8 bytes default value 0 Fractions: float 4 bytes default value 0.0f double 8 bytes default value 0 .0 Symbolic: char  2 bytes (Sun Unicode Character) default value‘u0000’ Logical : boolean 1 byte default value false User Defined: class and interface (to be described later on)
  • 4. Your First Java Program • In C consider the code snippet… #include<stdio.h> void main(){ printf(“Hello From Soham”); [email protected] }• The corresponding Java Code would be… class A { public static void main(String[] args){ System.out.print(“Hello from Soham”); }}
  • 5. Before I say more on Java some Do’s Soham was writing a program as on LHS. After typing out 1000 lines he felt he needed an extra statement in if branch, but poor Soham! What he did was [email protected] • if(condition) statement-1; statement-2; . . . Statement-1000; • if(condition) statement-1; ssttaatteemmeenntt--11AA;; statement-2; . . . Statement-1000
  • 6. Poor Me! I intended something else I was supposed to type… • if(condition){ [email protected] statement-1; ssttaatteemmeenntt--11AA;; }} statement-2; . . . statement-1000 • Moral: 1. When you come across some if-else branch, or for, while, switch, or any method or block, at once type out the braces and then carry on with your code 2. It’ll not only save you from my condition, but also it’ll save you quite a lot of time of compilation errors saying… “ } required”
  • 7. More on Java Answers to some FAQ about Java 2 • A java file is saved in .java extension • A java file, if successfully compiled, produces x+y number of .class files where x and y are the number of classes and interfaces in that file • In java, you can’t put anything except comments outside a class or [email protected] interface block • To run java program you need Java Virtual Machine(JVM) which comes as a part of JDK. • Successful compilation generates .class files which contain byte codes that is interpreted by JVM. So, java development generally uses both compiler and interpreter. • Java Byte codes are platform independent but JVM is different for different Operating Systems.
  • 8. Features of Java 2 (J2SE 1.4) 1. Platform independent…means runs on any HW+OS environment 2. Java was developed using C++ but excludes the features like [email protected] pointers. 3. Java is a purely typed language as it does not allow automatic type demotion (More on this later on) 4. Java is object oriented, secure due to its various security features, reusable and portable,form-free and case sensitive and supports general logical statements like C/C++ 5. Java is not only platform friendly but also is very much developer friendly. As support of this statement, Java does not have concept of garbage value. It will never let the program perform read operation on a non initialized local variable .Also, it saves you from getting tampered data due to overflow and/or underflow since it doesn’t allow automatic type demotion
  • 9. Java Source File Name & Class Name 1. A java source file may contain any number of classes and interfaces and there is no such hard-and-first rule that file name and class/ interface name should have relation…. But wait friends, this is applicable as long as the file contains no public class/interface. More concisely, a java source file must have the same name as that of the public class/interface in it. It’s thus implied that a java source file can contain one and only one public class/interface 2. To compile a Java file, say, A.java you have to give the command [email protected] …>javac A.java 3. If successful compilation occurs, you will surely want to run it. And your command is going to be …> java MyClass where MyClass is the class inside A.java that has then main method. 4. Remember, MyClass need not always have the main method.
  • 10. My Second Java Program #include<stdio.h> void main() { int x=940; printf(“U scored good marksn”); printf(“Your marks is %d”,x); [email protected] } class A { public static void main(String[] ar) { int x=940; System.out.println(“U scored good marks”); System.out.print(“Your marks is ”+x); } }
  • 11. Printing an output on the console • We generally use the syntax System.out.print() or System.out.println() to output text on the console. Difference between them is that println() can be used with no arguments where as print() can’t be used without an argument. Also, println() automatically appends a trailing new line character (‘n’) • Don’t ask me more about System.out because my plan is to climb up the Java tree step by step and I don’t want to stumble down the stairs. Yet, FYI, System is class under java.lang package and out is an static object belonging to System class and of type java.io.PrintStream. • Note the syntax: System.out.print(“Your marks is ”+x); • Here + is concatenation operator instead and apart from being the traditional addition operator. [email protected]
  • 12. Dual Nature of + operator Look at the code snippet below and see the outputs int x=9; int y=6; 15 System.out.println(x+y); int x=9; int y=6; System.out.println(“Sum is ”+x+y); Sum is 96 int x=9; int y=6; System.out.println(“Sum is ”+(x+y)); Sum is 15 int x=9; int y=6; System.out.println(“Product is ”+x*y); Product is 54 int x=9; int y=6; System.out.println(x+y+ “ is the sum”); 15 is the sum int x=9; int y=6; System.out.println(x-y+ “ is difference”); 3 is difference int x=9; int y=6; System.out.println(“Difference is”+x-y); Compilation error: Operator – cannot be applied to java.lang.String,int [email protected]
  • 13. From the Experts’ Desk 1. Since you can’t always afford to remember all the precedence rules and this sort of things, the Java Guru recommends that you should always use parentheses while using arithmetic expressions in the simplest way 2. As you are mostly accustomed to C/C++, first you’ll ask for a counterpart of scanf() and cin>>. Yes. You can take input from console through keyboard. But as I’ve told you, wait till I make you climb to that level! Java, unlike C/C++ is not meant to be used as a mere programming language with console as you did with Turbo C++, generating Pascal triangles or Fibonacci Series et al. 3. Today java is more of a technology than of a language itself. Java can carry out robust networking, enterprise web development to small mobile device programming. 4. Note that Java handles all inputs as String, unlike C then tries to convert to the intended type. [email protected]
  • 14. Java As a Typed language: code snippet [email protected] byte x=9; System.out.println(x); Here output will be 9 It’s OK to assign a value to a type within range byte x=129; System.out.println(x); Error: Possible loss of precision: found int , required byte Value beyond range. Range of byte –128 to +127 byte x=(byte)129; System.out.println(x); Output: -127 (data tampered due to overflow) Explicit type casting may cost you to worry later int y=5; byte x=y; System.out.println(x); Error: Possible loss of precision: found int , required byte Though value is in range, type int can’t be automatically demoted. int y=5; byte x=(byte)y; System.out.println(x); OK. Output: 5 Explicit type demotion ok here but can cause OF/UF long y=8; int x=y; System.out.println(x); Guess yourself Automatica type demotion not allowed so error. float x=9.8; // Error Should be float x=9.8f; Error: possible loss of precision: found double required float 9.8 is double and 9.8f/9.8F is float. This is because java is memory efficient
  • 15. Java A Typed Language: Contd. 1. boolean is the only data type that can’t be converted to any type nor any other type be converted to boolean. 2. Implicit type demotion is not allowed in java. You have to do it explicitly. But before that make sure that it causes no overflow and/or underflow or both. 3. Although char is 2 bytes and so is short, yet they are not compatible. char is automatically converted to int or higher. For hierarchy consult any standard book. 4. char is unsigned strictly in java and note the following. char ch=-90; // Error char ch=90; System.out.println(ch); // output : Z char ch=90; System.out.println((int)ch);// output 90 [email protected]
  • 16. Operators: Unary & Binary 1. Rule for Unary Operator: “If the operand is of a type which is below int in the hierarchy, the output is converted to int, else the type of the output is the type of the operand.” 2. Rule for Binary Operator: “ If the Binary operator takes 2 operators one of type T1 and the other of type T2, and max(T1,T2) is less than or equal to int, the output is converted to int itself, else the output is of type max(T1,T2)” This rule is not applicable to increment and decrement operators Hold your breath dears! Lots of surprises await you in the next slide. [email protected]
  • 17. Look at the code snippets below [email protected] byte x=9; x=-x; System.out.println(x); Error: Possible loss of precision found: int required: byte Rule-1: inputbyte Output int byte x=9; byte y=x+1; System.out.println(x); Same Error Rule:2 i/p byte, int O/p int byte x=7; byte y=2; short z=x+y; Same Error! Apply Rule-2 long x=89; byte y=8; int z=x+y; Error! Apply Rule-2. Output is of type long byte x=9; x=x+8; Error Apply Rule-2: Output is of type int byte x=9; x+=8; x++; OK Rule-2 Not applicable for += and ++ operator char ch=‘%’; int x=100 System.out.println(x+ch + “ pure am I”); Output 137 pure am I Be careful. To avoid this, use parentheses or String ch=“%”;
  • 18. Note the Following • byte x=‘c’; // is OK • int x=12; byte y=x; // Error • final int x=12; byte y=x; // IS OK • final int x=134; byte y=x; // Error out of range • This holds only when source data is less than or equal to int. • Adding the keyword “final” before a variable makes it constant. It can’t be changed and any code to change this will result in compilation error [email protected]
  • 19. Note the following code snippets public static void main(String[] args){ int x; x++; System.out.println(x); } Error: variable x might not have been initialized. In Java there is no concept of garbage value. Without initializing a local variable u can’t perform read operation on it. [email protected] int x; if(6>4){x=8; } System.out.println(x); OK. Output will be 8 6>4 is evaluated at compile time. So, since it’s true always, x must be initialized. int x; if(6<4){ x=8;} System.out.println(x); Error:variable x might not have been initialized. 6<4 is evaluated at compile time. So, since it’s false always, x must not be initialized. Replace numerics by variables say, a & b. Observe the result, it’s error if(a>b){ x=8;} System.out.print(x); But making them final will be ok if a>b is true Error:variable x might not have been initialized. a>b or a<b is not evaluated during compilation time. So, it’s not sure if x is initialized or not. Hence Error