SlideShare a Scribd company logo
1 of 38
JAVA BASICS
Prepared by
The Smartpath Information Systems
www.thesmartpath.in
Index
1. Java Technology
2. Java Programming
3. Java Programming (Cont.)
4. The Java Platform
5. Java Bytecode
6. Java Virtual Machine
7. Java Runtime Environment (JRE)
8. Java Software Development Kit (Java SDK)
9. Java Object-Oriented Programming Concepts
10. What Is an Object?
11. What Is a Class?
12. What Is Inheritance?
13. What Is an Interface?
14. What Is an Polymorphism?
15. Legal Identifiers
16. Source File Declaration Rules
17. Source File Declaration Rules (Cont.)
18. Class Declarations and Modifiers
19. Interface Implementation
20. Interface Implementation(Cont.)
21. Interface Implementation(Cont.)
22. Member Access Modifiers
23. Member Access Modifiers(Cont.)
24. Member Access Modifiers(Cont.)
25. Local Variables
26. Other Modifiers Members
27. Other Modifiers Members(Cont.)
28. Methods with var-args
29. Variable Declarations
30. Variable Declarations (Cont.)
31. Array Declarations
32. Static Variables and Methods
33. References
Java Technology
 Java technology is both a programming language and a platform.
Simple
Object oriented
Distributed
Multithreaded
Dynamic
Architecture neutral
Portable
High performance
Robust
Secure
Java Programming
 Source code is first written in plain text files ending with the .java extension.
 Source files are then compiled into .class files by the javac compiler. A .class file does
not contain code that is native to your processor; it instead contains bytecodes --
the machine language of the Java Virtual Machine (Java VM).
 The java launcher tool then runs your application with an instance of the
Java Virtual Machine.
Java Programming (Cont.)
Java VM is available on many different operating systems,
the same class files are capable of running on
 Microsoft Windows
 the Solaris™ Operating System (Solaris OS)
 Linux, or Mac OS. Etc.
Through the Java VM, the same application
is capable of running on multiple platforms.
The Java Platform
A platform is the hardware or software environment in which a program runs. Since Java
has its own runtime environment (JRE) and API, it is called platform .The Java platform
has two components:
•The Java Virtual Machine
•The Java Application Programming Interface (API)
The API is a large collection of ready-made software components that provide many useful
capabilities. It is grouped into libraries of related classes and interfaces; these libraries are
known as packages.
Java Bytecode
Java programs written in the Java language are compiled into Java bytecode which
can be executed by the Java Virtual Machine. The Java bytecode is stored in binary
.class files.
Java Virtual Machine
Java is an interpreted language.
The Java language is compiled into Java bytecode.
This Java bytecode is then executed by the Java Virtual Machine.
The Java Virtual Machine is like a computer. It can execute Java bytecode just like a
PC can execute assembler instructions.
The Java Virtual Machine is a program itself
Java Runtime Environment (JRE)
The Java Runtime Environment (JRE) is the Java Virtual Machine and the
standard Java APIs coming with Java Standard Edition (JSE).
The JRE contains enough to execute a Java application, but not to compile it.
Java Software Development Kit (Java SDK)
The Java Software Development Kit (Java SDK) is the JRE plus the Java compiler,
and a set of other tools.
If you need to develop Java programs you need the full Java SDK. The JRE is not
enough then. Only the full Java SDK contains the Java compiler which turns your .
java source files into byte code .class files.
Java Object-Oriented Programming Concepts
What Is an Object?
What Is a Class?
What Is Inheritance?
What Is an Encapsulation?
What Is Polymorphism?
What Is an Interface?
What Is an Object?
What Is an Object?
An Object is a particular concrete instance of Class.
Object is real world entity, which has property and behavior
Man Student Tree Car
What is class?
A class is a blueprint or prototype from which objects are created which has attributes
and behavior, we call attribute as members and behavior as methods.
What Is Inheritance?
Inheritance is the process by which one object acquires the properties of another object.
Inheritance provides a powerful and natural mechanism for organizing and
structuring your software.
What Is an Interface?
An interface is a contract between a class and the outside world. When a class implements
an interface, it promises to provide the behavior published by that interface.
What Is an Polymorphism?
Polymorphism is the ability of an object to take on many forms. The most common use
of polymorphism in OOP occurs when a parent class reference is used to refer to a child
class object.
Legal Identifiers
Identifiers must start with a letter, a currency character ($), or a connecting
character such as the underscore ( _ ). Identifiers cannot start with a number!
After the first character, identifiers can contain any combination of letters,
currency characters, connecting characters, or numbers.
In practice, there is no limit to the number of characters an identifier can contain.
You can't use a Java keyword as an identifier.
Identifiers in Java are case-sensitive; foo and FOO are two different identifiers.
Source File Declaration Rules
There can be only one public class per source code file.
 If there is a public class in a file, the name of the file must match the name of the public
class. For example, a class declared as
public class Dog { }
must be in a source code file named Dog.java.
 If the class is part of a package, the package statement must be the first line in the
source code file, before any import statements that may be present.
 If there are import statements, they must go between the package statement (if there is
one) and the class declaration. If there isn't a package statement, then the import
statement(s) must be the first line(s) in the source code file.
Source File Declaration Rules (Cont.)
 If there are no package or import statements, the class declaration must be the first
line in the source code file.
 import and package statements apply to all classes within a source code file.
In other words, there's no way to declare multiple classes in a file and have
them in different packages, or use different imports.
 A file can have more than one nonpublic class.
 Files with no public classes can have a name that does not match any of the
classes in the file.
Class Declarations and Modifiers
class MyClass { }
This code compiles just fine, but you can also add modifiers before the class
declaration. Modifiers fall into two categories:
■ Access modifiers: public, protected, private.
■ Non-access modifiers (including strictfp, final, and abstract).
Interface Implementation
❑ Interfaces are contracts for what a class can do, but they say nothing about
the way in which the class must do it.
❑ Interfaces can be implemented by any class, from any inheritance tree.
❑ An interface is like a 100-percent abstract class, and is implicitly abstract
whether you type the abstract modifier in the declaration or not.
❑ An interface can have only abstract methods, no concrete methods allowed.
❑ Interface methods are by default public and abstract—explicit declaration
of these modifiers is optional.
❑ Interfaces can have constants, which are always implicitly public,
static, and final.
Interface Implementation(Cont.)
❑ Interface constant declarations of public, static, and final are optional
in any combination.
❑ A legal non abstract implementing class has the following properties:
❑ It provides concrete implementations for the interface's methods.
❑ It must follow all legal override rules for the methods it implements.
❑ It must not declare any new checked exceptions for an implementation method.
❑ It must not declare any checked exceptions that are broader than the exceptions
declared in the interface method.
❑ It may declare runtime exceptions on any interface method implementation
regardless of the interface declaration.
❑ It must maintain the exact signature (allowing for covariant returns)
and return type of the methods it implements (but does not have to
declare the exceptions of the interface).
❑ A class implementing an interface can itself be abstract.
❑ An abstract implementing class does not have to implement the interface
methods (but the first concrete subclass must).
❑ A class can extend only one class (no multiple inheritance), but it can
implement many interfaces.
❑ Interfaces can extend one or more other interfaces.
❑ Interfaces cannot extend a class, or implement a class or interface.
Interface Implementation(Cont.)
Member Access Modifiers
Methods and instance (nonlocal) variables are known as "members."
❑ Members can use all four access levels: public, protected, default, private.
❑ Member access comes in two forms:
❑ Code in one class can access a member of another class.
❑ A subclass can inherit a member of its super class.
❑ If a class cannot be accessed, its members cannot be accessed.
❑ Determine class visibility before determining member visibility.
❑ public members can be accessed by all other classes, even in other packages.
❑ If a super class member is public, the subclass inherits it—regardless of package.
Member Access Modifiers(Cont.)
❑ Members accessed without the dot operator (.) must belong to the same class.
❑ this. always refers to the currently executing object.
❑ this.aMethod() is the same as just invoking aMethod().
❑ private members can be accessed only by code in the same class.
❑ private members are not visible to subclasses, so private members cannot
be inherited.
❑ Default and protected members differ only when subclasses are involved:
❑ Default members can be accessed only by classes in the same package.
❑ protected members can be accessed by other classes in the same package, plus
subclasses regardless of package.
❑ protected = package plus kids (kids meaning subclasses).
❑ For subclasses outside the package, the protected member can be accessed only
through inheritance; a subclass outside the package cannot access a protected member
by using a reference to a super class instance (in other words, inheritance is the only
mechanism for a subclass outside the package to access a protected member of its
super class).
❑ A protected member inherited by a subclass from another package is not accessible
to any other class in the subclass package, except for the subclass' own subclasses.
Member Access Modifiers(Cont.)
Local Variables
Local (method, automatic, or stack) variable declarations cannot have access
modifiers.
❑ final is the only modifier available to local variables.
❑ Local variables don't get default values, so they must be initialized before use.
Other Modifiers Members
final methods cannot be overridden in a subclass.
❑ abstract methods are declared, with a signature, a return type, and
an optional throws clause, but are not implemented.
❑ abstract methods end in a semicolon—no curly braces.
❑ Three ways to spot a non-abstract method:
❑ The method is not marked abstract.
❑ The method has curly braces.
❑ The method has code between the curly braces.
❑ The first non abstract (concrete) class to extend an abstract class must
implement all of the abstract class' abstract methods.
❑ The synchronized modifier applies only to methods and code blocks.
❑ synchronized methods can have any access control and can also be
marked final.
❑ abstract methods must be implemented by a subclass, so they must be
inheritable. For that reason:
❑ abstract methods cannot be private.
❑ abstract methods cannot be final.
❑ The native modifier applies only to methods.
❑ The strictfp modifier applies only to classes and methods.
Other Modifiers Members (Cont.)
Methods with var-args
❑ As of Java 5, methods can declare a parameter that accepts from zero to
many arguments, a so-called var-arg method.
❑ A var-arg parameter is declared with the syntax type... name; for instance:
doStuff(int... x) { }
❑ A var-arg method can have only one var-arg parameter.
❑ In methods with normal parameters and a var-arg, the var-arg must come last.
Variable Declarations
Instance variables can
❑ Have any access control
❑ Be marked final or transient
❑ Instance variables can't be abstract, synchronized, native, or strictfp.
❑ It is legal to declare a local variable with the same name as an instance
variable; this is called "shadowing."
❑ final variables have the following properties:
❑ final variables cannot be reinitialized once assigned a value.
❑ final reference variables cannot refer to a different object once the
object has been assigned to the final variable.
Variable Declarations(Cont.)
❑ final reference variables must be initialized before the constructor
completes.
❑ There is no such thing as a final object. An object reference marked final
does not mean the object itself is immutable.
❑ The transient modifier applies only to instance variables.
❑ The volatile modifier applies only to instance variables.
Array Declarations
Arrays can hold primitives or objects, but the array itself is always an object.
❑ When you declare an array, the brackets can be to the left or right of the variable
name.
❑ It is never legal to include the size of an array in the declaration.
❑ An array of objects can hold any object that passes the IS-A (or instance of)
test for the declared type of the array. For example, if Horse extends Animal,
then a Horse object can go into an Animal array.
Static Variables and Methods
 They are not tied to any particular instance of a class.
❑ No classes instances are needed in order to use static members of the class.
❑ There is only one copy of a static variable / class and all instances share it.
❑ Static methods do not have direct access to non-static members.
References
 http://www.oracle .com
 Book: SCJP By-Kathy Sierra ,Bert Bates
THANK YOU!!!

More Related Content

What's hot

Most Asked Java Interview Question and Answer
Most Asked Java Interview Question and AnswerMost Asked Java Interview Question and Answer
Most Asked Java Interview Question and AnswerTOPS Technologies
 
Interfaces In Java
Interfaces In JavaInterfaces In Java
Interfaces In Javaparag
 
Basic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobGaruda Trainings
 
Interface in Java
Interface in JavaInterface in Java
Interface in JavaDucat India
 
Java questions for viva
Java questions for vivaJava questions for viva
Java questions for vivaVipul Naik
 
Java interview questions 2
Java interview questions 2Java interview questions 2
Java interview questions 2Sherihan Anver
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)Prof. Erwin Globio
 
Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \Pritom Chaki
 
Inheritance and its types In Java
Inheritance and its types In JavaInheritance and its types In Java
Inheritance and its types In JavaMD SALEEM QAISAR
 
EEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerEEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerJeba Moses
 
Object+oriented+programming+in+java
Object+oriented+programming+in+javaObject+oriented+programming+in+java
Object+oriented+programming+in+javaYe Win
 
Complete java&j2ee
Complete java&j2eeComplete java&j2ee
Complete java&j2eeShiva Cse
 

What's hot (20)

Most Asked Java Interview Question and Answer
Most Asked Java Interview Question and AnswerMost Asked Java Interview Question and Answer
Most Asked Java Interview Question and Answer
 
Interfaces In Java
Interfaces In JavaInterfaces In Java
Interfaces In Java
 
Basic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a job
 
Interface in Java
Interface in JavaInterface in Java
Interface in Java
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Java questions for viva
Java questions for vivaJava questions for viva
Java questions for viva
 
Unit 4 Java
Unit 4 JavaUnit 4 Java
Unit 4 Java
 
Cs8392 oops 5 units notes
Cs8392 oops 5 units notes Cs8392 oops 5 units notes
Cs8392 oops 5 units notes
 
Java interview questions 2
Java interview questions 2Java interview questions 2
Java interview questions 2
 
Packages
PackagesPackages
Packages
 
Java Object Oriented Programming
Java Object Oriented Programming Java Object Oriented Programming
Java Object Oriented Programming
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
 
Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \
 
Lecture 10
Lecture 10Lecture 10
Lecture 10
 
Inheritance and its types In Java
Inheritance and its types In JavaInheritance and its types In Java
Inheritance and its types In Java
 
EEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerEEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answer
 
core java for hadoop
core java for hadoopcore java for hadoop
core java for hadoop
 
Object+oriented+programming+in+java
Object+oriented+programming+in+javaObject+oriented+programming+in+java
Object+oriented+programming+in+java
 
Complete java&j2ee
Complete java&j2eeComplete java&j2ee
Complete java&j2ee
 

Similar to Java Basics Guide for Beginners

Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interviewKuntal Bhowmick
 
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questionsGradeup
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Fresherszynofustechnology
 
Java Interview Questions
Java Interview QuestionsJava Interview Questions
Java Interview QuestionsKuntal Bhowmick
 
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
 
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
 
1669617800196.pdf
1669617800196.pdf1669617800196.pdf
1669617800196.pdfvenud11
 
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptxINDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptxIndu65
 
Selenium Training .pptx
Selenium Training .pptxSelenium Training .pptx
Selenium Training .pptxSajidTk2
 
C# interview-questions
C# interview-questionsC# interview-questions
C# interview-questionsnicolbiden
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)Khaled Anaqwa
 

Similar to Java Basics Guide for Beginners (20)

Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
 
Core_Java_Interview.pdf
Core_Java_Interview.pdfCore_Java_Interview.pdf
Core_Java_Interview.pdf
 
1
11
1
 
Suga java training_with_footer
Suga java training_with_footerSuga java training_with_footer
Suga java training_with_footer
 
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questions
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Freshers
 
Java Interview Questions
Java Interview QuestionsJava Interview Questions
Java Interview Questions
 
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
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
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
 
Pocket java
Pocket javaPocket java
Pocket java
 
1669617800196.pdf
1669617800196.pdf1669617800196.pdf
1669617800196.pdf
 
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptxINDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
 
Selenium Training .pptx
Selenium Training .pptxSelenium Training .pptx
Selenium Training .pptx
 
C# interview-questions
C# interview-questionsC# interview-questions
C# interview-questions
 
Viva file
Viva fileViva file
Viva file
 
Java
JavaJava
Java
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
 
Csci360 20 (1)
Csci360 20 (1)Csci360 20 (1)
Csci360 20 (1)
 
Csci360 20
Csci360 20Csci360 20
Csci360 20
 

Recently uploaded

BHOPAL CALL GIRL 92628*71154 BHOPAL CALL
BHOPAL CALL GIRL 92628*71154 BHOPAL CALLBHOPAL CALL GIRL 92628*71154 BHOPAL CALL
BHOPAL CALL GIRL 92628*71154 BHOPAL CALLNiteshKumar82226
 
▶ ●─Cash On Delivery Call Girls In ( Sector 63 Noida )꧁❤⎝8375860717⎠❤꧂
▶ ●─Cash On Delivery Call Girls In ( Sector 63 Noida )꧁❤⎝8375860717⎠❤꧂▶ ●─Cash On Delivery Call Girls In ( Sector 63 Noida )꧁❤⎝8375860717⎠❤꧂
▶ ●─Cash On Delivery Call Girls In ( Sector 63 Noida )꧁❤⎝8375860717⎠❤꧂door45step
 
Hot Vip Call Girls Service In Sector 149,9818099198 Young Female Escorts Serv...
Hot Vip Call Girls Service In Sector 149,9818099198 Young Female Escorts Serv...Hot Vip Call Girls Service In Sector 149,9818099198 Young Female Escorts Serv...
Hot Vip Call Girls Service In Sector 149,9818099198 Young Female Escorts Serv...riyaescorts54
 
Call Girls In Dwarka Delhi 💯Call Us 🔝9711014705🔝
Call Girls In Dwarka Delhi 💯Call Us 🔝9711014705🔝Call Girls In Dwarka Delhi 💯Call Us 🔝9711014705🔝
Call Girls In Dwarka Delhi 💯Call Us 🔝9711014705🔝thapagita
 
(9818099198) Noida Escorts Service Sector 60 (NOIDA CALL GIRLS)
(9818099198) Noida Escorts Service Sector 60 (NOIDA CALL GIRLS)(9818099198) Noida Escorts Service Sector 60 (NOIDA CALL GIRLS)
(9818099198) Noida Escorts Service Sector 60 (NOIDA CALL GIRLS)riyaescorts54
 
Call Girls In Sector 90, (Gurgaon) Call Us. 9711911712
Call Girls In Sector 90, (Gurgaon) Call Us. 9711911712Call Girls In Sector 90, (Gurgaon) Call Us. 9711911712
Call Girls In Sector 90, (Gurgaon) Call Us. 9711911712Delhi Escorts Service
 
9643097474 Full Enjoy @24/7 Call Girls In Khirki Extension Delhi Ncr
9643097474 Full Enjoy @24/7 Call Girls In Khirki Extension Delhi Ncr9643097474 Full Enjoy @24/7 Call Girls In Khirki Extension Delhi Ncr
9643097474 Full Enjoy @24/7 Call Girls In Khirki Extension Delhi Ncrthapariya601
 
Call Girls In {Laxmi Nagar Delhi} 9667938988 Indian Russian High Profile Girl...
Call Girls In {Laxmi Nagar Delhi} 9667938988 Indian Russian High Profile Girl...Call Girls In {Laxmi Nagar Delhi} 9667938988 Indian Russian High Profile Girl...
Call Girls In {Laxmi Nagar Delhi} 9667938988 Indian Russian High Profile Girl...aakahthapa70
 
Call Girls In {Aerocity Delhi} 9667938988 Cheap Price Your Budget & Cash Payment
Call Girls In {Aerocity Delhi} 9667938988 Cheap Price Your Budget & Cash PaymentCall Girls In {Aerocity Delhi} 9667938988 Cheap Price Your Budget & Cash Payment
Call Girls In {Aerocity Delhi} 9667938988 Cheap Price Your Budget & Cash Paymentaakahthapa70
 
Genuine Call Girls In {Mahipalpur Delhi} 9667938988 Indian Russian High Profi...
Genuine Call Girls In {Mahipalpur Delhi} 9667938988 Indian Russian High Profi...Genuine Call Girls In {Mahipalpur Delhi} 9667938988 Indian Russian High Profi...
Genuine Call Girls In {Mahipalpur Delhi} 9667938988 Indian Russian High Profi...aakahthapa70
 
NAGPUR CALL GIRL 92628*71154 NAGPUR CALL
NAGPUR CALL GIRL 92628*71154 NAGPUR CALLNAGPUR CALL GIRL 92628*71154 NAGPUR CALL
NAGPUR CALL GIRL 92628*71154 NAGPUR CALLNiteshKumar82226
 
9643097474 Full Enjoy @24/7 Call Girls In Munirka Delhi Ncr
9643097474 Full Enjoy @24/7 Call Girls In Munirka Delhi Ncr9643097474 Full Enjoy @24/7 Call Girls In Munirka Delhi Ncr
9643097474 Full Enjoy @24/7 Call Girls In Munirka Delhi Ncrthapariya601
 
Call Girls In Majnu-ka-Tilla 9711800081 Low Cheap Price ...
Call Girls In Majnu-ka-Tilla 9711800081 Low Cheap Price ...Call Girls In Majnu-ka-Tilla 9711800081 Low Cheap Price ...
Call Girls In Majnu-ka-Tilla 9711800081 Low Cheap Price ...gitathapa4
 
Call Girls in Paharganj Delhi 💯 Call Us 🔝9667422720🔝
Call Girls in Paharganj Delhi 💯 Call Us 🔝9667422720🔝Call Girls in Paharganj Delhi 💯 Call Us 🔝9667422720🔝
Call Girls in Paharganj Delhi 💯 Call Us 🔝9667422720🔝Lipikasharma29
 
9899855202 Call Girls In Goa This Ads Is Only For Those Clients Who Are Looki...
9899855202 Call Girls In Goa This Ads Is Only For Those Clients Who Are Looki...9899855202 Call Girls In Goa This Ads Is Only For Those Clients Who Are Looki...
9899855202 Call Girls In Goa This Ads Is Only For Those Clients Who Are Looki...delhincr993
 
Call Girls In {Aerocity Delhi} 98733@20244 Indian Russian High Profile Girls ...
Call Girls In {Aerocity Delhi} 98733@20244 Indian Russian High Profile Girls ...Call Girls In {Aerocity Delhi} 98733@20244 Indian Russian High Profile Girls ...
Call Girls In {Aerocity Delhi} 98733@20244 Indian Russian High Profile Girls ...aakahthapa70
 
Trusted Call~Girls In Shahdara Delhi ꧁❤ 9667422720 ❤꧂Escorts
Trusted Call~Girls In Shahdara Delhi ꧁❤ 9667422720 ❤꧂EscortsTrusted Call~Girls In Shahdara Delhi ꧁❤ 9667422720 ❤꧂Escorts
Trusted Call~Girls In Shahdara Delhi ꧁❤ 9667422720 ❤꧂EscortsLipikasharma29
 
Call Girls in Majnu ka Tilla Delhi 💯 Call Us 🔝9711014705🔝
Call Girls in Majnu ka Tilla Delhi 💯 Call Us 🔝9711014705🔝Call Girls in Majnu ka Tilla Delhi 💯 Call Us 🔝9711014705🔝
Call Girls in Majnu ka Tilla Delhi 💯 Call Us 🔝9711014705🔝thapagita
 
Call Girls In Islamabad 💯Call Us 🔝03090999379🔝
Call Girls In Islamabad 💯Call Us 🔝03090999379🔝Call Girls In Islamabad 💯Call Us 🔝03090999379🔝
Call Girls In Islamabad 💯Call Us 🔝03090999379🔝Ayesha Khan
 

Recently uploaded (20)

BHOPAL CALL GIRL 92628*71154 BHOPAL CALL
BHOPAL CALL GIRL 92628*71154 BHOPAL CALLBHOPAL CALL GIRL 92628*71154 BHOPAL CALL
BHOPAL CALL GIRL 92628*71154 BHOPAL CALL
 
▶ ●─Cash On Delivery Call Girls In ( Sector 63 Noida )꧁❤⎝8375860717⎠❤꧂
▶ ●─Cash On Delivery Call Girls In ( Sector 63 Noida )꧁❤⎝8375860717⎠❤꧂▶ ●─Cash On Delivery Call Girls In ( Sector 63 Noida )꧁❤⎝8375860717⎠❤꧂
▶ ●─Cash On Delivery Call Girls In ( Sector 63 Noida )꧁❤⎝8375860717⎠❤꧂
 
Hot Vip Call Girls Service In Sector 149,9818099198 Young Female Escorts Serv...
Hot Vip Call Girls Service In Sector 149,9818099198 Young Female Escorts Serv...Hot Vip Call Girls Service In Sector 149,9818099198 Young Female Escorts Serv...
Hot Vip Call Girls Service In Sector 149,9818099198 Young Female Escorts Serv...
 
Call Girls In Dwarka Delhi 💯Call Us 🔝9711014705🔝
Call Girls In Dwarka Delhi 💯Call Us 🔝9711014705🔝Call Girls In Dwarka Delhi 💯Call Us 🔝9711014705🔝
Call Girls In Dwarka Delhi 💯Call Us 🔝9711014705🔝
 
Call Girls In Saket Delhi 9953056974 (Low Price) Escort Service Saket Delhi
Call Girls In Saket Delhi 9953056974 (Low Price) Escort Service Saket DelhiCall Girls In Saket Delhi 9953056974 (Low Price) Escort Service Saket Delhi
Call Girls In Saket Delhi 9953056974 (Low Price) Escort Service Saket Delhi
 
(9818099198) Noida Escorts Service Sector 60 (NOIDA CALL GIRLS)
(9818099198) Noida Escorts Service Sector 60 (NOIDA CALL GIRLS)(9818099198) Noida Escorts Service Sector 60 (NOIDA CALL GIRLS)
(9818099198) Noida Escorts Service Sector 60 (NOIDA CALL GIRLS)
 
Call Girls In Sector 90, (Gurgaon) Call Us. 9711911712
Call Girls In Sector 90, (Gurgaon) Call Us. 9711911712Call Girls In Sector 90, (Gurgaon) Call Us. 9711911712
Call Girls In Sector 90, (Gurgaon) Call Us. 9711911712
 
9643097474 Full Enjoy @24/7 Call Girls In Khirki Extension Delhi Ncr
9643097474 Full Enjoy @24/7 Call Girls In Khirki Extension Delhi Ncr9643097474 Full Enjoy @24/7 Call Girls In Khirki Extension Delhi Ncr
9643097474 Full Enjoy @24/7 Call Girls In Khirki Extension Delhi Ncr
 
Call Girls In {Laxmi Nagar Delhi} 9667938988 Indian Russian High Profile Girl...
Call Girls In {Laxmi Nagar Delhi} 9667938988 Indian Russian High Profile Girl...Call Girls In {Laxmi Nagar Delhi} 9667938988 Indian Russian High Profile Girl...
Call Girls In {Laxmi Nagar Delhi} 9667938988 Indian Russian High Profile Girl...
 
Call Girls In {Aerocity Delhi} 9667938988 Cheap Price Your Budget & Cash Payment
Call Girls In {Aerocity Delhi} 9667938988 Cheap Price Your Budget & Cash PaymentCall Girls In {Aerocity Delhi} 9667938988 Cheap Price Your Budget & Cash Payment
Call Girls In {Aerocity Delhi} 9667938988 Cheap Price Your Budget & Cash Payment
 
Genuine Call Girls In {Mahipalpur Delhi} 9667938988 Indian Russian High Profi...
Genuine Call Girls In {Mahipalpur Delhi} 9667938988 Indian Russian High Profi...Genuine Call Girls In {Mahipalpur Delhi} 9667938988 Indian Russian High Profi...
Genuine Call Girls In {Mahipalpur Delhi} 9667938988 Indian Russian High Profi...
 
NAGPUR CALL GIRL 92628*71154 NAGPUR CALL
NAGPUR CALL GIRL 92628*71154 NAGPUR CALLNAGPUR CALL GIRL 92628*71154 NAGPUR CALL
NAGPUR CALL GIRL 92628*71154 NAGPUR CALL
 
9643097474 Full Enjoy @24/7 Call Girls In Munirka Delhi Ncr
9643097474 Full Enjoy @24/7 Call Girls In Munirka Delhi Ncr9643097474 Full Enjoy @24/7 Call Girls In Munirka Delhi Ncr
9643097474 Full Enjoy @24/7 Call Girls In Munirka Delhi Ncr
 
Call Girls In Majnu-ka-Tilla 9711800081 Low Cheap Price ...
Call Girls In Majnu-ka-Tilla 9711800081 Low Cheap Price ...Call Girls In Majnu-ka-Tilla 9711800081 Low Cheap Price ...
Call Girls In Majnu-ka-Tilla 9711800081 Low Cheap Price ...
 
Call Girls in Paharganj Delhi 💯 Call Us 🔝9667422720🔝
Call Girls in Paharganj Delhi 💯 Call Us 🔝9667422720🔝Call Girls in Paharganj Delhi 💯 Call Us 🔝9667422720🔝
Call Girls in Paharganj Delhi 💯 Call Us 🔝9667422720🔝
 
9899855202 Call Girls In Goa This Ads Is Only For Those Clients Who Are Looki...
9899855202 Call Girls In Goa This Ads Is Only For Those Clients Who Are Looki...9899855202 Call Girls In Goa This Ads Is Only For Those Clients Who Are Looki...
9899855202 Call Girls In Goa This Ads Is Only For Those Clients Who Are Looki...
 
Call Girls In {Aerocity Delhi} 98733@20244 Indian Russian High Profile Girls ...
Call Girls In {Aerocity Delhi} 98733@20244 Indian Russian High Profile Girls ...Call Girls In {Aerocity Delhi} 98733@20244 Indian Russian High Profile Girls ...
Call Girls In {Aerocity Delhi} 98733@20244 Indian Russian High Profile Girls ...
 
Trusted Call~Girls In Shahdara Delhi ꧁❤ 9667422720 ❤꧂Escorts
Trusted Call~Girls In Shahdara Delhi ꧁❤ 9667422720 ❤꧂EscortsTrusted Call~Girls In Shahdara Delhi ꧁❤ 9667422720 ❤꧂Escorts
Trusted Call~Girls In Shahdara Delhi ꧁❤ 9667422720 ❤꧂Escorts
 
Call Girls in Majnu ka Tilla Delhi 💯 Call Us 🔝9711014705🔝
Call Girls in Majnu ka Tilla Delhi 💯 Call Us 🔝9711014705🔝Call Girls in Majnu ka Tilla Delhi 💯 Call Us 🔝9711014705🔝
Call Girls in Majnu ka Tilla Delhi 💯 Call Us 🔝9711014705🔝
 
Call Girls In Islamabad 💯Call Us 🔝03090999379🔝
Call Girls In Islamabad 💯Call Us 🔝03090999379🔝Call Girls In Islamabad 💯Call Us 🔝03090999379🔝
Call Girls In Islamabad 💯Call Us 🔝03090999379🔝
 

Java Basics Guide for Beginners

  • 1. JAVA BASICS Prepared by The Smartpath Information Systems www.thesmartpath.in
  • 2. Index 1. Java Technology 2. Java Programming 3. Java Programming (Cont.) 4. The Java Platform 5. Java Bytecode 6. Java Virtual Machine 7. Java Runtime Environment (JRE) 8. Java Software Development Kit (Java SDK) 9. Java Object-Oriented Programming Concepts 10. What Is an Object? 11. What Is a Class?
  • 3. 12. What Is Inheritance? 13. What Is an Interface? 14. What Is an Polymorphism? 15. Legal Identifiers 16. Source File Declaration Rules 17. Source File Declaration Rules (Cont.) 18. Class Declarations and Modifiers 19. Interface Implementation 20. Interface Implementation(Cont.) 21. Interface Implementation(Cont.) 22. Member Access Modifiers 23. Member Access Modifiers(Cont.) 24. Member Access Modifiers(Cont.)
  • 4. 25. Local Variables 26. Other Modifiers Members 27. Other Modifiers Members(Cont.) 28. Methods with var-args 29. Variable Declarations 30. Variable Declarations (Cont.) 31. Array Declarations 32. Static Variables and Methods 33. References
  • 5. Java Technology  Java technology is both a programming language and a platform. Simple Object oriented Distributed Multithreaded Dynamic Architecture neutral Portable High performance Robust Secure
  • 6. Java Programming  Source code is first written in plain text files ending with the .java extension.  Source files are then compiled into .class files by the javac compiler. A .class file does not contain code that is native to your processor; it instead contains bytecodes -- the machine language of the Java Virtual Machine (Java VM).  The java launcher tool then runs your application with an instance of the Java Virtual Machine.
  • 7. Java Programming (Cont.) Java VM is available on many different operating systems, the same class files are capable of running on  Microsoft Windows  the Solaris™ Operating System (Solaris OS)  Linux, or Mac OS. Etc. Through the Java VM, the same application is capable of running on multiple platforms.
  • 8. The Java Platform A platform is the hardware or software environment in which a program runs. Since Java has its own runtime environment (JRE) and API, it is called platform .The Java platform has two components: •The Java Virtual Machine •The Java Application Programming Interface (API) The API is a large collection of ready-made software components that provide many useful capabilities. It is grouped into libraries of related classes and interfaces; these libraries are known as packages.
  • 9. Java Bytecode Java programs written in the Java language are compiled into Java bytecode which can be executed by the Java Virtual Machine. The Java bytecode is stored in binary .class files.
  • 10. Java Virtual Machine Java is an interpreted language. The Java language is compiled into Java bytecode. This Java bytecode is then executed by the Java Virtual Machine. The Java Virtual Machine is like a computer. It can execute Java bytecode just like a PC can execute assembler instructions. The Java Virtual Machine is a program itself
  • 11. Java Runtime Environment (JRE) The Java Runtime Environment (JRE) is the Java Virtual Machine and the standard Java APIs coming with Java Standard Edition (JSE). The JRE contains enough to execute a Java application, but not to compile it.
  • 12. Java Software Development Kit (Java SDK) The Java Software Development Kit (Java SDK) is the JRE plus the Java compiler, and a set of other tools. If you need to develop Java programs you need the full Java SDK. The JRE is not enough then. Only the full Java SDK contains the Java compiler which turns your . java source files into byte code .class files.
  • 13. Java Object-Oriented Programming Concepts What Is an Object? What Is a Class? What Is Inheritance? What Is an Encapsulation? What Is Polymorphism? What Is an Interface? What Is an Object?
  • 14. What Is an Object? An Object is a particular concrete instance of Class. Object is real world entity, which has property and behavior Man Student Tree Car
  • 15. What is class? A class is a blueprint or prototype from which objects are created which has attributes and behavior, we call attribute as members and behavior as methods.
  • 16. What Is Inheritance? Inheritance is the process by which one object acquires the properties of another object. Inheritance provides a powerful and natural mechanism for organizing and structuring your software.
  • 17. What Is an Interface? An interface is a contract between a class and the outside world. When a class implements an interface, it promises to provide the behavior published by that interface.
  • 18. What Is an Polymorphism? Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.
  • 19. Legal Identifiers Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( _ ). Identifiers cannot start with a number! After the first character, identifiers can contain any combination of letters, currency characters, connecting characters, or numbers. In practice, there is no limit to the number of characters an identifier can contain. You can't use a Java keyword as an identifier. Identifiers in Java are case-sensitive; foo and FOO are two different identifiers.
  • 20. Source File Declaration Rules There can be only one public class per source code file.  If there is a public class in a file, the name of the file must match the name of the public class. For example, a class declared as public class Dog { } must be in a source code file named Dog.java.  If the class is part of a package, the package statement must be the first line in the source code file, before any import statements that may be present.  If there are import statements, they must go between the package statement (if there is one) and the class declaration. If there isn't a package statement, then the import statement(s) must be the first line(s) in the source code file.
  • 21. Source File Declaration Rules (Cont.)  If there are no package or import statements, the class declaration must be the first line in the source code file.  import and package statements apply to all classes within a source code file. In other words, there's no way to declare multiple classes in a file and have them in different packages, or use different imports.  A file can have more than one nonpublic class.  Files with no public classes can have a name that does not match any of the classes in the file.
  • 22. Class Declarations and Modifiers class MyClass { } This code compiles just fine, but you can also add modifiers before the class declaration. Modifiers fall into two categories: ■ Access modifiers: public, protected, private. ■ Non-access modifiers (including strictfp, final, and abstract).
  • 23. Interface Implementation ❑ Interfaces are contracts for what a class can do, but they say nothing about the way in which the class must do it. ❑ Interfaces can be implemented by any class, from any inheritance tree. ❑ An interface is like a 100-percent abstract class, and is implicitly abstract whether you type the abstract modifier in the declaration or not. ❑ An interface can have only abstract methods, no concrete methods allowed. ❑ Interface methods are by default public and abstract—explicit declaration of these modifiers is optional. ❑ Interfaces can have constants, which are always implicitly public, static, and final.
  • 24. Interface Implementation(Cont.) ❑ Interface constant declarations of public, static, and final are optional in any combination. ❑ A legal non abstract implementing class has the following properties: ❑ It provides concrete implementations for the interface's methods. ❑ It must follow all legal override rules for the methods it implements. ❑ It must not declare any new checked exceptions for an implementation method. ❑ It must not declare any checked exceptions that are broader than the exceptions declared in the interface method. ❑ It may declare runtime exceptions on any interface method implementation regardless of the interface declaration.
  • 25. ❑ It must maintain the exact signature (allowing for covariant returns) and return type of the methods it implements (but does not have to declare the exceptions of the interface). ❑ A class implementing an interface can itself be abstract. ❑ An abstract implementing class does not have to implement the interface methods (but the first concrete subclass must). ❑ A class can extend only one class (no multiple inheritance), but it can implement many interfaces. ❑ Interfaces can extend one or more other interfaces. ❑ Interfaces cannot extend a class, or implement a class or interface. Interface Implementation(Cont.)
  • 26. Member Access Modifiers Methods and instance (nonlocal) variables are known as "members." ❑ Members can use all four access levels: public, protected, default, private. ❑ Member access comes in two forms: ❑ Code in one class can access a member of another class. ❑ A subclass can inherit a member of its super class. ❑ If a class cannot be accessed, its members cannot be accessed. ❑ Determine class visibility before determining member visibility. ❑ public members can be accessed by all other classes, even in other packages. ❑ If a super class member is public, the subclass inherits it—regardless of package.
  • 27. Member Access Modifiers(Cont.) ❑ Members accessed without the dot operator (.) must belong to the same class. ❑ this. always refers to the currently executing object. ❑ this.aMethod() is the same as just invoking aMethod(). ❑ private members can be accessed only by code in the same class. ❑ private members are not visible to subclasses, so private members cannot be inherited. ❑ Default and protected members differ only when subclasses are involved: ❑ Default members can be accessed only by classes in the same package. ❑ protected members can be accessed by other classes in the same package, plus subclasses regardless of package.
  • 28. ❑ protected = package plus kids (kids meaning subclasses). ❑ For subclasses outside the package, the protected member can be accessed only through inheritance; a subclass outside the package cannot access a protected member by using a reference to a super class instance (in other words, inheritance is the only mechanism for a subclass outside the package to access a protected member of its super class). ❑ A protected member inherited by a subclass from another package is not accessible to any other class in the subclass package, except for the subclass' own subclasses. Member Access Modifiers(Cont.)
  • 29. Local Variables Local (method, automatic, or stack) variable declarations cannot have access modifiers. ❑ final is the only modifier available to local variables. ❑ Local variables don't get default values, so they must be initialized before use.
  • 30. Other Modifiers Members final methods cannot be overridden in a subclass. ❑ abstract methods are declared, with a signature, a return type, and an optional throws clause, but are not implemented. ❑ abstract methods end in a semicolon—no curly braces. ❑ Three ways to spot a non-abstract method: ❑ The method is not marked abstract. ❑ The method has curly braces. ❑ The method has code between the curly braces. ❑ The first non abstract (concrete) class to extend an abstract class must implement all of the abstract class' abstract methods.
  • 31. ❑ The synchronized modifier applies only to methods and code blocks. ❑ synchronized methods can have any access control and can also be marked final. ❑ abstract methods must be implemented by a subclass, so they must be inheritable. For that reason: ❑ abstract methods cannot be private. ❑ abstract methods cannot be final. ❑ The native modifier applies only to methods. ❑ The strictfp modifier applies only to classes and methods. Other Modifiers Members (Cont.)
  • 32. Methods with var-args ❑ As of Java 5, methods can declare a parameter that accepts from zero to many arguments, a so-called var-arg method. ❑ A var-arg parameter is declared with the syntax type... name; for instance: doStuff(int... x) { } ❑ A var-arg method can have only one var-arg parameter. ❑ In methods with normal parameters and a var-arg, the var-arg must come last.
  • 33. Variable Declarations Instance variables can ❑ Have any access control ❑ Be marked final or transient ❑ Instance variables can't be abstract, synchronized, native, or strictfp. ❑ It is legal to declare a local variable with the same name as an instance variable; this is called "shadowing." ❑ final variables have the following properties: ❑ final variables cannot be reinitialized once assigned a value. ❑ final reference variables cannot refer to a different object once the object has been assigned to the final variable.
  • 34. Variable Declarations(Cont.) ❑ final reference variables must be initialized before the constructor completes. ❑ There is no such thing as a final object. An object reference marked final does not mean the object itself is immutable. ❑ The transient modifier applies only to instance variables. ❑ The volatile modifier applies only to instance variables.
  • 35. Array Declarations Arrays can hold primitives or objects, but the array itself is always an object. ❑ When you declare an array, the brackets can be to the left or right of the variable name. ❑ It is never legal to include the size of an array in the declaration. ❑ An array of objects can hold any object that passes the IS-A (or instance of) test for the declared type of the array. For example, if Horse extends Animal, then a Horse object can go into an Animal array.
  • 36. Static Variables and Methods  They are not tied to any particular instance of a class. ❑ No classes instances are needed in order to use static members of the class. ❑ There is only one copy of a static variable / class and all instances share it. ❑ Static methods do not have direct access to non-static members.
  • 37. References  http://www.oracle .com  Book: SCJP By-Kathy Sierra ,Bert Bates