Lecture-1.2
Lecture-1.2
DEPARTMENT : CSE
Bachelor of Engineering (Computer Science & Engineering)
Java Programming (20CST-218)
TOPIC OF PRESENTATION:
Java Fundamentals
2
JAVA API
• Java application programming interface (API) is a list of all classes that are part of
the Java development kit (JDK).
• It includes all Java packages, classes, and interfaces, along with their methods, fields,
and constructors.
• These prewritten classes provide a tremendous amount of Built-in Packages.
• The Java API is a library of prewritten classes which contains components for managing
input, database programming. T
• The library is divided into packages and classes i.e you can either import a single class
or a whole package that contain all the classes that belong to the specified package.
• To use a class or a package from the library, you need to use the import keyword.
Understanding of .class file concept.
Sample.java file contains class A, B and C. How many .class files will be created after compiling
Sample.java?
• Object - Objects have states and behaviors. Example: A dog has states - color,
name, breed as well as behavior such as wagging their tail, barking, eating. An
object is an instance of a class.
• Class - A class can be defined as a template/blueprint that describes the
behavior/state that the object of its type supports.
• Methods - A method is basically a behavior. A class can contain many methods. It
is in methods where the logics are written, data is manipulated and all the actions
are executed
• Instance - Each object has its unique set of instance variables. An object's state is
created by the values assigned to these instance variables.
Analyze the below program and answer
What will be the result if you try to compile and execute the following program ?
Reason out :
Sample.java
class Sample {
public static void main() {
System.out.println(“Welcome”);
}
}
a. Compilation Error
b. Runtime Error
c. The program compiles and executes successfully but prints
nothing.
d. It will print “Welcome”
Accessing numeric command line arguments
class Simple {
static public void main(String[] args) {
int i1 = Integer.parseInt(args[0]);
int i2 = Integer.parseInt(args[1]);
System.out.println(i1+i2);
}
}
When we compile the above code successfully and execute it as Java Simple 10 20,
the output will be 30
Java Keywords
• Java has a set of keywords that are reserved words that cannot be used as variables, methods,
classes, or any other identifiers.
• Example break, abstract, byte, Boolean etc
• True, false, and null are not keywords, but they are literals and reserved words that cannot be
used as identifiers.
Which statement is true?
Select the one correct answer.
(a) new and delete are keywords in the Java language.
(b) try, catch, and thrown are keywords in the Java language.
(c) static, unsigned, and long are keywords in the Java language.
(d) exit, class, and while are keywords in the Java language.
(e) return, goto, and default are keywords in the Java language.
(f) for, while, and next are keywords in the Java language.
Java Operators
Java Operators
Identifiers in java
• In programming languages, identifiers are used for identification purpose. In Java, an identifier can be a class
name, method name, variable name or a label.
• For example :
public class Test { public static void main(String[] args) { int a = 20; } }
Which of the following can be used in a Java program as identifiers? Check all of the identifiers that are legal.
1. sum_of_data
2. AnnualSalary
3. _average
4. 42isThesolution
5. B4
6. ABC
7. for
8. println
9. "hello"
10. first-name
Answer 1 2 3 5 6 8
Quick test
1. What is null in Java.
The null is not a keyword. null is a literal as true or false
2. Can a digit form the first character of an identifier?
No. Only characters are allowed. However they may be used after the first
character.
3. Explain var keyword in Java.
var keyword is introduced in Java 10 to enhance the Java Language to extend type
inference to declarations of local variables with initializers.
var map = new HashMap<String, Integer>();
Difference between local, instance and static variable
Books:
1. Balaguruswamy, Java.
2. A Primer, E.Balaguruswamy, Programming with Java, Tata McGraw Hill
Companies
3. John P. Flynt Thomson, Java Programming.
Video Lectures :
https://www.youtube.com/watch?v=0MFC_Vw9NxY
E-book :
https://www.learnjavaonline.org/
THANK YOU