SlideShare a Scribd company logo
1 of 23
Java Fundamentals
Java Architecture/Language Basics
FEATURES
FEATURES OF JAVA
Memory access via pointer arithmetic: this is fundamentally unsafe.
Java has a robust security model and disallows pointer arithmetic for
the same reason. It would be impossible for the Virtual Machine to
ensure that code containing pointer arithmetic is safe without
expensive runtime checks.
Security: By not allowing pointers, Java effectively provides another
level of abstraction to the developer. No pointer support make Java
more secure because they point to memory location or used
for memory management that loses the security as we use them
directly.
Why pointer concept not use in java?
JAVAARCHITECTURE
Write the correct order of the Java program execution
A. Class Loader
B. Interpretation
C. Compilation
D. Byte Code Verification
E. Java Source Code
F. Execution
Which of the following is used to load a .class file?
A. Class Loader
B. Byte Code Verifier
C. JIT Compiler
D. Interpreter
Questions based on JAVA architecture
Overview of JDK ,JRE, JVM
JVM (Java Virtual Machine) is an abstract machine. It is called a virtual machine
because it doesn't physically exist. It is a specification that provides a runtime
environment in which Java bytecode can be executed. It can also run those
programs which are written in other languages and compiled to Java bytecode.
JRE is an acronym for Java Runtime Environment. It is also written as Java
RTE. The Java Runtime Environment is a set of software tools which are used for
developing Java applications. It is used to provide the runtime environment. It is
the implementation of JVM. It physically exists. It contains a set of libraries +
other files that JVM uses at runtime.
JDK is an acronym for Java Development Kit. The Java Development Kit (JDK)
is a software development environment which is used to develop Java
applications and applets. It physically exists. It contains JRE + development
tools.
Overview of JDK ,JRE, JVM
QUES
The JDK is a superset of the JRE, and contains everything that is in the
JRE, plus tools such as the compilers and debuggers
necessary for developing applets and applications.
A. TRUE
B. FALSE
JDK JRE JVM
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, that are free to use, included
in the Java Development Environment.
The library contains components for managing input, database programming,
and much much more. The complete list can be found at Oracles
website: https://docs.oracle.com/javase/8/docs/api/.
The library is divided into packages and classes. Meaning you can either
import a single class (along with its methods and attributes), 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.
JAVA API
Sample.java file contains class A, B and C. How many .class files
will be created after compiling Sample.java?
What is your observation?
//Sample.java javac Sample.java A.class B.class C.class
class A {
void m1( ) { }
}
class B {
void m2( ) { }
}
class C {
void m3( ) { }
}
Understanding of .class file concept.
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.
Difference between class, object, methods,
and instance variables?
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”
Analyze the below program and answer
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
Accessing numeric command line arguments
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 KEYWORDS
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
Identifiers in java
What is null in Java.
The null is not a keyword. null is a literal as true or false
Can a digit form the first character of an identifier?
No. Only characters are allowed. However they may be used after the first
character.
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>();
Quick test
The Java programming language defines the following kinds of
Variables:
Local Variables
Tied to a method
Scope of a local variable is within the method
Instance Variables (Non-static)
Tied to an object
Scope of an instance variable is the whole class
Static Variables
Tied to a class
Shared by all instances of a class
Difference between local, instance and static variable
public class StudentDetails {
public void StudentAge()
{ // local variable age
int age = 0;
age = age + 5;
}
public static void main(String args[])
{
// using local variable age outside it's scope
System.out.println("Student age is : " + age);
}
}
Output:
Compilation Error in java code :- prog.java:12: error: cannot find symbol
System.out.println("Student age is : " + age); ^ symbol: variable age location: class
StudentDetails 1 error
Understanding the concept of local variable
class variable_scope
{public static void main(String args[])
{
int x;
x = 5;{
int y = 6;
System.out.print(x + " " + y);}
System.out.println(x + " " + y);
} }
Compilation error
Explanation: Second print statement doesn’t have access to y , scope y
was limited to the block defined after initialization of x.
What will be the output of the following Java program?
DATA TYPES
What will be the result, if we try to compile and execute the
following??
code?
class Test {
public static void main(String [ ] ar) {
byte b=128;
System.out.println(b);
}
}
Understanding of data type concepts
class Simple{
public static void main(String[] args){
float f=10.5f;
//int a=f;//Compile time error
int a=(int)f;
System.out.println(f);
System.out.println(a);
}}
O/P
10.5 10
class Simple{
public static void main(String[] args){
int a=10;
float f=a;
System.out.println(a);
System.out.println(f);
}}
Output:
10 10.0
Java Variable Example: Narrowing (Typecasting) and : Widening
Which of the following do not denote a primitive data value in Java? Select
the two correct answers.
(a) "t"
(b) 'k‘
(c) 50.5F
(d) "hello"
(e) false 2.5
Which of the following primitive data types are not integer types? Select the
three correct answers.
(a) boolean
(b) byte
(c) float
(d) short
(e) double
MCQ

More Related Content

Similar to DAY_1.1.pptx

Unit1 introduction to Java
Unit1 introduction to JavaUnit1 introduction to Java
Unit1 introduction to JavaDevaKumari Vijay
 
Chapter1pp
Chapter1ppChapter1pp
Chapter1ppJ. C.
 
Introduction
IntroductionIntroduction
Introductionrichsoden
 
Java Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedJava Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedyearninginjava
 
A seminar report on core java
A  seminar report on core javaA  seminar report on core java
A seminar report on core javaAisha Siddiqui
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javaSujit Majety
 
Top 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experiencedTop 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experiencedGaurav Maheshwari
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using ReflectionGanesh Samarthyam
 
Fundamentals of oop lecture 2
Fundamentals of oop lecture 2Fundamentals of oop lecture 2
Fundamentals of oop lecture 2miiro30
 
Java essentials for hadoop
Java essentials for hadoopJava essentials for hadoop
Java essentials for hadoopSeo Gyansha
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answersKrishnaov
 
Java programming basics
Java programming basicsJava programming basics
Java programming basicsHamid Ghorbani
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Ayes Chinmay
 
Top 10 Important Core Java Interview questions and answers.pdf
Top 10 Important Core Java Interview questions and answers.pdfTop 10 Important Core Java Interview questions and answers.pdf
Top 10 Important Core Java Interview questions and answers.pdfUmesh Kumar
 

Similar to DAY_1.1.pptx (20)

Unit1 introduction to Java
Unit1 introduction to JavaUnit1 introduction to Java
Unit1 introduction to Java
 
java basic .pdf
java basic .pdfjava basic .pdf
java basic .pdf
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Chapter1pp
Chapter1ppChapter1pp
Chapter1pp
 
1
11
1
 
Introduction
IntroductionIntroduction
Introduction
 
Java Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedJava Faqs useful for freshers and experienced
Java Faqs useful for freshers and experienced
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
A seminar report on core java
A  seminar report on core javaA  seminar report on core java
A seminar report on core java
 
java notes.pdf
java notes.pdfjava notes.pdf
java notes.pdf
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Top 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experiencedTop 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experienced
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using Reflection
 
Fundamentals of oop lecture 2
Fundamentals of oop lecture 2Fundamentals of oop lecture 2
Fundamentals of oop lecture 2
 
Java essentials for hadoop
Java essentials for hadoopJava essentials for hadoop
Java essentials for hadoop
 
Java essentials for hadoop
Java essentials for hadoopJava essentials for hadoop
Java essentials for hadoop
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
 
Top 10 Important Core Java Interview questions and answers.pdf
Top 10 Important Core Java Interview questions and answers.pdfTop 10 Important Core Java Interview questions and answers.pdf
Top 10 Important Core Java Interview questions and answers.pdf
 

Recently uploaded

EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIkoyaldeepu123
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AI
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 

DAY_1.1.pptx

  • 3. Memory access via pointer arithmetic: this is fundamentally unsafe. Java has a robust security model and disallows pointer arithmetic for the same reason. It would be impossible for the Virtual Machine to ensure that code containing pointer arithmetic is safe without expensive runtime checks. Security: By not allowing pointers, Java effectively provides another level of abstraction to the developer. No pointer support make Java more secure because they point to memory location or used for memory management that loses the security as we use them directly. Why pointer concept not use in java?
  • 5. Write the correct order of the Java program execution A. Class Loader B. Interpretation C. Compilation D. Byte Code Verification E. Java Source Code F. Execution Which of the following is used to load a .class file? A. Class Loader B. Byte Code Verifier C. JIT Compiler D. Interpreter Questions based on JAVA architecture
  • 6. Overview of JDK ,JRE, JVM
  • 7. JVM (Java Virtual Machine) is an abstract machine. It is called a virtual machine because it doesn't physically exist. It is a specification that provides a runtime environment in which Java bytecode can be executed. It can also run those programs which are written in other languages and compiled to Java bytecode. JRE is an acronym for Java Runtime Environment. It is also written as Java RTE. The Java Runtime Environment is a set of software tools which are used for developing Java applications. It is used to provide the runtime environment. It is the implementation of JVM. It physically exists. It contains a set of libraries + other files that JVM uses at runtime. JDK is an acronym for Java Development Kit. The Java Development Kit (JDK) is a software development environment which is used to develop Java applications and applets. It physically exists. It contains JRE + development tools. Overview of JDK ,JRE, JVM
  • 8. QUES The JDK is a superset of the JRE, and contains everything that is in the JRE, plus tools such as the compilers and debuggers necessary for developing applets and applications. A. TRUE B. FALSE JDK JRE JVM
  • 9. 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, that are free to use, included in the Java Development Environment. The library contains components for managing input, database programming, and much much more. The complete list can be found at Oracles website: https://docs.oracle.com/javase/8/docs/api/. The library is divided into packages and classes. Meaning you can either import a single class (along with its methods and attributes), 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. JAVA API
  • 10. Sample.java file contains class A, B and C. How many .class files will be created after compiling Sample.java? What is your observation? //Sample.java javac Sample.java A.class B.class C.class class A { void m1( ) { } } class B { void m2( ) { } } class C { void m3( ) { } } Understanding of .class file concept.
  • 11. 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. Difference between class, object, methods, and instance variables?
  • 12. 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” Analyze the below program and answer
  • 13. 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 Accessing numeric command line arguments
  • 14. 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 KEYWORDS
  • 15. 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 Identifiers in java
  • 16. What is null in Java. The null is not a keyword. null is a literal as true or false Can a digit form the first character of an identifier? No. Only characters are allowed. However they may be used after the first character. 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>(); Quick test
  • 17. The Java programming language defines the following kinds of Variables: Local Variables Tied to a method Scope of a local variable is within the method Instance Variables (Non-static) Tied to an object Scope of an instance variable is the whole class Static Variables Tied to a class Shared by all instances of a class Difference between local, instance and static variable
  • 18. public class StudentDetails { public void StudentAge() { // local variable age int age = 0; age = age + 5; } public static void main(String args[]) { // using local variable age outside it's scope System.out.println("Student age is : " + age); } } Output: Compilation Error in java code :- prog.java:12: error: cannot find symbol System.out.println("Student age is : " + age); ^ symbol: variable age location: class StudentDetails 1 error Understanding the concept of local variable
  • 19. class variable_scope {public static void main(String args[]) { int x; x = 5;{ int y = 6; System.out.print(x + " " + y);} System.out.println(x + " " + y); } } Compilation error Explanation: Second print statement doesn’t have access to y , scope y was limited to the block defined after initialization of x. What will be the output of the following Java program?
  • 21. What will be the result, if we try to compile and execute the following?? code? class Test { public static void main(String [ ] ar) { byte b=128; System.out.println(b); } } Understanding of data type concepts
  • 22. class Simple{ public static void main(String[] args){ float f=10.5f; //int a=f;//Compile time error int a=(int)f; System.out.println(f); System.out.println(a); }} O/P 10.5 10 class Simple{ public static void main(String[] args){ int a=10; float f=a; System.out.println(a); System.out.println(f); }} Output: 10 10.0 Java Variable Example: Narrowing (Typecasting) and : Widening
  • 23. Which of the following do not denote a primitive data value in Java? Select the two correct answers. (a) "t" (b) 'k‘ (c) 50.5F (d) "hello" (e) false 2.5 Which of the following primitive data types are not integer types? Select the three correct answers. (a) boolean (b) byte (c) float (d) short (e) double MCQ