<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jeff Odhiambo</title>
    <description>The latest articles on DEV Community by Jeff Odhiambo (@smartjeff).</description>
    <link>https://dev.to/smartjeff</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F811073%2F17346198-42f1-4413-aa7f-54e45e13d499.png</url>
      <title>DEV Community: Jeff Odhiambo</title>
      <link>https://dev.to/smartjeff</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/smartjeff"/>
    <language>en</language>
    <item>
      <title>VSTech Limited: The Kenyan Tech Company Making Waves in the Industry</title>
      <dc:creator>Jeff Odhiambo</dc:creator>
      <pubDate>Sun, 22 Jan 2023 20:52:33 +0000</pubDate>
      <link>https://dev.to/smartjeff/vstech-limited-the-kenyan-tech-company-making-waves-in-the-industry-2d1d</link>
      <guid>https://dev.to/smartjeff/vstech-limited-the-kenyan-tech-company-making-waves-in-the-industry-2d1d</guid>
      <description>&lt;p&gt;VSTech Limited is a technology company based in Kenya that is quickly making a name for itself in the industry. Founded in October 2022, the company has a strong focus on developing innovative solutions for a wide range of industries. With a range of services including web app development, support and maintenance, e-learning and training, hosting services, consultation services, mobile app development, and software development, VSTech Limited is a one-stop-shop for all your tech needs. You can find more information on the services provided by VSTech Limited on the website &lt;a href="https://vstech.co.ke/services/" rel="noopener noreferrer"&gt;https://vstech.co.ke/services/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One of the main areas of expertise for VSTech Limited is web app development. The company has a team of highly skilled engineers and developers who specialize in building custom web applications that are tailored to meet the unique needs of each client. Whether you're looking for an e-commerce platform, a content management system, or a custom application to streamline your business processes, VSTech Limited has the skills and experience to deliver.&lt;/p&gt;

&lt;p&gt;In addition to web app development, VSTech Limited also offers support and maintenance services to ensure that your applications are always running smoothly. This includes everything from bug fixes and updates to security patches and performance enhancements.&lt;/p&gt;

&lt;p&gt;VSTech Limited also offers e-learning and training services, which can help organizations to improve their employees' skills and knowledge. The company has developed a range of customized e-learning courses that can be tailored to meet the specific needs of each client.&lt;/p&gt;

&lt;p&gt;The company also provides hosting services and consultation services to ensure that your online presence is always up and running. VSTech Limited's hosting services are highly scalable and secure, making it ideal for businesses of all sizes.&lt;/p&gt;

&lt;p&gt;Mobile app development is also another area of expertise for VSTech Limited. The company's team of experienced engineers and designers have extensive experience in developing mobile apps for iOS and Android platforms, which can help businesses to reach a wider audience and improve customer engagement.&lt;/p&gt;

&lt;p&gt;In addition to these core areas of expertise, VSTech Limited is also working on a number of other projects. The company offers software development services, which can help organizations to automate their business processes and improve efficiency.&lt;/p&gt;

&lt;p&gt;Despite being a relatively new company, VSTech Limited has already made a big impact in the tech industry in Kenya.&lt;/p&gt;

&lt;p&gt;Looking ahead, VSTech Limited has ambitious plans for the future. The company intends to continue developing new and innovative technologies, and it plans to expand its business into new markets and industries. With a talented team of engineers and a clear vision for the future, there is no doubt that VSTech Limited will continue to be a major player in the Kenyan tech industry for years to come.&lt;/p&gt;

&lt;p&gt;VSTech Limited welcomes suggestions and inquiries. You can find their contact information on their website &lt;a href="https://vstech.co.ke/contact/" rel="noopener noreferrer"&gt;https://vstech.co.ke/contact/&lt;/a&gt; .You can also reach them via email at &lt;a href="mailto:info@vstech.co.ke"&gt;info@vstech.co.ke&lt;/a&gt; or &lt;a href="mailto:support@vstech.co.ke"&gt;support@vstech.co.ke&lt;/a&gt; and by phone at +254202346703&lt;/p&gt;

</description>
      <category>community</category>
      <category>welcome</category>
      <category>forem</category>
    </item>
    <item>
      <title>Python - JavaScript Training</title>
      <dc:creator>Jeff Odhiambo</dc:creator>
      <pubDate>Mon, 05 Sep 2022 06:17:04 +0000</pubDate>
      <link>https://dev.to/smartjeff/python-javascript-training-3073</link>
      <guid>https://dev.to/smartjeff/python-javascript-training-3073</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YJNwRQ5p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ps28gmi94fmzmf3np7hw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YJNwRQ5p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ps28gmi94fmzmf3np7hw.png" alt="Poster" width="880" height="1245"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://posts.gle/VwV288"&gt;VSTech Academy&lt;/a&gt; will be offering free Python - JavaScript training that will include both the basics and advanced concepts of Python and JavaScript. During this period the students will undertake and submit the assigned projects every week. They will also do technical writing on the sections they've learnt and share. The writing will be done here in dev.to. Instructions on how to submit the projects will be provided in the project description.&lt;br&gt;
At the end of training(31st November) the successful students will be awarded certificates&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You are all invited&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://posts.gle/VwV288"&gt;SignUp&lt;/a&gt;&lt;/strong&gt; for the event.&lt;br&gt;
You can &lt;strong&gt;&lt;a href="https://forms.gle/29UL78zTYkfb2oXY7"&gt;verify&lt;/a&gt;&lt;/strong&gt; to check if you already signed.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>python</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Java for Beginners Full Course</title>
      <dc:creator>Jeff Odhiambo</dc:creator>
      <pubDate>Mon, 07 Mar 2022 19:08:03 +0000</pubDate>
      <link>https://dev.to/smartjeff/java-for-beginners-full-course-315l</link>
      <guid>https://dev.to/smartjeff/java-for-beginners-full-course-315l</guid>
      <description>&lt;h2&gt;
  
  
  What is JAVA?
&lt;/h2&gt;

&lt;p&gt;Java is a high-level, third generation programming language, like C,C++, Perl, and many others. You can use Java to write computer applications that play games, store data etc. Compared to other programming languages, Java is most similar to C++.&lt;br&gt;
What's special about Java in relation to other programming languages is that it lets you write special programs called &lt;strong&gt;applets&lt;/strong&gt; that can be downloaded from the Internet and played safely within a web browser.&lt;/p&gt;
&lt;h2&gt;
  
  
  History
&lt;/h2&gt;

&lt;p&gt;Java is an object-oriented programming language created by &lt;strong&gt;James Gosling&lt;/strong&gt; from &lt;strong&gt;Sun Microsystems (Sun)&lt;/strong&gt; in &lt;strong&gt;1991&lt;/strong&gt;. The first publicly available version of Java (Java 1.0) was released in 1995.&lt;br&gt;
Sun Microsystems was acquired by the Oracle Corporation in 2010.&lt;br&gt;
Over time new enhanced versions of Java have been released. The current version of Java is Java 8.&lt;br&gt;
From the Java programming language, the Java platform evolved. The Java platform is usually associated with the Java virtual machine and the Java core libraries.&lt;br&gt;
In 2006, Sun started to make Java available under the GNU General Public License (GPL).&lt;/p&gt;
&lt;h2&gt;
  
  
  The Java compiler
&lt;/h2&gt;

&lt;p&gt;A compiler is a program that converts a high-level language to a machine language, i.e. from source code to binary code.&lt;br&gt;
When you program from the Java platform, you write source code with a &lt;code&gt;.java&lt;/code&gt; file extension and then compile them. The java compiler converts high-level java code into bytecode.&lt;br&gt;
The compiler checks your code against the language's syntax rules, then writes out bytecodes in a &lt;code&gt;.class&lt;/code&gt; files. Bytecodes are standard instructions targeted to run on a Java virtual machine (JVM).&lt;br&gt;
In adding this level of abstraction, the Java compiler differs from other language compilers, which write out instructions suitable for the CPU chipset the program will run on.&lt;br&gt;
An interpreter is a program that translates or converts a high-level language to a machine-language line by line. In Java, the Just In Time Code generator converts the bytecode into the native machine code which are at the same programming levels. Hence java is both compiled as well as an interpreted language.&lt;/p&gt;
&lt;h2&gt;
  
  
  Java virtual machine(JVM)
&lt;/h2&gt;

&lt;p&gt;Java programs are compiled by the Java compiler into bytecode. The JVM is a software implementation of a computer that executes programs like a real machine. At run time, the JVM reads and interprets a &lt;code&gt;.class&lt;/code&gt; files and executes the program's instructions on the native hardware platform for which the JVM was written. The Java virtual machine is written specifically for a specific operating system, e.g., for &lt;code&gt;Linux&lt;/code&gt; a special implementation is required as well as for &lt;code&gt;Windows&lt;/code&gt;.&lt;br&gt;
The JVM is the heart of the Java language's &lt;strong&gt;"write-once, run-anywhere"&lt;/strong&gt; principle. Your code can run on any chipset for which a suitable JVM implementation is available. JVMs are available for major platforms like Linux and Windows, and subsets of the Java language have been implemented in JVMs for mobile phones and hobbyist chips.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5vyla9th2neiz6hjf5pc.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5vyla9th2neiz6hjf5pc.PNG" alt="JVM"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  What are the tasks of JVM?
&lt;/h3&gt;

&lt;p&gt;JVM performs byte-code interpretation, garbage collection, exception handling, thread management, initialization of variables, and type definition.&lt;/p&gt;
&lt;h2&gt;
  
  
  Java platform
&lt;/h2&gt;

&lt;p&gt;The Java platform is the name given to the computing platform from Oracle that helps users to run and develop Java applications. The platform does not just enable a user to run and develop Java applications but also features a wide variety of tools that can help developers work efficiently with the Java programming language. The platform consists of two essential components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Java Runtime Environment (JRE)&lt;/strong&gt;, which is needed to run Java applications and applets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Java Development Kit (JDK)&lt;/strong&gt;, which is needed to develop those Java applications and applets. If you have installed the JDK, it comes equipped with a JRE as well.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When installed on a computer the &lt;strong&gt;JRE&lt;/strong&gt; provides the operating system with the means to run Java programs, whereas the &lt;strong&gt;JDK&lt;/strong&gt; is a collection of tools used by a programmer to create Java applications. &lt;br&gt;
The JDK has as its primary components a collection of programming tools, including:&lt;/p&gt;
&lt;h3&gt;
  
  
  Basic Tools
&lt;/h3&gt;

&lt;p&gt;These tools are the foundation of the JDK. They are the tools you use to create and build applications.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;appletviewer&lt;/strong&gt; - Run and debug applets without a web browser.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;apt&lt;/strong&gt; - Annotation processing tool.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;extcheck&lt;/strong&gt; - Utility to detect Jar conflicts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;jar&lt;/strong&gt;   - Create and manage Java Archive (JAR) files.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;java&lt;/strong&gt; - The launcher for Java applications. The old deployment launcher, JRE, is no longer provided.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;javac&lt;/strong&gt; - The compiler for the Java programming language.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;javadoc&lt;/strong&gt; - API documentation generator.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;javah&lt;/strong&gt; - C header and stub generator. Used to write native methods.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;javap&lt;/strong&gt; - Class file disassembler&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;jdb&lt;/strong&gt;   - The Java Debugger. See &lt;a href="https://docs.oracle.com/javase/7/docs/technotes/guides/jpda/index.html" rel="noopener noreferrer"&gt;JPDA&lt;/a&gt; for the debugger architecture specifications.
###Security Tools
These security tools help you set security policies on your system and create applications that can work within the scope of security policies set at remote sites.
&lt;strong&gt;keytool&lt;/strong&gt; - Manage keystores and certificates.
&lt;strong&gt;jarsigner&lt;/strong&gt; - Generate and verify JAR signatures.
&lt;strong&gt;policytool&lt;/strong&gt; - GUI tool for managing policy files.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://docs.oracle.com/javase/7/docs/technotes/tools/" rel="noopener noreferrer"&gt;More&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Characteristics of Java
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Object Oriented&lt;/strong&gt;&lt;br&gt;
In Java, everything is an Object. Java can be easily extended since it is based on the Object model.&lt;br&gt;
&lt;strong&gt;Simple&lt;/strong&gt;&lt;br&gt;
Java is designed to be easy to learn. If you understand the basic concept of OOP Java, it would be easy to master.&lt;br&gt;
&lt;strong&gt;Platform Independent&lt;/strong&gt;&lt;br&gt;
When Java is compiled, it is not compiled into platform-specific machine, rather into platform-independent byte code. This byte code is distributed over the web and interpreted by the Virtual Machine (JVM) on whichever platform it is being run on.&lt;br&gt;
&lt;strong&gt;Secure&lt;/strong&gt;&lt;br&gt;
With Java's secure feature it enables to develop virus-free, tamper-free systems. Authentication techniques are based on public-key encryption.&lt;br&gt;
&lt;strong&gt;Portable&lt;/strong&gt;&lt;br&gt;
Being architecture-neutral and having no implementation-dependent aspects of the specification makes Java portable. &lt;br&gt;
&lt;strong&gt;Multithreaded&lt;/strong&gt;&lt;br&gt;
With Java's multithreaded feature it is possible to write programs that can perform many tasks simultaneously. This design feature allows the developers to construct interactive applications that can run smoothly.&lt;br&gt;
&lt;strong&gt;Architecture-neutral&lt;/strong&gt;&lt;br&gt;
Java compiler generates an architecture-neutral object file format, which makes the compiled code executable on many processors, with the presence of Java runtime system.&lt;br&gt;
&lt;strong&gt;Interpreted&lt;/strong&gt;&lt;br&gt;
Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development process is more rapid and analytical since the linking is an incremental and lightweight process.&lt;br&gt;
&lt;strong&gt;Dynamic&lt;/strong&gt;&lt;br&gt;
Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment. Java programs can carry an extensive amount of run-time information that can be used to verify and resolve accesses to objects at run-time.&lt;br&gt;
&lt;strong&gt;High Performance&lt;/strong&gt;&lt;br&gt;
With the use of Just-In-Time compilers, Java enables high performance.&lt;br&gt;
&lt;strong&gt;Distributed&lt;/strong&gt;&lt;br&gt;
Java is designed for the distributed environment of the internet.&lt;/p&gt;
&lt;h2&gt;
  
  
  Development process with java
&lt;/h2&gt;

&lt;p&gt;Java source files are written as plain text documents. The programmer typically writes Java source code in an Integrated Development Environment (IDE) for programming. An IDE supports the programmer in the task of writing code, e.g., it &lt;code&gt;provides auto-formatting&lt;/code&gt; of the source code, &lt;code&gt;highlighting of the important keywords&lt;/code&gt;, etc. At some point, the programmer (or the IDE) calls the Java compiler (javac). The Java compiler creates the bytecode instructions. These instructions are stored in a &lt;code&gt;.class&lt;/code&gt; file and can be executed by the Java Virtual Machine.&lt;/p&gt;
&lt;h2&gt;
  
  
  Garbage collector
&lt;/h2&gt;

&lt;p&gt;The JVM automatically recollects or reclaims the memory which is not in use by the program. The Java garbage collector checks all object references and finds the objects which can be automatically released. While the garbage collector relieves the programmer from the need to explicitly manage memory, the programmer still needs to ensure that he does not keep unneeded object references, otherwise the garbage collector cannot release the associated memory.&lt;br&gt;
Keeping unneeded object references is typically called &lt;strong&gt;memory leaks&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Classpath
&lt;/h2&gt;

&lt;p&gt;The classpath defines where the Java compiler and Java runtime look for a &lt;code&gt;.class&lt;/code&gt; files to load. These instructions can be used in the Java program. For example, if you want to use an external Java library you have to add this library to your classpath to use it in your program. Java is case-sensitive, e.g., variables called jeff and Jeff are treated as different variables&lt;/p&gt;
&lt;h2&gt;
  
  
  Java Development Tools
&lt;/h2&gt;

&lt;p&gt;Java source files are written as plain text documents. The programmer writes Java source code in an Integrated Development Environment(IDE) for programming. An &lt;strong&gt;integrated development environment (IDE) or interactive development&lt;br&gt;
environment&lt;/strong&gt; is a software application that provides comprehensive facilities for programmers to use for software development. An &lt;strong&gt;IDE&lt;/strong&gt; normally consists of a &lt;code&gt;source code editor&lt;/code&gt;, &lt;code&gt;build automation tools&lt;/code&gt;, and &lt;code&gt;a debugger&lt;/code&gt;.&lt;br&gt;
Several modern IDEs integrate with Intelli-sense coding features. An IDE also supports the programmer in the task of writing code, e.g., it provides auto-formatting of the source code, highlighting of the important keywords, etc.&lt;br&gt;
Common Java IDE Tools include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IntelliJ IDEA &lt;/li&gt;
&lt;li&gt;Eclipse Java development tools (JDT)&lt;/li&gt;
&lt;li&gt;JCreator — Java IDE&lt;/li&gt;
&lt;li&gt;Java-Editor&lt;/li&gt;
&lt;li&gt;NetBeans IDE among others&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;How do you know that you have java installed? How do you install Java? How do you write, compile and run a java code?&lt;br&gt;
We will perform all these in a few minutes.&lt;/p&gt;
&lt;h2&gt;
  
  
  Check installation
&lt;/h2&gt;

&lt;p&gt;To run Java programs on your computer you must at least have the Java runtime environment (JRE) installed. This might already be the case on your machine. You can test if the JRE is installed and in your current path by opening a terminal or cmd in windows&lt;code&gt;(Win+R, enter cmd and press Enter)&lt;/code&gt; and by typing in the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;java &lt;span class="nt"&gt;-version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the JRE is installed and within your path, this command will print information about your Java installation as shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;C:&lt;span class="se"&gt;\U&lt;/span&gt;sers&lt;span class="se"&gt;\p&lt;/span&gt;rof&amp;gt;java &lt;span class="nt"&gt;-version&lt;/span&gt;
java version &lt;span class="s2"&gt;"17.0.2"&lt;/span&gt; 2022-01-18 LTS
Java&lt;span class="o"&gt;(&lt;/span&gt;TM&lt;span class="o"&gt;)&lt;/span&gt; SE Runtime Environment &lt;span class="o"&gt;(&lt;/span&gt;build 17.0.2+8-LTS-86&lt;span class="o"&gt;)&lt;/span&gt;
Java HotSpot&lt;span class="o"&gt;(&lt;/span&gt;TM&lt;span class="o"&gt;)&lt;/span&gt; 64-Bit Server VM &lt;span class="o"&gt;(&lt;/span&gt;build 17.0.2+8-LTS-86, mixed mode, sharing&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the command line returns the information that the program could not be found, you have to install Java.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to install java on Ubuntu or any UNIX system
&lt;/h2&gt;

&lt;p&gt;On Ubuntu, you can install the latest Java through the terminal by writing the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;openjdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or you can specify the version, e.g for Java 7 we can use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;openjdk-7-jdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to install Java on Windows
&lt;/h2&gt;

&lt;p&gt;For Windows, Oracle provides a native installer which can be found on the Oracle website. The central website for installing Java is located under the following URL which also contains instructions on how to install&lt;br&gt;
Java for other platforms. &lt;a href="//java.com"&gt;java.com&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What to do if you come across an installation problem
&lt;/h2&gt;

&lt;p&gt;If you have problems installing Java on your system, search via Google for &lt;code&gt;How to install JDK on &amp;lt;YOUR_OS&amp;gt;&lt;/code&gt;. This should result in helpful links. Replace &lt;code&gt;&amp;lt;YOUR_OS&amp;gt;&lt;/code&gt; with your operating system, e.g., &lt;code&gt;Windows&lt;/code&gt;, &lt;code&gt;Ubuntu&lt;/code&gt;, &lt;code&gt;Mac OSX&lt;/code&gt;, etc.&lt;br&gt;
For instance, if having problem in installing Java on windows &lt;br&gt;
Search &lt;code&gt;How to install java on windows&lt;/code&gt; which will result to  &lt;a href="https://www.google.com/search?q=How+to+install+java+on+windows" rel="noopener noreferrer"&gt;results&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Validate installation
&lt;/h2&gt;

&lt;p&gt;After installation, you can confirm if Java is correctly installed by running &lt;code&gt;java -version&lt;/code&gt; on your terminal or cmd.&lt;br&gt;
If successful the output will be similar to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;C:&lt;span class="se"&gt;\U&lt;/span&gt;sers&lt;span class="se"&gt;\p&lt;/span&gt;rof&amp;gt;java &lt;span class="nt"&gt;-version&lt;/span&gt;
java version &lt;span class="s2"&gt;"17.0.2"&lt;/span&gt; 2022-01-18 LTS
Java&lt;span class="o"&gt;(&lt;/span&gt;TM&lt;span class="o"&gt;)&lt;/span&gt; SE Runtime Environment &lt;span class="o"&gt;(&lt;/span&gt;build 17.0.2+8-LTS-86&lt;span class="o"&gt;)&lt;/span&gt;
Java HotSpot&lt;span class="o"&gt;(&lt;/span&gt;TM&lt;span class="o"&gt;)&lt;/span&gt; 64-Bit Server VM &lt;span class="o"&gt;(&lt;/span&gt;build 17.0.2+8-LTS-86, mixed mode, sharing&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How can you tell you are using a 32-bit or 64-bit version of Java?
&lt;/h2&gt;

&lt;p&gt;You can run a 32b-it or a 64-bit version of Java on a 64-bit system. If you use &lt;code&gt;java -version&lt;/code&gt; and the output contains the "64-Bit" string, then you are using the 64-bit version of Java otherwise you are using the 32-bit version. &lt;br&gt;
The following is the output of a 64-bit version.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;C:&lt;span class="se"&gt;\U&lt;/span&gt;sers&lt;span class="se"&gt;\p&lt;/span&gt;rof&amp;gt;java &lt;span class="nt"&gt;-version&lt;/span&gt;
java version &lt;span class="s2"&gt;"17.0.2"&lt;/span&gt; 2022-01-18 LTS
Java&lt;span class="o"&gt;(&lt;/span&gt;TM&lt;span class="o"&gt;)&lt;/span&gt; SE Runtime Environment &lt;span class="o"&gt;(&lt;/span&gt;build 17.0.2+8-LTS-86&lt;span class="o"&gt;)&lt;/span&gt;
Java HotSpot&lt;span class="o"&gt;(&lt;/span&gt;TM&lt;span class="o"&gt;)&lt;/span&gt; 64-Bit Server VM &lt;span class="o"&gt;(&lt;/span&gt;build 17.0.2+8-LTS-86, mixed mode, sharing&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Writing, compiling, and running a Java program
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Write source code
&lt;/h3&gt;

&lt;p&gt;To create Java programs, use any text editor such as Notepad, WordPad, or gedit in ubux/Linux. After creation, save the file with &lt;code&gt;.Java&lt;/code&gt; file extension. Example: Create file &lt;code&gt;HelloWorld.java&lt;/code&gt; then write the following source code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Simplest Java program&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HelloWorld&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello World"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations, you just created your first java source file.&lt;br&gt;
The above Java program can be developed under Linux/Windows using a text editor and the command line. Select or create a new directory in Windows which will be used for your Java development. In this description, the path &lt;code&gt;C:\Users\prof\Desktop\javalessons&lt;/code&gt; is used.&lt;br&gt;
On Linux, you might see &lt;code&gt;\home\&amp;lt;name&amp;gt;\javalessons&lt;/code&gt; but this will depend on how you named your folder and the location of the folder.&lt;br&gt;
We will ignore the first file you created.&lt;br&gt;
Once done creating a directory, open a text editor which supports plain text, e.g., gedit in Linux or&lt;br&gt;
Notepad in Windows and write the following source code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Simplest Java program&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HelloWorld&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello World, Thanks for reading this article. Did you find it useful"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the source code in your javadir directory(my case it's, &lt;em&gt;C:\Users\prof\Desktop\javalessons&lt;/em&gt;) with the &lt;code&gt;HelloWorld.java&lt;/code&gt; filename. The name of a Java source file must always be the same as the class name(within the source code) and end with the &lt;code&gt;.java&lt;/code&gt; extension. In this example, the filename must be &lt;code&gt;HelloWorld.java&lt;/code&gt;, because the class is called &lt;code&gt;HelloWorld&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Compiling and Running Java Programs
&lt;/h3&gt;

&lt;p&gt;Open a terminal or command line. Switch to the javadir directory using the command &lt;code&gt;cd javadir&lt;/code&gt;, e.g, in the above example  I'll use &lt;code&gt;cd C:\Users\prof\Desktop\javalessons&lt;/code&gt; command to change directory to where the file is located.&lt;br&gt;
Then use the &lt;code&gt;dir&lt;/code&gt; command (ls in Linux) to verify that the source file is in the directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;C:&lt;span class="se"&gt;\U&lt;/span&gt;sers&lt;span class="se"&gt;\p&lt;/span&gt;rof&amp;gt;cd C:&lt;span class="se"&gt;\U&lt;/span&gt;sers&lt;span class="se"&gt;\p&lt;/span&gt;rof&lt;span class="se"&gt;\D&lt;/span&gt;esktop&lt;span class="se"&gt;\j&lt;/span&gt;avalessons

C:&lt;span class="se"&gt;\U&lt;/span&gt;sers&lt;span class="se"&gt;\p&lt;/span&gt;rof&lt;span class="se"&gt;\D&lt;/span&gt;esktop&lt;span class="se"&gt;\j&lt;/span&gt;avalessons&amp;gt;dir

05/03/2022  14:54    &amp;lt;DIR&amp;gt;          &lt;span class="nb"&gt;.&lt;/span&gt;
05/03/2022  14:54    &amp;lt;DIR&amp;gt;          ..
05/03/2022  14:54               151 HelloWorld.java
               1 File&lt;span class="o"&gt;(&lt;/span&gt;s&lt;span class="o"&gt;)&lt;/span&gt;            151 bytes

C:&lt;span class="se"&gt;\U&lt;/span&gt;sers&lt;span class="se"&gt;\p&lt;/span&gt;rof&lt;span class="se"&gt;\D&lt;/span&gt;esktop&lt;span class="se"&gt;\j&lt;/span&gt;avalessons&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To compile the source code file into a class file, use the &lt;code&gt;javac&lt;/code&gt; command. For example, the following command compiles &lt;code&gt;HelloWorld.java&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;javac HelloWorld.java
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Afterward, list again the content of the directory with the &lt;code&gt;ls&lt;/code&gt; or &lt;code&gt;dir&lt;/code&gt; command. The directory contains now a file &lt;code&gt;HelloWorld.class&lt;/code&gt;. If you see this file, you have successfully compiled your first Java source code into bytecode.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;C:&lt;span class="se"&gt;\U&lt;/span&gt;sers&lt;span class="se"&gt;\p&lt;/span&gt;rof&lt;span class="se"&gt;\D&lt;/span&gt;esktop&lt;span class="se"&gt;\j&lt;/span&gt;avalessons&amp;gt;javac HelloWorld.java

C:&lt;span class="se"&gt;\U&lt;/span&gt;sers&lt;span class="se"&gt;\p&lt;/span&gt;rof&lt;span class="se"&gt;\D&lt;/span&gt;esktop&lt;span class="se"&gt;\j&lt;/span&gt;avalessons&amp;gt;dir

05/03/2022  15:04    &amp;lt;DIR&amp;gt;          &lt;span class="nb"&gt;.&lt;/span&gt;
05/03/2022  15:04    &amp;lt;DIR&amp;gt;          ..
05/03/2022  15:04               425 HelloWorld.class
05/03/2022  14:54               151 HelloWorld.java
               2 File&lt;span class="o"&gt;(&lt;/span&gt;s&lt;span class="o"&gt;)&lt;/span&gt;            576 bytes

C:&lt;span class="se"&gt;\U&lt;/span&gt;sers&lt;span class="se"&gt;\p&lt;/span&gt;rof&lt;span class="se"&gt;\D&lt;/span&gt;esktop&lt;span class="se"&gt;\j&lt;/span&gt;avalessons&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can now start to run your compiled Java program. Ensure that you are still in the &lt;code&gt;jardir&lt;/code&gt; directory.&lt;br&gt;
To run, use the java command. For example, the command &lt;code&gt;java HelloWorld&lt;/code&gt; will display &lt;code&gt;Hello World, Thanks for reading this article. Did you find it useful?&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;C:&lt;span class="se"&gt;\U&lt;/span&gt;sers&lt;span class="se"&gt;\p&lt;/span&gt;rof&lt;span class="se"&gt;\D&lt;/span&gt;esktop&lt;span class="se"&gt;\j&lt;/span&gt;avalessons&amp;gt;java HelloWorld
Hello World, Thanks &lt;span class="k"&gt;for &lt;/span&gt;reading this article. Did you find it useful?

C:&lt;span class="se"&gt;\U&lt;/span&gt;sers&lt;span class="se"&gt;\p&lt;/span&gt;rof&lt;span class="se"&gt;\D&lt;/span&gt;esktop&lt;span class="se"&gt;\j&lt;/span&gt;avalessons&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using the classpath
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Common Error when compiling programs is:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu4lfren3hvb622hifqpt.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu4lfren3hvb622hifqpt.PNG" alt="Error"&gt;&lt;/a&gt;&lt;br&gt;
To solve the problem, set the classpath in the environmental variables as follows:&lt;/p&gt;
&lt;h3&gt;
  
  
  Classpath
&lt;/h3&gt;

&lt;p&gt;The classpath defines where the Java compiler and Java runtime look for &lt;code&gt;.class&lt;/code&gt; files to load. These instructions can be used in the Java program. You can use the classpath to run the program from another place in your directory.&lt;/p&gt;
&lt;h3&gt;
  
  
  Configure classpath in Java environment on Windows (Windows10)
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Click on the Start menu&lt;/li&gt;
&lt;li&gt;Search Advanced System setting
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuonl0pfclvxr4lps595h.png" alt="Advance system setting"&gt;
&lt;/li&gt;
&lt;li&gt;Click on Environment Variables, under System Variables, find path, and click on it.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmzngy4gcyv936qiye86l.PNG" alt="system variables"&gt;
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr80iinbyjsvvzjaths38.PNG" alt="Path"&gt;
&lt;/li&gt;
&lt;li&gt;In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value .e.g PATH= C:\ProgramFiles\Java\jdk1.7.0_45\bin.
In my case, it is already configured.&lt;/li&gt;
&lt;li&gt;Reopen Command prompt window, and run your java code using the &lt;code&gt;javac&lt;/code&gt; command.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Java Fundamentals
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Java Input/Output
&lt;/h3&gt;

&lt;p&gt;Java uses streams to perform input and output. A &lt;strong&gt;stream&lt;/strong&gt; can be defined as a sequence of data. All streams represent an input source and an output destination.&lt;br&gt;
Java uses the &lt;strong&gt;InputStream&lt;/strong&gt; to read data from a source and the &lt;strong&gt;OutputStream&lt;/strong&gt; is used for writing data to a destination.&lt;br&gt;
The JDK has two sets of I/O packages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Standard I/O (in package java.io), introduced since JDK 1.0 for stream-based I/O.&lt;/li&gt;
&lt;li&gt;The New I/O (in packages java.nio), introduced in JDK 1.4, for more efficient buffer-based I/O.
###Console Output
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;print&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello "&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"world"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Console Input
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;BufferedReader&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BufferedReader&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;InputStreamReader&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;in&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;readLine&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  GUI Input
&lt;/h3&gt;

&lt;p&gt;GUI input and output is performed using the JOptionPane class of package &lt;code&gt;javax.swing&lt;/code&gt;&lt;br&gt;
&lt;code&gt;String name = JOptionPane.showInputDialog(null, "What's your name?");&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4z76ne0zrgs5ci7cr90w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4z76ne0zrgs5ci7cr90w.png" alt="Output"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  GUI Output
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;JOptionPane.showMessageDialog(null,"Welcome to Java Programming");&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9nm804t4yrm49xb67los.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9nm804t4yrm49xb67los.png" alt="Output"&gt;&lt;/a&gt;&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;javax.swing.*&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;JOptionPaneTest1&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;ans&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;ans&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;JOptionPane&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;showInputDialog&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Speed in miles per hour?"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;mph&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Double&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;parseDouble&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ans&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;kph&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;1.621&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;mph&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;JOptionPane&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;showMessageDialog&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"KPH = "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;kph&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;exit&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjtmu9kocrqz4eknjzgp5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjtmu9kocrqz4eknjzgp5.png" alt="Question image"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fseere7cf0fjfk8lr04wq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fseere7cf0fjfk8lr04wq.png" alt="Answer image"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  File Output
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;        &lt;span class="nc"&gt;PrintWriter&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PrintWriter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FileWriter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/home/jeff/Desktop/Notes-1.pdf\n"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
        &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;print&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello "&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"world"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;close&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  File Input
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt; &lt;span class="nc"&gt;BufferedReader&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BufferedReader&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FileReader&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/home/jeff/Desktop/Notes-1.pdf"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;readLine&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;in&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;close&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Converting input data
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;readLine&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;parseInt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Double&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;parseDouble&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Reading until EOF&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while (in.ready()) {
    text = in.readLine();
    System.out.println(text);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Variables:
&lt;/h3&gt;

&lt;p&gt;Variables are named memory locations that store data to be used in a program.&lt;br&gt;
Variables maintain the state of your application, and enable the user to manage data. The values stored in variables may change during program execution.&lt;/p&gt;
&lt;h3&gt;
  
  
  Identifier:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;These are variable names.&lt;/strong&gt; Variable name is a name given to memory cells location of a computer where data is stored. You can use any combination of those&lt;br&gt;
characters as long as the name doesn’t begin with a number. Identifier is the name of a variable that is made up from combination of alphabets, digits and underscore.&lt;/p&gt;
&lt;h3&gt;
  
  
  Rules for naming varibales:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Variable names may contain only letters, numbers, underscores.&lt;/li&gt;
&lt;li&gt;Should not begin with a number. First character should be letter or alphabet.&lt;/li&gt;
&lt;li&gt;Keywords are not allowed to be used as a variable name.&lt;/li&gt;
&lt;li&gt;White space is not allowed.&lt;/li&gt;
&lt;li&gt;Java is case sensitive i.e. UPPER and lower case are significant.&lt;/li&gt;
&lt;li&gt;Special characters such as space etc not allowed.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Keywords
&lt;/h3&gt;

&lt;p&gt;Keywords are the system defined identifiers. All keywords have predefined meanings. White spaces are not allowed in keywords. Keyword should not be used as an identifier.&lt;/p&gt;
&lt;h3&gt;
  
  
  Common java keywords include:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;abstract&lt;/strong&gt; - Indicates that the details of a class, a method, or an interface are given elsewhere in&lt;/li&gt;
&lt;li&gt;the code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;assert&lt;/strong&gt; - Tests the truth of a condition that the programmer believes is true.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;boolean&lt;/strong&gt; - Indicates that a value is either true or false.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;break&lt;/strong&gt; - Jumps out of a loop or switch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;byte&lt;/strong&gt; - Indicates that a value is an 8-bit whole number.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;case&lt;/strong&gt; - Introduces one of several possible paths of execution in a switch statement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;catch&lt;/strong&gt; - Introduces statements that are executed when something interrupts the flow of execution in a try clause.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;char&lt;/strong&gt; - Indicates that a value is a character (a single letter, digit, punctuation symbol, and so on).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;class&lt;/strong&gt; - Introduces a class(a blueprint for an object).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;continue&lt;/strong&gt; - Forces the abrupt end of the current loop iteration and begins another iteration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;default&lt;/strong&gt; - Introduces a path of execution to take when no case is a match in a switch statement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;do&lt;/strong&gt; Causes the computer to repeat some statements over and over again (for example, as long as the computer keeps getting unacceptable results).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;double&lt;/strong&gt; - Indicates that a value is a 64-bit number with one or more digits after the decimal point.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;else&lt;/strong&gt; - Introduces statements that are executed when the condition in an if statement isn’t true.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;enum&lt;/strong&gt; - Creates a newly defined type(a group of values that a variable can have).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;extends&lt;/strong&gt; - Creates a subclass (a class that reuses functionality from a previously defined class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;final&lt;/strong&gt; - Indicates that a variable’s value cannot be changed, that a class’s functionality cannot be extended, or that a method cannot be overridden.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;finally&lt;/strong&gt; - Introduces the last will and testament of the statements in a try clause.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;float&lt;/strong&gt; - Indicates that a value is a 32-bit number with one or more digits after the decimal point.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;for&lt;/strong&gt; - Gets the computer to repeat some statements over and over again (for example, for a certain number of times).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;if&lt;/strong&gt; - Tests to see whether a condition is true. If it’s true, the computer executes certain statements; otherwise, the computer executes the remaining other statements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;implements&lt;/strong&gt; - Reuses the functionality from a previously defined interface.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;import&lt;/strong&gt; - Enables the programmer to abbreviate the names of classes defined in a package.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;instanceof&lt;/strong&gt; - Tests to see whether a certain object comes from a certain class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;int&lt;/strong&gt; - Indicates that a value is a 32-bit whole number.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;interface&lt;/strong&gt; - Introduces an interface, which is like a class, but less specific. (Interfaces are used where one is to inherit from one or more other instances.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;long&lt;/strong&gt; - Indicates that a value is a 64-bit whole number.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;native&lt;/strong&gt; - Enables the programmer to use code that was written in another language.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;new&lt;/strong&gt; - Creates an object from an existing class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;package&lt;/strong&gt; - Puts the code into a package — a collection of logically related definitions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;private&lt;/strong&gt; - Indicates that a variable or method can be used only within a certain class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;protected&lt;/strong&gt; - Indicates that a variable or method can be used in subclass from another package.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;public&lt;/strong&gt; - Indicates that a variable, class, or method can be used by any other Java code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;return&lt;/strong&gt; - Ends execution of a method and possibly returns a value to the calling code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;short&lt;/strong&gt; - Indicates that a value is a 16-bit whole number.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;static&lt;/strong&gt; - Indicates that a variable or method belongs to a class, rather than to any object created from the class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;strictfp&lt;/strong&gt; - Limits the computer’s ability to represent extra large or extra small numbers when the computer does intermediate calculations on float and double values.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;super&lt;/strong&gt; - Refers to the super class of the code in which the word super appears.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;switch&lt;/strong&gt; - Tells the computer to follow one of many possible paths of execution (one of many possible cases), depending on the value of an expression.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;synchronized&lt;/strong&gt; - Keeps two threads from interfering with one another.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;this&lt;/strong&gt; - A self-reference(refers to the object in which the word this appears).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;throw&lt;/strong&gt; - Creates a new exception object and indicates that an exceptional situation (usually something unwanted) has occurred.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;throws&lt;/strong&gt; - Indicates that a method or constructor may pass the buck when an exception is thrown.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;transient&lt;/strong&gt; - Indicates that, if and when an object is serialized, a variable’s value doesn’t need to be stored.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;try&lt;/strong&gt; - Introduces statements that are watched (during runtime) for things that can go wrong.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;void&lt;/strong&gt; - Indicates that a method doesn’t return a value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;volatile&lt;/strong&gt; - Imposes strict rules on the use of a variable by more than one thread at a time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;while&lt;/strong&gt; - Repeats some statements over and over again (as long as a condition is still true).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Data Types in Java
&lt;/h2&gt;

&lt;p&gt;Data types dictate the kind of data that a variable can store. Data type can be defined as the type of data for a variable or constant store. When we use a variable&lt;br&gt;
in a program then we have to mention the type of data.&lt;br&gt;
In java, there are two types of data types : &lt;strong&gt;primitive data types&lt;/strong&gt; and &lt;strong&gt;non-primitive data types&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fadhr8l2berx4cpvo1mdf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fadhr8l2berx4cpvo1mdf.png" alt="Data types in Java"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fepudz11mcp4b8thw208a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fepudz11mcp4b8thw208a.png" alt="Data size"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Variable Initialization
&lt;/h2&gt;

&lt;p&gt;In Java, variables aren’t necessarily assigned an initial value when they’re declared, but all variables must be assigned a value before the variable’s value is used in an assignment statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// We're now initializing BOTH variables explicitly.&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use of variables before they are initialized results in a compiler error.&lt;/p&gt;

&lt;h2&gt;
  
  
  The String Type
&lt;/h2&gt;

&lt;p&gt;A String represents a sequence of zero or more Unicode characters, in other words we can say, a String is array of characters. The symbol String starts with a capital “S,” whereas the names of &lt;strong&gt;primitive types&lt;/strong&gt; are expressed in all lowercase: int, float, boolean, etc.&lt;br&gt;
E.g. &lt;code&gt;String name = "Jeff";&lt;/code&gt;&lt;br&gt;
&lt;em&gt;This capitalization difference is deliberate and mandatory—string (lowercase) won’t&lt;br&gt;
work as a type.&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  String concatenation
&lt;/h3&gt;

&lt;p&gt;The plus sign (+) operator is normally used for arithmetic addition, but when used in conjunction with Strings. Any number of String values can be concatenated with the &lt;code&gt;+&lt;/code&gt; operator, as the following code snippet illustrates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;StringCont&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;f_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Jeff"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;l_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Odhiambo"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Mr. "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;f_name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;l_name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Mr. Jeff Odhiambo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Statements
&lt;/h2&gt;

&lt;p&gt;A statement is basically any declaration, function call, assignment, or condition. Statements are the building blocks of any program. Statements in Java must be&lt;br&gt;
terminated with a semi colon. E.g.&lt;br&gt;
&lt;code&gt;int a;&lt;/code&gt;&lt;br&gt;
&lt;code&gt;a=10;&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Comments
&lt;/h2&gt;

&lt;p&gt;Java supports three different comment styles: single line (end-of-line), Multi-line and Java documentation comments.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Single line (End-of-Line Comments)&lt;/strong&gt;
We use a double slash (//) to note the beginning of a comment that automatically ends when the end of the line is reached.
E.g. &lt;code&gt;x = y + z; // text of comment continues through to the end of the line&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-line Comments&lt;/strong&gt;
These comments begin with a forward slash followed by an asterisk (/&lt;em&gt;) and end with an asterisk followed by a forward slash (&lt;/em&gt;/).
Everything enclosed between these delimiters is treated as a comment and is therefore ignored by the Java
compiler, no matter how many lines the comment spans.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Java Documentation Comments&lt;/strong&gt;
The third and final type of Java comment, Java documentation comments (Javadoc comments), can be parsed from source code files by a special javadoc command-line utility program (which comes standard with the Java SDK)
and used to automatically generate HTML documentation for an application.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Operators and Expressions
&lt;/h2&gt;

&lt;p&gt;An expression is a statement that has a value. Expressions are basically any math or logical operation(s). They consist of a sequence of operators and operands that specifies a computation. E.g &lt;code&gt;x = 12 + 42;&lt;/code&gt; that assigns 54 i.e., 12+42 to variable x.&lt;br&gt;
A simple expression in Java is either&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A constant: &lt;code&gt;a=7;&lt;/code&gt;, &lt;code&gt;payment_status=false;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;A char(acter) literal enclosed in single quotes: &lt;code&gt;grade = 'A'&lt;/code&gt;, &lt;code&gt;mark = '3'&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;A String literal enclosed in double quotes: &lt;code&gt;f_name = "Jeff"&lt;/code&gt;, &lt;code&gt;"l_name = Odhiambo"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The name of any properly declared variables: &lt;code&gt;myString&lt;/code&gt;, &lt;code&gt;x&lt;/code&gt;, etc&lt;/li&gt;
&lt;li&gt;Any two of the preceding types of expression that are combined with one of the Java binary operators (discussed in detail later in this chapter). &lt;code&gt;y = 2x+3;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Any one of the preceding types of expression that is modified by one of the Java unary operators (discussed in detail later in this chapter): &lt;code&gt;i++&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Any of the preceding types of expression enclosed in parentheses: &lt;code&gt;(x + 2)&lt;/code&gt; etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Expressions of arbitrary complexity&lt;/strong&gt; can be assembled from the various different simple expression types by nesting parentheses, for example: &lt;code&gt;((((4/x) + y) * 7) +z)&lt;/code&gt;.
##Operators
Operators are symbols that specifies operations to be performed on operands. 
&lt;strong&gt;Common operators include:&lt;/strong&gt;
Assignment (=) The assignment operator assigns a value to a variable. &lt;code&gt;a = 5&lt;/code&gt;;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;*&lt;em&gt;Arithmetic operators ( +, -, *, /, *&lt;/em&gt;% )&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;-&amp;gt; addition&lt;/li&gt;
&lt;li&gt;-&amp;gt; subtraction&lt;/li&gt;
&lt;li&gt;-&amp;gt; multiplication
/ -&amp;gt; division
% -&amp;gt; modulo
&lt;strong&gt;Compound assignment (+=,-=,*=,/=, %=,&amp;gt;&amp;gt;=,&amp;lt;&amp;lt;=)&lt;/strong&gt;
When we want to modify the value of a variable by performing an operation on the value currently stored in that variable we can use compound assignment operators
which include:
&lt;code&gt;value += increase;&lt;/code&gt; -&amp;gt; &lt;code&gt;value = value + increase;&lt;/code&gt;
&lt;code&gt;a -= 5;&lt;/code&gt; -&amp;gt; &lt;code&gt;a = a - 5;&lt;/code&gt;
&lt;code&gt;a /= b;&lt;/code&gt; -&amp;gt; &lt;code&gt;a = a / b;&lt;/code&gt;
&lt;code&gt;price *= units + 1;&lt;/code&gt; -&amp;gt; price = &lt;code&gt;price * (units + 1);&lt;/code&gt;
&lt;strong&gt;Increment and Decrement operators&lt;/strong&gt;
The increment operator ( ++ ) and the decrement operator ( -- ) increase or reduce by one the value stored in a variable. They are equivalent to &lt;code&gt;+=1&lt;/code&gt; and to &lt;code&gt;-=1&lt;/code&gt; ,
respectively. Thus: &lt;code&gt;c++;c+=1;c=c+1;&lt;/code&gt; are all equivalent in its functionality.
&lt;strong&gt;Relational and equality operators (==,!=,&amp;gt;,&amp;lt;,&amp;gt;=,&amp;lt;= )&lt;/strong&gt;
These operators are used for comparison between two expressions. The result of a relational operation is a Boolean value that can only be true or false, according to its Boolean result. We may want to compare two expressions, for example, to know if they are equal or if one is greater than the other is. 
The relational and equality operators that can be used include:
&lt;code&gt;==&lt;/code&gt; -&amp;gt; &lt;code&gt;Equal to&lt;/code&gt;
&lt;code&gt;!=&lt;/code&gt; -&amp;gt; &lt;code&gt;Not equal to&lt;/code&gt;
&lt;code&gt;&amp;gt;&lt;/code&gt; -&amp;gt; &lt;code&gt;Greater than&lt;/code&gt;
&lt;code&gt;&amp;lt;&lt;/code&gt; -&amp;gt; &lt;code&gt;Less than&lt;/code&gt;
&lt;code&gt;&amp;gt;=&lt;/code&gt; -&amp;gt; &lt;code&gt;Greater than or equal to&lt;/code&gt;
&lt;code&gt;&amp;lt;=&lt;/code&gt; -&amp;gt; &lt;code&gt;Less than or equal to&lt;/code&gt;
&lt;strong&gt;Logical operators ( !, &amp;amp;&amp;amp;, || )&lt;/strong&gt;
The Operator &lt;code&gt;!&lt;/code&gt;, Is used to perform the Boolean operation &lt;code&gt;NOT&lt;/code&gt;, it has only one operand, located at its right, and the only thing that it does is to inverse the value of it, producing false if its operand is true and true if its operand is false.
The logical operators &amp;amp;&amp;amp; and || are used when evaluating two expressions to obtain a single relational result. The operator &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; corresponds with Boolean logical operation &lt;code&gt;AND&lt;/code&gt;. This operation results true if both its two operands are true, and false otherwise.
The operator &lt;code&gt;||&lt;/code&gt; corresponds with Boolean logical operation &lt;code&gt;OR&lt;/code&gt;. This operation results true if either one of its two operands is true, thus being false only when both operands are false themselves.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnvg2e40i3fdq126ztws8.jpg" alt="Operators"&gt;
&lt;strong&gt;Conditional operator ( ? )&lt;/strong&gt;
The conditional operator evaluates an expression returning a value if that expression is true and a different one if the expression is evaluated as false. Its format is:
&lt;code&gt;condition ?result1 : result2&lt;/code&gt;
&lt;strong&gt;Precedence of operators&lt;/strong&gt;
Precedence of operators determines which operand is evaluated first and which one
is evaluated later. For example, in this expression: &lt;code&gt;a = 5 + 7 % 2&lt;/code&gt; we may doubt if it really means:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// with a result of 6, or&lt;/span&gt;
&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="c1"&gt;// with a result of 0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Types of expressions in Java
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Arithmetic expressions
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;unary&lt;/strong&gt; expression consists of either a unary operator prepended to an operand, or the sizeof keyword followed by an expression. A &lt;strong&gt;binary&lt;/strong&gt; expression consists of two operands joined by a binary operator. A ternary expression consists of three operands joined by the conditional-expression operator.&lt;/p&gt;

&lt;p&gt;The easiest example of an expression is in the assignment statement. An expression is evaluated, and the result is saved in a variable. A simple example might look like &lt;code&gt;y = (m * x) + c&lt;/code&gt;&lt;br&gt;
This assignment will save the value of the expression in variable &lt;code&gt;y&lt;/code&gt;.&lt;br&gt;
Short hand assignments&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foibepqz5j7i1oukvzlvk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foibepqz5j7i1oukvzlvk.png" alt="Assignments"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Logical expressions
&lt;/h3&gt;

&lt;p&gt;Logical connectors allow several comparisons to be combined into a single test. They use And, Or and Not operators.&lt;br&gt;
They are frequently used to combine relational operators, for example &lt;code&gt;x&amp;lt; 20 &amp;amp;&amp;amp; x &amp;gt;= 10&lt;/code&gt;&lt;br&gt;
They evaluate their left hand operand, and then only evaluate the right hand one if this is required. Not operates on a single logical value, its effect is to reverse its state. Here is an example of its use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;acceptable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;acceptable&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Not acceptable"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Comparison Expressions
&lt;/h3&gt;

&lt;p&gt;Comparison takes two numbers and produces a logical result. Comparisons are usually found controlling if statements or loops. Example&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5rg0yiz58mdhnks42bv9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5rg0yiz58mdhnks42bv9.png" alt="Coparison expression"&gt;&lt;/a&gt;&lt;br&gt;
Note that == is used in comparisons and = is used in assignments. Comparison operators are used when creating comparisons expressions. E.g.&lt;br&gt;
x == y&lt;br&gt;
i&amp;gt; 10&lt;br&gt;
a + b != c&lt;/p&gt;
&lt;h2&gt;
  
  
  Object, Class, Abstract, Polymorphism etc
&lt;/h2&gt;

&lt;p&gt;Object-oriented programming takes advantage of our perception of world. An &lt;strong&gt;object&lt;/strong&gt; is an encapsulated completely-specified data aggregate containing attributes and behavior.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data hiding&lt;/strong&gt; protects the implementation from interference by other objects and defines approved interface. An object-oriented program is a growing and shrinking collection of objects that interact via messages. &lt;/p&gt;

&lt;p&gt;You can send the same message to similar objects--the target decides how to implement or respond to a message at run-time. Objects with same characteristics are called &lt;strong&gt;instances&lt;/strong&gt; of a class.&lt;/p&gt;
&lt;h2&gt;
  
  
  Benefits of object-oriented programming include:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Troubleshooting is easy in OOP through modularity&lt;/li&gt;
&lt;li&gt;Benefit of code re-usability through inheritance&lt;/li&gt;
&lt;li&gt;Data redundancy is reduced&lt;/li&gt;
&lt;li&gt;Code flexibility emphasis through polymorphism&lt;/li&gt;
&lt;li&gt;Effective problem solving.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Java Classes
&lt;/h2&gt;

&lt;p&gt;A class is essentially an abstract data type that provides a template from which objects are created. Class consists of a collection of data together with functions that operate on the data. &lt;br&gt;
&lt;code&gt;Data&lt;/code&gt; is referred to as data members and &lt;code&gt;functions&lt;/code&gt; are referred to as member functions of a class. By declaring a class we create a new data type that is as powerful as any of the basic types.&lt;/p&gt;
&lt;h3&gt;
  
  
  class syntax
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;classname&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//body&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Student&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//body&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Class data member
&lt;/h3&gt;

&lt;p&gt;In a class, the members are by default hidden within the class and cannot be accessed from outside. We say that the members of a class are declared private by default. However, if we want to, we can declare members of a class to be public.&lt;br&gt;
&lt;strong&gt;Syntax&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;classname&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;{&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;data_type&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;variable_name&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;//body&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
java&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Student{
    String student_name;
    int marks;
    Character grade;
    //body
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Class member functions (methods)
&lt;/h3&gt;

&lt;p&gt;Member functions of a class are also referred to as methods. If we make the member data of our student class private, we should provide functions to access the data for setting, manipulating or printing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Encapsulation and data hiding
&lt;/h3&gt;

&lt;p&gt;Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods. If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class.&lt;br&gt;
Encapsulation can be described as a protective barrier that prevents the code and data being randomly accessed by other code defined outside the class. Access to the data and code is tightly controlled by an interface.&lt;br&gt;
Encapsulation gives maintainability, flexibility and extensibility to our code. Data encapsulation led to the important OOP concept of data hiding.&lt;/p&gt;
&lt;h3&gt;
  
  
  Java Variable Types
&lt;/h3&gt;

&lt;p&gt;In Java, all variables must be declared before they can be used. The basic form of a variable declaration is shown here:&lt;br&gt;
&lt;code&gt;&amp;lt;type&amp;gt; &amp;lt;identifier&amp;gt; = &amp;lt;value&amp;gt;;&lt;/code&gt; e.g&lt;br&gt;
&lt;code&gt;String name = "Jeff Odhiambo";&lt;/code&gt;&lt;br&gt;
The &lt;strong&gt;type&lt;/strong&gt; is one of Java's data types. The &lt;strong&gt;identifier&lt;/strong&gt; is the name of the variable. To declare more than one variable of the specified type, use a comma-separated list.&lt;br&gt;
Java supports the following types of variables:&lt;/p&gt;
&lt;h4&gt;
  
  
  1. Local variables
&lt;/h4&gt;

&lt;p&gt;Local variables are declared in methods, constructors, or blocks. Local variables are created when the method, constructor or block is entered and the variable will be destroyed once it exits the method, constructor or block. Access modifiers cannot be used for local variables. Local variables are visible only within the declared method, constructor or block. Local variables are implemented at stack level internally. There is no default value for local variables so local variables&lt;br&gt;
should be declared and an initial value should be assigned before the first use.&lt;/p&gt;
&lt;h4&gt;
  
  
  2. Class (static) Variables
&lt;/h4&gt;

&lt;p&gt;Class variables are shared by all the instances of the class. Class variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block. Class methods are not tied to a specific object.&lt;br&gt;
There would only be one copy of each class variable per class, regardless of how many objects are created from it. Static variables are created when the program starts and destroyed when the program stops. Static variables can be accessed by calling with the class name. Syntax &lt;code&gt;ClassName.VariableName&lt;/code&gt; e.g &lt;code&gt;Math.PI&lt;/code&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  3. Constants (Final Variables)
&lt;/h4&gt;

&lt;p&gt;Any variable either member variable or local variable (declared inside method or block) modified by final keyword is called &lt;strong&gt;final variable&lt;/strong&gt;. Final variables are often declare with static keyword in java and treated as constant. A final variable can only be initialized once, either via an initializer or an assignment statement.&lt;br&gt;
Class constants are final variables shared by all the instances of the class. Class variables, constants, and methods are used with class name, such as &lt;code&gt;Math.pow(2,3)&lt;/code&gt;, &lt;code&gt;Math.PI&lt;/code&gt;.&lt;br&gt;
To declare class variables, constants, and methods, use the static modifier.&lt;br&gt;
When declaring class variables as public static final, then variables names (constants) are all in upper case. If the static variables are not public and final&lt;br&gt;
the naming syntax is the same as instance and local variables.&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.io.*&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Employee&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// salary variable is a private static variable&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// DEPARTMENT is a constant&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="no"&gt;DEPARTMENT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Development "&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[]){&lt;/span&gt;
        &lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;DEPARTMENT&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s"&gt;"average salary:"&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Instance variables
&lt;/h4&gt;

&lt;p&gt;Instance variables are declared in a class, but outside a method, constructor or any block. When a space is allocated for an object in the heap a slot for each instance variable value is created. Instance variables are created when an object is created with the use of the key word 'new' and destroyed when the object is destroyed.&lt;br&gt;
Instance variables hold values that must be referenced by more than one method, constructor or block, or essential parts of an object’s state that must be present throughout the class. Instance variables can be declared in class level before or after use. Access modifiers can be given for instance variables.&lt;/p&gt;

&lt;p&gt;The instance variables are visible for all methods, constructors and block in the class. Normally it is recommended to make these variables private (access level). However visibility for sub classes can be given for these variables with the use of access modifiers.&lt;br&gt;
Instance variables have default values. For numbers the default value is 0, for Booleans it is false and for object references it is null. Values can be assigned during the declaration or within the constructor.&lt;br&gt;
Instance variables can be accessed directly by calling the variable name inside the class. However within static methods and different class ( when instance variables are given accessibility) the should be called using the fully qualified name . &lt;code&gt;ObjectReference.VariableName&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Scope of Variables
&lt;/h3&gt;

&lt;p&gt;The scope of instance and class variables is the entire class. They can be declared anywhere inside a class. They are global variables. The scope of a local variable starts from its declaration and continues to the end of the block that contains the variable. A local variable must be declared before it can be used.&lt;br&gt;
E.g.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6pbgwqu5inaxp9ys52wn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6pbgwqu5inaxp9ys52wn.png" alt="Scope of variable"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Visibility Modifiers and Accessor Methods
&lt;/h3&gt;

&lt;p&gt;By default, the class, variable, or data can be accessed by any function in the class in which they are declared. &lt;strong&gt;Visibility modifiers include:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Public&lt;/strong&gt; - The class, data, or method is visible to any class in any package.&lt;br&gt;
&lt;strong&gt;Private&lt;/strong&gt; - The data or methods can be accessed only by the declaring class.&lt;br&gt;
&lt;strong&gt;Protected&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Accessor methods(Setters and Getters Methods)
&lt;/h3&gt;

&lt;p&gt;The getter and setter accessor methods are used to read and modify private properties in a class. These methods are also called accessor methods. &lt;br&gt;
&lt;strong&gt;The syntax for accessor methods is:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AccessorExample&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;attribute&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getAttribute&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;attribute&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setAttribute&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;attribute&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;attribute&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attribute&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Java this Keyword
&lt;/h3&gt;

&lt;p&gt;The keyword this in Java refers to the current class instance. Within an instance method or a constructor, this is a reference to the current object. Therefore, this can be used inside any method to refer to the current object. You can refer to any member of the current object from within an instance method or a constructor by using this . The keyword can also be used to call overloaded constructors.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using &lt;code&gt;this&lt;/code&gt; to access a shadowed field
&lt;/h3&gt;

&lt;p&gt;The most common reason for using the this keyword is because a field is shadowed by a method or constructor parameter.&lt;br&gt;
For example, the &lt;code&gt;Point class&lt;/code&gt; was written like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Point&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;//constructor&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Point&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but it could have been written like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Point&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;//constructor&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Point&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each argument to the constructor shadows one of the object's fields — inside the constructor x is a local copy of the constructor's first argument. To refer to the Point field &lt;code&gt;x&lt;/code&gt; , the constructor must use &lt;code&gt;this.x&lt;/code&gt; .&lt;/p&gt;

&lt;h3&gt;
  
  
  Using this to call a Constructor from another constructor
&lt;/h3&gt;

&lt;p&gt;From within a constructor, you can also use the &lt;code&gt;this&lt;/code&gt; keyword to call another constructor in the same class. Doing so is called an &lt;code&gt;explicit constructor invocation&lt;/code&gt;. Here's another Rectangle class, with a different implementation from the one in the Objects section.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Rectangle&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Rectangle&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Rectangle&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Rectangle&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This class contains a set of constructors. Each constructor initializes some or all of the rectangle's member variables. The constructors provide a default value for any member variable whose initial value is not provided by an argument.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data encapsulation
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Data encapsulation&lt;/strong&gt; is a mechanism of bundling the data, and the functions that use them.&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Student&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;idNum&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;getAge&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getIdNum&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;idNum&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setAge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;newAge&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newAge&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setName&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;newName&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newName&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setIdNum&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;newId&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;idNum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newId&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Encapsulation using “this” Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Student&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;idNum&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;getAge&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getIdNum&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;idNum&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setAge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setName&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setIdNum&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;idNum&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;idNum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;idNum&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Advantage of Encapsulation in Java and OOPS
&lt;/h3&gt;

&lt;p&gt;Here are few advantages of using Encapsulation while writing code in Java or any Object oriented programming language:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Encapsulated Code is more flexible and easy to change with new requirements.&lt;/li&gt;
&lt;li&gt;Encapsulation in Java makes unit testing easy.&lt;/li&gt;
&lt;li&gt;Encapsulation in Java allows you to control who can access what.&lt;/li&gt;
&lt;li&gt;Encapsulation also helps to write immutable class in Java which are a good choice in multi-threading environment.&lt;/li&gt;
&lt;li&gt;Encapsulation reduce coupling of modules and increase cohesion inside a module because all piece of one thing are encapsulated in one place.&lt;/li&gt;
&lt;li&gt;Encapsulation allows you to change one part of code without affecting other part of code.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Relationships among Classes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Association
&lt;/h3&gt;

&lt;p&gt;Association is a relationship between two objects. Association represents a general binary relationship that describes an activity between two classes.&lt;br&gt;
The association relationship is a way of describing that a class knows about and holds a reference to another class.&lt;br&gt;
You may be aware of one-to-one, one-to-many, many-to-one, many-to-many all these words define an association between objects.&lt;/p&gt;
&lt;h3&gt;
  
  
  Aggregation
&lt;/h3&gt;

&lt;p&gt;Aggregation is a relationship between two classes that is best described as a "has-a" and "whole/part" relationship.&lt;br&gt;
Aggregation models the relationship like has-a, part-of, owns, and employed-by. When an object ‘has-a’ another object, then you have got an aggregation between them.&lt;br&gt;
Direction between them specifies which object contains the other object. Aggregation is also called a &lt;code&gt;“Has-a” relationship.&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
There is an aggregation relationship between Student class and the Subject class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Subject&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setName&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Student&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Subject&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;studyAreas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Subject&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Find more examples &lt;a href="http://www.javatpoint.com/aggregation-in-java" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Composition
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Composition&lt;/strong&gt; is restricted aggregation. When an object contains the other object,i.e., if the contained object cannot exist without the existence of container object, then it is called composition.&lt;br&gt;
&lt;strong&gt;Example:&lt;/strong&gt; A class contains students. A student cannot exist without a class.&lt;br&gt;
There exists composition between class and students.&lt;/p&gt;
&lt;h3&gt;
  
  
  Abstraction
&lt;/h3&gt;

&lt;p&gt;Abstraction is specifying the framework and hiding the implementation level information. Concreteness will be built on top of the abstraction. It gives you a&lt;br&gt;
blueprint to follow to while implementing the details. Abstraction reduces the complexity by hiding low level details.&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt;: A wire frame model of a car.&lt;/p&gt;
&lt;h3&gt;
  
  
  Generalization
&lt;/h3&gt;

&lt;p&gt;Generalization uses a “is-a” relationship from a specialization to the generalization class. Common structure and behavior are used from the specialization to the generalized class. At a very broader level you can understand this as &lt;code&gt;inheritance&lt;/code&gt;. Why I take the term inheritance is, you can relate this term very well.&lt;br&gt;
&lt;strong&gt;Example:&lt;/strong&gt; Consider there exists a class named Person. A student is a person. A faculty is a person. Therefore here the relationship between student and person, similarly faculty and person is generalization.&lt;/p&gt;
&lt;h3&gt;
  
  
  Realization
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Realization&lt;/strong&gt; is a relationship between the blueprint class and the object containing its respective implementation level details. This object is said to&lt;br&gt;
realize the blueprint class. In other words, you can understand this as the relationship between the interface and the implementing class.&lt;br&gt;
&lt;strong&gt;Example:&lt;/strong&gt; A particular model of a car ‘GTB Fiorano’ that implements the blueprint of a car realizes the abstraction.&lt;/p&gt;
&lt;h3&gt;
  
  
  Dependency
&lt;/h3&gt;

&lt;p&gt;Change in structure or behavior of a class affects the other related class, then there is a dependency between those two classes. It need not be the same on the vice-&lt;br&gt;
versa. When one class contains the other class this happens.&lt;br&gt;
&lt;strong&gt;Example:&lt;/strong&gt; Relationship between shape and circle is dependency.&lt;/p&gt;
&lt;h3&gt;
  
  
  Inheritance (developed from)
&lt;/h3&gt;

&lt;p&gt;Inheritance models the “is-a” relationship between two classes. It is a mechanism where a new class is derived from an existing class.&lt;br&gt;
In Java, classes may inherit or acquire the non private properties and methods of other classes. A class derived from another class is called a &lt;code&gt;subclass&lt;/code&gt;, whereas&lt;br&gt;
the class from which a subclass is derived is called a &lt;code&gt;super class&lt;/code&gt;. A subclass can have only one super class, whereas a super class may have one or more sub classes.&lt;/p&gt;

&lt;p&gt;Any class in java that does not extend any other class implicitly extends Object class. Therefore, the &lt;strong&gt;java.lang.Object&lt;/strong&gt; class is always at the top of any Class inheritance hierarchy.&lt;br&gt;
In Java, inheritance is used for two purposes:&lt;br&gt;
&lt;strong&gt;1. Class inheritance&lt;/strong&gt; - create a new class as an extension of another class, primarily for the purpose of code reuse. That is, the derived class inherits the public methods and public data of the base class. Java only allows a class to have one immediate base class,&lt;br&gt;
i.e., single class inheritance. The keyword “extends” is used to derive a subclass from the superclass, as illustrated by the following syntax:&lt;br&gt;
&lt;strong&gt;syntax&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;derived&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;name&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;name&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;// derived class methods extend and possibly override those of the base class&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;A&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;//properties and methods of A&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;B&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="no"&gt;A&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Class inheritance defines a is-a relationship between a superclass and its subclasses. Therefore inheritance is achieved at class level. We can therefore define inheritance in java as mechanism is used to build new classes from existing classes.&lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Mammal&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Reptile&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Mammal&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Object Oriented terms following are true:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Animal is the super class of Mammal class.&lt;/li&gt;
&lt;li&gt;Animal is the super class of Reptile class.&lt;/li&gt;
&lt;li&gt;Mammal and Reptile are sub classes of Animal class.&lt;/li&gt;
&lt;li&gt;Dog is the subclass of both Mammal and Animal classes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now if we consider the IS-A relationship we can say:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mammal IS-A Animal&lt;/li&gt;
&lt;li&gt;Reptile IS-A Animal&lt;/li&gt;
&lt;li&gt;Dog IS-A Mammal&lt;/li&gt;
&lt;li&gt;Hence : Dog IS-A Animal as well
With use of extends keyword the sub classes will be able to inherit all the properties of the super class except for the private properties of the super class.
Below is a sample implementation of the Dog class:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Mammal&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[]){&lt;/span&gt;
        &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="nc"&gt;Mammal&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Mammal&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;&lt;span class="c1"&gt;//Outputs true&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;Mammal&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//Outputs true&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//Outputs true&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Boolean &lt;code&gt;instanceof&lt;/code&gt; operator is used to determine whether Mammal is actually an Animal, and dog is actually an Animal.&lt;/p&gt;

&lt;h3&gt;
  
  
  super keyword
&lt;/h3&gt;

&lt;p&gt;‘super’ is used for pointing the super class instance. That is, it is a reference variable that is used to refer immediate parent class object.&lt;br&gt;
The keyword super will therefore be used when referring to the super class of an object.&lt;/p&gt;
&lt;h3&gt;
  
  
  Uses of super Keyword
&lt;/h3&gt;

&lt;p&gt;super is used to refer immediate parent class instance variable.&lt;br&gt;
super() is used to invoke immediate parent class constructor.&lt;br&gt;
super is used to invoke immediate parent class method.&lt;br&gt;
&lt;strong&gt;Using the super keyword to call immediate parent class constructor&lt;/strong&gt;&lt;br&gt;
The syntax for calling a super class constructor is&lt;br&gt;
&lt;code&gt;super();&lt;/code&gt; or &lt;code&gt;super(parameter list);&lt;/code&gt;&lt;br&gt;
NB: In a constructor, super MUST always be the first statement to appear:&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Vehicle&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Vehicle is created"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="nc"&gt;Void&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Vehicle is starting..."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Bike&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Bike&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="kd"&gt;super&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;&lt;span class="c1"&gt;//will invoke parent class constructor&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Bike is created"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[]){&lt;/span&gt;
        &lt;span class="nc"&gt;Bike&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Bike&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Vehicle is created
Bike is created
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With super(), the super class no-argument constructor is called. With super(parameter list), the super class constructor with a matching parameter list is called. If accessing a method in super class, we use the syntax:&lt;br&gt;
&lt;code&gt;super.methodName( argument(s))&lt;/code&gt;&lt;br&gt;
&lt;code&gt;super.start();&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Method Overriding
&lt;/h2&gt;

&lt;p&gt;When a sub class defines a method that has same name signature and return type (or compatible with return type of super class method) it is called method overriding. In object oriented terms, overriding means to override the functionality of any existing method.&lt;br&gt;
The benefit of overriding is: ability to define a behavior that's specific to the sub class type. Which means a subclass can implement a parent class method based on its requirement.&lt;br&gt;
Consider the following example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;move&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Animals can move"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;move&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Dogs can walk and run"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TestDog&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[]){&lt;/span&gt;
        &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Animal reference and object&lt;/span&gt;
        &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Animal reference but Dog object&lt;/span&gt;
        &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;move&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;&lt;span class="c1"&gt;// runs the method in Animal class&lt;/span&gt;
        &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;move&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;&lt;span class="c1"&gt;//Runs the method in Dog class&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would produce following result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Animals can move
Dogs can walk and run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example you can see that the even though b is a type of Animal it runs the move method in the Dog class. The reason for this is : In compile time the check is made on the reference type. However in the runtime JVM figures out the object type and would run the method that belongs to that particular object.&lt;br&gt;
Therefore in the above example, the program will compile properly since Animal class has the method move. Then at the runtime it runs the method specific for that object.&lt;br&gt;
Consider the following example :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;move&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Animals can move"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;move&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Dogs can walk and run"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;bark&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Dogs can bark"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TestDog&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[])&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Animal reference and object&lt;/span&gt;
        &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Animal reference but Dog object&lt;/span&gt;

        &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;move&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;&lt;span class="c1"&gt;// runs the method in Animal class&lt;/span&gt;
        &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;move&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;&lt;span class="c1"&gt;//Runs the method in Dog class&lt;/span&gt;
        &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;bark&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would produce following result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;TestDog.java:30: cannot find symbol
symbol : method bark&lt;span class="o"&gt;()&lt;/span&gt;
location: class Animal
b.bark&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  ^
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This program will throw a compile time error since b's reference type Animal doesn't have a method by the name of bark.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using the super keyword to call overridden method
&lt;/h3&gt;

&lt;p&gt;When invoking a super class version of an overridden method the super keyword is used.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;move&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Animals can move"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;move&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="kd"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;move&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// invokes the super class method&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Dogs can walk and run"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TestDog&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[]){&lt;/span&gt;
        &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Animal reference but Dog object&lt;/span&gt;
        &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;move&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;//Runs the method in Dog class&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would produce following result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Animals can move
Dogs can walk and run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Rules for method overriding:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The argument list should be exactly the same as that of the overridden method.&lt;/li&gt;
&lt;li&gt;The return type should be the same or a sub type of the return type declared in the original overridden method in the super class.&lt;/li&gt;
&lt;li&gt;The access level cannot be more restrictive than the overridden method's access level. For example: if the super class method is declared public then the overridding method in the sub class cannot be either private or protected.&lt;/li&gt;
&lt;li&gt;Instance methods can be overridden only if they are inherited by the subclass.&lt;/li&gt;
&lt;li&gt;A method declared final cannot be overridden.&lt;/li&gt;
&lt;li&gt;A method declared static cannot be overridden but can be re-declared.&lt;/li&gt;
&lt;li&gt;If a method cannot be inherited then it cannot be overridden.&lt;/li&gt;
&lt;li&gt;A subclass within the same package as the instance's superclass can override any superclass method that is not declared private or final.&lt;/li&gt;
&lt;li&gt;A subclass in a different package can only override the non-final methods declared public or protected.&lt;/li&gt;
&lt;li&gt;An overriding method can throw any uncheck exceptions, regardless of whether the overridden method throws exceptions or not. However the overriding method should not throw checked exceptions that are new or broader than the ones declared by the overridden method. The overriding method can throw narrower or fewer exceptions than the overridden method.&lt;/li&gt;
&lt;li&gt;Constructors cannot be overridden.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Data abstraction
&lt;/h2&gt;

&lt;p&gt;Abstraction is the concept of object-oriented programming that “shows” only essential attributes and “hides” unnecessary information. The main purpose of abstraction is hiding the unnecessary details from the users. The implementation details is hidded from the user. Abstraction is achieved using either abstract classes or interfaces.&lt;/p&gt;

&lt;h2&gt;
  
  
  Class Abstraction
&lt;/h2&gt;

&lt;p&gt;Class abstraction means to separate class implementation from the use of the class. The creator of the class provides a description of the class and let the user know how the class can be used. The user of the class does not need to know how the class is implemented. The detail of implementation is encapsulated and hidden from the user.&lt;/p&gt;

&lt;h2&gt;
  
  
  Abstract Classes and Abstract Methods
&lt;/h2&gt;

&lt;p&gt;An &lt;strong&gt;abstract class&lt;/strong&gt; is a restricted class that cannot be used to create objects (to access it, it must be inherited from another class). An abstract class leaves one or more method implementations unspecified by declaring one or more methods abstract. An abstract can only be used as a super class for other classes that&lt;br&gt;
extend the abstract class. Abstract classes are declared with the abstract keyword. Abstract classes are used to provide a template or design for concrete subclasses down the inheritance tree.&lt;br&gt;
&lt;strong&gt;Abstract methods&lt;/strong&gt; are methods with no body specification (implementation).&lt;br&gt;
Abstract methods can only be used in an abstract class, and it does not have a body. I.e Abstract method would have no definition, and its signature is followed by a semicolon, not curly braces. The body is provided by the subclass (inherited from).&lt;br&gt;
The &lt;strong&gt;abstract keyword&lt;/strong&gt; is a non-access modifier, used for classes and methods. The abstract keyword is used to declare a class or a method as abstract. An abstract method consists of a method signature, but no method body.&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;abstract&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Shape&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Shape&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setColor&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getColor&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;abstract&lt;/span&gt; &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;area&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that If a class has at least one abstract method, the class must be declared as abstract.&lt;br&gt;
A subclass is therefore required to override the abstract method and provide an implementation. Subclasses must provide the method statements for their particular meaning. If the method was one provided by the superclass, it would require overriding in each subclass. Hence, an abstract class is incomplete and cannot be instantiated, but can be used as a base class.&lt;br&gt;
The abstract class guarantees that each shape will have the same set of basic properties. We declare this class abstract because there is no such thing as a generic shape. There can only be concrete shapes such as squares, circles, triangles etc.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Point&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Shape&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Point&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;area&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;perimeter&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"point: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;","&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[])&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Point&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Point&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;print&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Points to Remember&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An abstract class must be declared with an abstract keyword.&lt;/li&gt;
&lt;li&gt;It can have abstract and non-abstract methods.&lt;/li&gt;
&lt;li&gt;It cannot be instantiated.&lt;/li&gt;
&lt;li&gt;It can have constructors and static methods also.&lt;/li&gt;
&lt;li&gt;It can have final methods which will force the subclass not to change the body of the method.
##Interfaces
An interface in Java is a blueprint of a class. It consists of static constants and abstract methods. In Java, an interface is a mechanism to achieve abstraction.
There can be only abstract methods in a Java interface. No need to include keyword abstract when declaring abstract methods in in interface.
Just like an abstract class, an interface cannot be instantiated.
You can declare an interface in its own file like a class. In such a case, File name must be the same as the class name. Java Interface also represents the IS-A relationship.
###Declaring Interfaces
The interface keyword is used to declare an interface.
Syntax:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;interface_name&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;{&lt;/span&gt;
&lt;span class="c1"&gt;// declare constant fields&lt;/span&gt;
&lt;span class="c1"&gt;// declare abstract methods&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* File name : Animal.java */&lt;/span&gt;
&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;eat&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;travel&lt;/span&gt;&lt;span class="o"&gt;();}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Implementing an interface
&lt;/h3&gt;

&lt;p&gt;Class inheritance in java uses the keyword extends. To access the interface methods, the interface must be "implemented" (inherited) by another class using the implements keyword (instead of extends). During implementation the body of each interface method is provided by the "implementing" class:&lt;br&gt;
Syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;class&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;name&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;// class provides an implementation for the methods&lt;/span&gt;
&lt;span class="c1"&gt;// as specified by the interface&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;makeSound&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// interface method (does not have a body)&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// interface method (does not have a body)}&lt;/span&gt;

    &lt;span class="c1"&gt;//Donkey "implements" the Animal interface&lt;/span&gt;
    &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Donkey&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;makeSound&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// The body of animalSound() is provided here&lt;/span&gt;
            &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The donkey says: hee hoo"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// The body of sleep() is provided here&lt;/span&gt;
            &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Zzz"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DonkeyImpl&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;Donkey&lt;/span&gt; &lt;span class="n"&gt;dnk&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Donkey&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="c1"&gt;// Create a Donkey object&lt;/span&gt;
            &lt;span class="n"&gt;dnk&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;makeSound&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="n"&gt;dnk&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sleep&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why use Java interface?
&lt;/h3&gt;

&lt;p&gt;There are mainly three reasons to use interface. They are given below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is used to achieve abstraction.&lt;/li&gt;
&lt;li&gt;By interface, we can support the functionality of multiple inheritance.&lt;/li&gt;
&lt;li&gt;It can be used to achieve loose coupling.
Interfaces are preferred to classes because they help us to to achieve abstraction as well
as multiple inheritance in Java.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Extending Interfaces
&lt;/h3&gt;

&lt;p&gt;An interface can extend another interface in the same way that a class can extend another class. The extends keyword is used to extend an interface, and the child&lt;br&gt;
interface inherits the methods of the parent interface.&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Filename: Sports.java&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Sports&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setHomeTeam&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setVisitingTeam&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// Filename: Football.java&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Football&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Sports&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;homeTeamScored&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;points&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;visitingTeamScored&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;points&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;endOfQuarter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;quarter&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// Filename: Hockey.java&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Hockey&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Sports&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;homeGoalScored&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;visitingGoalScored&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;endOfPeriod&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;period&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;overtimePeriod&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;ot&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Multiple Class Inheritance in Java
&lt;/h3&gt;

&lt;p&gt;A class can extends ONLY one parent class using the extends keyword. Multiple class inheritance is not allowed.&lt;br&gt;
Class inheritance inheritance in java has the following limitations.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A subclass cannot inherit private members of its super class.&lt;/li&gt;
&lt;li&gt;A subclass can have only one super class.&lt;/li&gt;
&lt;li&gt;Constructor and initializer blocks cannot be inherited by a subclass.
Interfaces are not classes, thus you are allowed to inherit one or more interfaces.
Multiple inheritance by interface occurs if a class implements multiple interfaces or also if an interface itself extends multiple interfaces.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Extending Multiple Interfaces
&lt;/h3&gt;

&lt;p&gt;To achieve multiple inheritance, java allows you to implement more than one parent interfaces by declaring them in a comma-separated list. E.g.&lt;br&gt;
&lt;code&gt;public interface Hockey extends Sports, Event&lt;/code&gt;&lt;br&gt;
&lt;em&gt;Note that an interface can extend more than one parent interface&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwgsxn94j8kauykr4pyk3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwgsxn94j8kauykr4pyk3.png" alt="interface"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Difference between Abstraction and Encapsulation
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa5nodojkrwrcxsg4ybms.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa5nodojkrwrcxsg4ybms.png" alt="abstraction"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Difference between Abstract Class and Interface
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7tl5pfodhqo21yvp56f7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7tl5pfodhqo21yvp56f7.png" alt="interfaces"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Polymorphism in Java
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Polymorphism&lt;/strong&gt; is the ability of an object to take on many forms. In OOP, polymorphism is the capability of an action or method to do different things based on the object that it is acting upon.&lt;br&gt;
This is the third basic principle of object oriented programming. Polymorphism in Java has two types: &lt;strong&gt;Compile time polymorphism&lt;/strong&gt; (static binding) and &lt;strong&gt;Runtime polymorphism&lt;/strong&gt; (dynamic binding).&lt;/p&gt;
&lt;h2&gt;
  
  
  Compile time (Static) polymorphism
&lt;/h2&gt;

&lt;p&gt;A static polymorphism is one which method binds at compile time, also known as Compile time or static polymorphism. Static polymorphism is achieved through method(function) overloading or operator overloading. But Java doesn’t support the Operator Overloading.&lt;/p&gt;
&lt;h2&gt;
  
  
  Overloaded methods
&lt;/h2&gt;

&lt;p&gt;When there are multiple functions (methods) with same name but different parameters (implementation) then these functions are said to be overloaded. Thus, functions can be overloaded by change in number of arguments or/and change in type of arguments.&lt;br&gt;
These overloaded methods have same name signature but either a different number of parameters or different types in the parameter list. Overloaded methods:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Appear in the same class or a subclass.&lt;/li&gt;
&lt;li&gt;Have the same name but.&lt;/li&gt;
&lt;li&gt;Have different parameter lists.&lt;/li&gt;
&lt;li&gt;Can have different return types.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;At compile time, Java knows which method to invoke by checking the method signatures. So, this is called compile time polymorphism or static binding. The concept will be clear from the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DemoOverload&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt; &lt;span class="c1"&gt;//method 1&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt; &lt;span class="c1"&gt;//method 2&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt; &lt;span class="c1"&gt;//method 3&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt; &lt;span class="c1"&gt;//method 4&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Test&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
        &lt;span class="nc"&gt;DemoOverload&lt;/span&gt; &lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DemoOverload&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
        &lt;span class="c1"&gt;//method&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
        &lt;span class="c1"&gt;//method&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;3.4&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
        &lt;span class="c1"&gt;//method&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;2.5&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
        &lt;span class="c1"&gt;//method&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Constructor Overloading:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Constructor overloading is a technique in Java in which a class can have any number of constructors that differ in parameter lists.&lt;/li&gt;
&lt;li&gt;The compiler differentiates these constructors by taking into account the number of parameters in the list and their type.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Room&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="n"&gt;breadth&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Room&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;breadth&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="nc"&gt;Room&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="o"&gt;=-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;breadth&lt;/span&gt;&lt;span class="o"&gt;=-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="nc"&gt;Room&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;breadth&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;volume&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;breadth&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OverloadConstructors&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[])&lt;/span&gt;
    &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Room&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Room&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="nc"&gt;Room&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Room&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="nc"&gt;Room&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Room&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;vol&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;vol&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;volume&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Volume of room a is "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;vol&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;vol&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;volume&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Volume of room b is "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;vol&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;vol&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;volume&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Volume of room c is "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;vol&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Limitation:&lt;/strong&gt; Poor utilization of memory resource (main memory).&lt;/p&gt;

&lt;h2&gt;
  
  
  Dynamic (Run Time) Polymorphism:
&lt;/h2&gt;

&lt;p&gt;It is a process in which a function call to the overridden method is resolved at Runtime. This type of polymorphism is achieved by Method Overriding.&lt;br&gt;
Run time polymorphism occurs when a sub class overrides a particular method of the super class.&lt;/p&gt;
&lt;h3&gt;
  
  
  Dynamic Binding (Late Binding)
&lt;/h3&gt;

&lt;p&gt;When a method is invoked, the code to be executed is only determined at run-time. During the compilation, the compiler checks whether the method exists and performs type check on the arguments and return type, but does not know which piece of codes to execute at run-time. When a message is sent to an object to invoke a method, the object figures out which piece of codes to execute at run-time. This mechanism is called &lt;strong&gt;dynamic binding&lt;/strong&gt; (or &lt;strong&gt;late-binding&lt;/strong&gt; or &lt;strong&gt;run-time binding&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;In polymorphism, Dynamic (or late) method binding is the ability of a program to resolve references to subclass methods at runtime.&lt;/p&gt;
&lt;h2&gt;
  
  
  Overridden Methods
&lt;/h2&gt;

&lt;p&gt;Overridden methods are methods of a super class that are redefined(defined again) within a subclass.&lt;br&gt;
In Java, you can create a method in a superclass (or parent class), then in a subclass ALSO define that&lt;br&gt;
method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;move&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Vehicles can move!!"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MotorBike&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;move&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"MotorBike can move and accelerate too!!"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Test&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
        &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="n"&gt;vh&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;MotorBike&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;vh&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;move&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// prints MotorBike can move and accelerate too!!&lt;/span&gt;
        &lt;span class="n"&gt;vh&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;vh&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;move&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// prints Vehicles can move!!&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It should be noted that in the first call to move(), the reference type is Vehicle and the object being referenced is MotorBike. So, when a call to move() is made, Java waits until runtime to determine&lt;br&gt;
which object is actually being pointed to by the reference. In this case, the object is of the class MotorBike. So, the move() method of MotorBike class will be called. In the second call to move(), the object is of the class Vehicle. So, the move() method of Vehicle will be called. As the method to call is determined at runtime, this is called &lt;strong&gt;dynamic binding&lt;/strong&gt; or &lt;strong&gt;late binding&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Overriding:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;applies ONLY to inherited methods is related to polymorphism&lt;/li&gt;
&lt;li&gt;object type (NOT reference variable type) determines which overridden method will be used at runtime&lt;/li&gt;
&lt;li&gt;overriding method MUST have the same argument list (if not, it might be a case of overloading)&lt;/li&gt;
&lt;li&gt;overriding method MUST have the same return type; the exception is covariant return (used as of Java 5) which returns a type that is a subclass of what is returned by the overridden method&lt;/li&gt;
&lt;li&gt;overriding method MUST NOT have more restrictive access modifier, but MAY have less restrictive one&lt;/li&gt;
&lt;li&gt;overriding method MUST NOT throw new or broader checked exceptions, but MAY throw fewer or narrower checked exceptions or any unchecked exceptions&lt;/li&gt;
&lt;li&gt;abstract methods MUST be overridden&lt;/li&gt;
&lt;li&gt;final methods CANNOT be overridden&lt;/li&gt;
&lt;li&gt;static methods CANNOT be overridden&lt;/li&gt;
&lt;li&gt;constructors CANNOT be overridden
##Upcasting &amp;amp; Downcasting
&lt;strong&gt;Upcasting a Subclass Instance to a Superclass Reference&lt;/strong&gt;
Substituting a subclass instance for its superclass is called "upcasting". This is because, in a UML class diagram, subclass is often drawn below its superclass. Upcasting is always safe because a subclass instance possesses all the properties of its superclass and can do whatever its superclass can do. The compiler checks for valid upcasting and issues error "incompatible types" otherwise.
For example,
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Circle c1 = new Cylinder(); // Compiler checks to ensure that R-value is a subclass of L-value
Circle c2 = new String(); // Compilation error: incompatible types
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Downcasting a Substituted Reference to Its Original Class&lt;/strong&gt;&lt;br&gt;
You can revert a substituted instance back to a subclass reference. This is called "downcasting". For&lt;br&gt;
example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Cycle c1 = new Cylinder(5.0); // upcast is safe
Cylinder aCylinder = (Cylinder) c1; // downcast needs the casting operator
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Downcasting requires explicit type casting operator in the form of prefix operator (new-type).&lt;br&gt;
Downcasting is not always safe, and throws a runtime &lt;code&gt;ClassCastException&lt;/code&gt; if the instance to be downcasted does not belong to the correct subclass. A subclass object can be substituted for its superclass, but the reverse is not true.&lt;br&gt;
Compiler may not be able to detect error in explicit cast, which will be detected only at runtime.&lt;br&gt;
For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Circle&lt;/span&gt; &lt;span class="n"&gt;c1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nc"&gt;Point&lt;/span&gt; &lt;span class="n"&gt;p1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Point&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;c1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;p1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// compilation error: incompatible types (Point is not subclass of Circle)&lt;/span&gt;
&lt;span class="n"&gt;c1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="n"&gt;p1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// runtime error: java.lang.ClassCastException: Point cannot be casted to Circle&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The &lt;code&gt;instanceof&lt;/code&gt; Operator&lt;/strong&gt;&lt;br&gt;
Java provides a binary operator called &lt;code&gt;instanceof&lt;/code&gt; which returns true if an object is an instance of a particular class. The syntax is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//anObjectinstanceofaClass
Circle c1 = new Circle();
System.out.println(c1 instanceof Circle); // true
if (c1 instanceof Cirlce){
    //body
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An instance of subclass is also an instance of its superclass. For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Circle&lt;/span&gt; &lt;span class="n"&gt;c1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nc"&gt;Cylinder&lt;/span&gt; &lt;span class="n"&gt;cy1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Cylinder&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c1&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c1&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;Cylinder&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//false&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cy1&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;Cylinder&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cy1&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;//true&lt;/span&gt;

&lt;span class="nc"&gt;Circle&lt;/span&gt; &lt;span class="n"&gt;c2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Cylinder&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c2&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c2&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;Cylinder&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Summary:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The method binding happens at the compile time i.e which methods can be invoked on a given reference type is decided at the compile time.&lt;/li&gt;
&lt;li&gt;The selection of the method’s implementation to execute happens at the run time i.e which implementation of the method to be executed i.e the super class version or one of the subclass’s version is decided at the run time and this is what leads to the runtime polymorphism.&lt;/li&gt;
&lt;li&gt;An object in Java that passes more than one IS-A tests is polymorphic in nature&lt;/li&gt;
&lt;li&gt;Static polymorphism in Java is achieved by method overloading&lt;/li&gt;
&lt;li&gt;Dynamic polymorphism in Java is achieved by method overriding.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A &lt;strong&gt;package&lt;/strong&gt; can be defined as a group of similar types of classes, interface, enumeration and sub-package. Enumerations and annotation types are special kinds of classes and interfaces. Packages provide access protection and name space management in a java program. Therefore, a package provides a mechanism for organizing Java classes into namespaces similar to the modules in VB.&lt;br&gt;
Packages are used in Java in order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations easier, etc. Using package it becomes easier to locate the related classes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Package are categorized into two forms:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Built-in Package&lt;/strong&gt;:-Existing Java package for example java.lang and java.util&lt;br&gt;
&lt;strong&gt;User-defined-package&lt;/strong&gt;:- Java package created by user to categorize source files.&lt;/p&gt;
&lt;h2&gt;
  
  
  Built-in Packages
&lt;/h2&gt;

&lt;p&gt;These packages consist of a large number of classes which are a part of Java API. Some of the commonly used built-in packages are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;java.lang&lt;/strong&gt;: Contains language support classes(e.g classed which defines primitive data types, math operations). This package is automatically imported.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;java.io&lt;/strong&gt;: Contains classed for supporting input / output operations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;java.util&lt;/strong&gt;: Contains utility classes which implement data structures like Linked List, Dictionary and support ; for Date / Time operations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;java.applet&lt;/strong&gt;: Contains classes for creating Applets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;java.awt&lt;/strong&gt;: Contain classes for implementing the components for graphical user interfaces (like button , ;menus etc).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;java.net&lt;/strong&gt;: Contain classes for supporting networking operations. And many others.
##User-defined packages
Programmers can define their own packages to bundle group of classes/interfaces etc. It is a good practice to group related classes implemented by you so that a programmers can easily determine that the classes, interfaces, enumerations, annotations are related.
Since the package creates a new namespace there won't be any name conflicts with names in other packages. Using packages, it is easier to provide access control and it is also easier to locate the related classed.
To set up the programmer-defined packages for general reuse, not just use by the programs in the same folder, we have to perform the following tasks:&lt;/li&gt;
&lt;li&gt;Include the statement
&lt;code&gt;package myutil;&lt;/code&gt; as the first statement of the source file for the &lt;code&gt;Fraction class&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The class declaration must include the visibility modifier public as &lt;code&gt;public class Fraction {}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create a folder named &lt;code&gt;myutil&lt;/code&gt; , the same name as the package name. In Java, the package must have a one-to-one correspondence with the folder.&lt;/li&gt;
&lt;li&gt;Place the modified Fraction class into the myutil folder and compile it.&lt;/li&gt;
&lt;li&gt;Modify the &lt;code&gt;CLASSPATH environment variabl&lt;/code&gt;e to include the folder that contains the myutil folder.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Creating a package
&lt;/h2&gt;

&lt;p&gt;To group classes into a package each class must have a package statement defined at the top of a java file. It lets the compiler know which package the class belongs to and must be the first line of code. The syntax for defining a package is:&lt;br&gt;
&lt;code&gt;package &amp;lt;package name&amp;gt;&lt;/code&gt; &lt;br&gt;
NB: A package name is a fully qualified variable name. e.g. package diploma_students. To create your own package, you need to understand that Java uses a file system directory to store them. Just like folders on your computer.&lt;/p&gt;
&lt;h2&gt;
  
  
  Java Package Names and Directory Structure
&lt;/h2&gt;

&lt;p&gt;Organizing classes in a program can take multiple levels so that each package can have as many sub-packages as needed. The Java Package name consists of words separated by periods. The first part of the name represents the organization which created the package. The remaining words of the Java Package name reflect the contents of the package. The Java Package name also reflects its directory structure. &lt;br&gt;
The period "." is used to distinguish the package and sub-package. The period is placed in-between the package names. E.g. package &lt;code&gt;university.college.department.course&lt;/code&gt;&lt;br&gt;
The first part of that package name "university" represents the organization that developed the package. The second part of the package name "college" stands for the contents of the package, in this case the department and lastly the course offered by a given department.&lt;/p&gt;
&lt;h2&gt;
  
  
  The import Keyword
&lt;/h2&gt;

&lt;p&gt;Import keyword is used to import built-in and user-defined packages into your java source file. Packages allow your class to refer to a class that is in another package by directly using its name. &lt;br&gt;
There are 3 different ways to refer to class that is present in different package.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Using fully qualified name (which is not a good practise). &lt;strong&gt;Example&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;myDate&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;util&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;Date&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//body&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Import the only class you need
&lt;strong&gt;Example&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.Date&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;myDate&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//body&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Import all classes from a particular package
&lt;strong&gt;Example&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.*&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;myDate&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//body&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Importing a Class from an Existing Java Package using the import Keyword:&lt;/strong&gt;&lt;br&gt;
If a class wants to use another class in the same package, the package name does not need to be used. Classes in the same package find each other without any special syntax.&lt;br&gt;
If a class in one package uses details of another class in different package, the class to be used MUST be included in current class using the import statement. E.g.&lt;br&gt;
&lt;code&gt;import javax.swing.JOptionPane;&lt;/code&gt;&lt;br&gt;
Note: The import statement is terminated with a semicolon.&lt;/p&gt;
&lt;h3&gt;
  
  
  How to access Package from another package
&lt;/h3&gt;

&lt;p&gt;There are three ways to access the package from outside the package.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;import package.*;&lt;/li&gt;
&lt;li&gt;import package.classname;&lt;/li&gt;
&lt;li&gt;fully qualified name.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Using packagename.*
&lt;/h3&gt;

&lt;p&gt;If you use package.* then all the classes and interfaces of this package will be accessible but not sub-packages. The import keyword is used to make the classes and interface of another package accessible to the current package.&lt;/p&gt;
&lt;h4&gt;
  
  
  Static import
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;Static import&lt;/code&gt; is a feature that extends the capabilities of &lt;code&gt;import&lt;/code&gt; keyword. It is used to import static member of a class.We will know that static member are referred in association with its class name outside the class. Using static import, its possible to refer to the static member directly without its class name.&lt;/p&gt;

&lt;p&gt;The 2 general form of static statement are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The first form of static import statement, import only a single static member of a class.
&lt;strong&gt;Syntax&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import static package.class-name.static-member-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;static&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;lang&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;Math&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sqrt&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; 
&lt;span class="c1"&gt;//importing static method sqrt of Math class &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Second form of static import statement, imports all the static member of a class.
&lt;strong&gt;Syntax&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;static&lt;/span&gt; &lt;span class="kn"&gt;package&lt;/span&gt;&lt;span class="nn"&gt;.class&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;.*;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;static&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;lang&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;Math&lt;/span&gt;&lt;span class="o"&gt;.*;&lt;/span&gt;
&lt;span class="c1"&gt;//importing all static method of Math class &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example without using static import&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Test&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Math&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sqrt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;144&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output: &lt;code&gt;12&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Example using static import&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;static&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;lang&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;Math&lt;/span&gt;&lt;span class="o"&gt;.*;&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Test&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sqrt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;144&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Handling name conflicts
&lt;/h3&gt;

&lt;p&gt;The only time we need to pay attention to packages is when we have a name conflict . For example both, java.util and java.sql packages have a class named&lt;br&gt;
Date. So if we import both packages in program as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.*&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.sql.*&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;//And then use Date class, then we will get a compile-time error :&lt;br&gt;
&lt;code&gt;Date today ; //ERROR-- java.util.Date or java.sql.Date?&lt;/code&gt;&lt;br&gt;
The compiler will not be able to figure out which Date class do we want. This problem can be solved by using a specific import statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.Date&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.sql.*&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we need both Date classes then, we need to use a full package name every time we declare a new object of that class.&lt;br&gt;
For Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;util&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;Date&lt;/span&gt; &lt;span class="n"&gt;deadLine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;util&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;Date&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sql&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;Date&lt;/span&gt; &lt;span class="n"&gt;today&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sql&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;Date&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How to compile the Package (if not using IDE)
&lt;/h3&gt;

&lt;p&gt;If you are not using any IDE, you need to follow the syntax given below:&lt;br&gt;
&lt;code&gt;javac -d &amp;lt;directory or dot operator&amp;gt; &amp;lt;javafilename&amp;gt;&lt;/code&gt;&lt;br&gt;
For example&lt;br&gt;
&lt;code&gt;javac -d . Simple.java&lt;/code&gt;&lt;br&gt;
The -d switch specifies the destination where to put the generated class file. You can use any directory name like /home (in case of Linux), d:/abc (in case of windows) etc. If you want to keep the package within the same directory, you can use . (dot).&lt;br&gt;
For more visit &lt;a href="https://dev.to/killallnano/java-for-beginners-installation-of-java-nhc"&gt;Java Installation&lt;/a&gt;.&lt;br&gt;
&lt;strong&gt;How to run the Package (if not using IDE)&lt;/strong&gt;&lt;br&gt;
You need to use fully qualified name e.g. mypack.Simple etc to run the class.&lt;br&gt;
&lt;strong&gt;To Compile:&lt;/strong&gt; &lt;code&gt;javac - d . Simple.java&lt;/code&gt;&lt;br&gt;
The &lt;code&gt;-d&lt;/code&gt; is a switch that tells the compiler where to put the class file i.e. it represents destination. The &lt;code&gt;.&lt;/code&gt; represents the current folder.&lt;/p&gt;

&lt;p&gt;This marks the end of the Java for beginners.&lt;br&gt;
You can learn more about Java through the urls below:&lt;br&gt;
&lt;a href="https://beginnersbook.com/2013/03/packages-in-java/" rel="noopener noreferrer"&gt;https://beginnersbook.com/2013/03/packages-in-java/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/packages-in-java/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/packages-in-java/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.javatpoint.com/package" rel="noopener noreferrer"&gt;https://www.javatpoint.com/package&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you gained something from this article, if yes, let me know in the comment section.&lt;/p&gt;

</description>
      <category>java</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Java for Beginners: Java - Packages</title>
      <dc:creator>Jeff Odhiambo</dc:creator>
      <pubDate>Mon, 07 Mar 2022 18:25:35 +0000</pubDate>
      <link>https://dev.to/smartjeff/java-for-beginners-java-packages-2j1i</link>
      <guid>https://dev.to/smartjeff/java-for-beginners-java-packages-2j1i</guid>
      <description>&lt;p&gt;A &lt;strong&gt;package&lt;/strong&gt; can be defined as a group of similar types of classes, interface, enumeration and sub-package. Enumerations and annotation types are special kinds of classes and interfaces. Packages provide access protection and name space management in a java program. Therefore, a package provides a mechanism for organizing Java classes into namespaces similar to the modules in VB.&lt;br&gt;
Packages are used in Java in order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations easier, etc. Using package it becomes easier to locate the related classes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Package are categorized into two forms:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Built-in Package&lt;/strong&gt;:-Existing Java package for example java.lang and java.util&lt;br&gt;
&lt;strong&gt;User-defined-package&lt;/strong&gt;:- Java package created by user to categorize source files.&lt;/p&gt;
&lt;h2&gt;
  
  
  Built-in Packages
&lt;/h2&gt;

&lt;p&gt;These packages consist of a large number of classes which are a part of Java API. Some of the commonly used built-in packages are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;java.lang&lt;/strong&gt;: Contains language support classes(e.g classed which defines primitive data types, math operations). This package is automatically imported.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;java.io&lt;/strong&gt;: Contains classed for supporting input / output operations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;java.util&lt;/strong&gt;: Contains utility classes which implement data structures like Linked List, Dictionary and support ; for Date / Time operations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;java.applet&lt;/strong&gt;: Contains classes for creating Applets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;java.awt&lt;/strong&gt;: Contain classes for implementing the components for graphical user interfaces (like button , ;menus etc).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;java.net&lt;/strong&gt;: Contain classes for supporting networking operations. And many others.
##User-defined packages
Programmers can define their own packages to bundle group of classes/interfaces etc. It is a good practice to group related classes implemented by you so that a programmers can easily determine that the classes, interfaces, enumerations, annotations are related.
Since the package creates a new namespace there won't be any name conflicts with names in other packages. Using packages, it is easier to provide access control and it is also easier to locate the related classed.
To set up the programmer-defined packages for general reuse, not just use by the programs in the same folder, we have to perform the following tasks:&lt;/li&gt;
&lt;li&gt;Include the statement
&lt;code&gt;package myutil;&lt;/code&gt; as the first statement of the source file for the &lt;code&gt;Fraction class&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The class declaration must include the visibility modifier public as &lt;code&gt;public class Fraction {}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create a folder named &lt;code&gt;myutil&lt;/code&gt; , the same name as the package name. In Java, the package must have a one-to-one correspondence with the folder.&lt;/li&gt;
&lt;li&gt;Place the modified Fraction class into the myutil folder and compile it.&lt;/li&gt;
&lt;li&gt;Modify the &lt;code&gt;CLASSPATH environment variabl&lt;/code&gt;e to include the folder that contains the myutil folder.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Creating a package
&lt;/h2&gt;

&lt;p&gt;To group classes into a package each class must have a package statement defined at the top of a java file. It lets the compiler know which package the class belongs to and must be the first line of code. The syntax for defining a package is:&lt;br&gt;
&lt;code&gt;package &amp;lt;package name&amp;gt;&lt;/code&gt; &lt;br&gt;
NB: A package name is a fully qualified variable name. e.g. package diploma_students. To create your own package, you need to understand that Java uses a file system directory to store them. Just like folders on your computer.&lt;/p&gt;
&lt;h2&gt;
  
  
  Java Package Names and Directory Structure
&lt;/h2&gt;

&lt;p&gt;Organizing classes in a program can take multiple levels so that each package can have as many sub-packages as needed. The Java Package name consists of words separated by periods. The first part of the name represents the organization which created the package. The remaining words of the Java Package name reflect the contents of the package. The Java Package name also reflects its directory structure. &lt;br&gt;
The period "." is used to distinguish the package and sub-package. The period is placed in-between the package names. E.g. package &lt;code&gt;university.college.department.course&lt;/code&gt;&lt;br&gt;
The first part of that package name "university" represents the organization that developed the package. The second part of the package name "college" stands for the contents of the package, in this case the department and lastly the course offered by a given department.&lt;/p&gt;
&lt;h2&gt;
  
  
  The import Keyword
&lt;/h2&gt;

&lt;p&gt;Import keyword is used to import built-in and user-defined packages into your java source file. Packages allow your class to refer to a class that is in another package by directly using its name. &lt;br&gt;
There are 3 different ways to refer to class that is present in different package.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Using fully qualified name (which is not a good practise). &lt;strong&gt;Example&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class myDate extends java.util.Date{
    //body
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Import the only class you need
&lt;strong&gt;Example&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.Date;
class myDate extends Date{
    //body
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Import all classes from a particular package
&lt;strong&gt;Example&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.*;
class myDate extends Date{
    //body
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Importing a Class from an Existing Java Package using the import Keyword:&lt;/strong&gt;&lt;br&gt;
If a class wants to use another class in the same package, the package name does not need to be used. Classes in the same package find each other without any special syntax.&lt;br&gt;
If a class in one package uses details of another class in different package, the class to be used MUST be included in current class using the import statement. E.g.&lt;br&gt;
&lt;code&gt;import javax.swing.JOptionPane;&lt;/code&gt;&lt;br&gt;
Note: The import statement is terminated with a semicolon.&lt;/p&gt;
&lt;h3&gt;
  
  
  How to access Package from another package
&lt;/h3&gt;

&lt;p&gt;There are three ways to access the package from outside the package.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;import package.*;&lt;/li&gt;
&lt;li&gt;import package.classname;&lt;/li&gt;
&lt;li&gt;fully qualified name.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Using packagename.*
&lt;/h3&gt;

&lt;p&gt;If you use package.* then all the classes and interfaces of this package will be accessible but not sub-packages. The import keyword is used to make the classes and interface of another package accessible to the current package.&lt;/p&gt;
&lt;h4&gt;
  
  
  Static import
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;Static import&lt;/code&gt; is a feature that extends the capabilities of &lt;code&gt;import&lt;/code&gt; keyword. It is used to import static member of a class.We will know that static member are referred in association with its class name outside the class. Using static import, its possible to refer to the static member directly without its class name.&lt;/p&gt;

&lt;p&gt;The 2 general form of static statement are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The first form of static import statement, import only a single static member of a class.
&lt;strong&gt;Syntax&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import static package.class-name.static-member-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import static java.lang.Math.sqrt; 
//importing static method sqrt of Math class 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Second form of static import statement, imports all the static member of a class.
&lt;strong&gt;Syntax&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import static package.class-type-name.*;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import static java.lang.Math.*;
//importing all static method of Math class 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example without using static import&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Test {
    public static void main(String[] args) {
        System.out.println(Math.sqrt(144));
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output: &lt;code&gt;12&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Example using static import&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import static java.lang.Math.*;
public class Test{
    public static void main(String[] args) {
        System.out.println(sqrt(144));
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Handling name conflicts
&lt;/h3&gt;

&lt;p&gt;The only time we need to pay attention to packages is when we have a name conflict . For example both, java.util and java.sql packages have a class named&lt;br&gt;
Date. So if we import both packages in program as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.*;
import java.sql.*;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;//And then use Date class, then we will get a compile-time error :&lt;br&gt;
&lt;code&gt;Date today ; //ERROR-- java.util.Date or java.sql.Date?&lt;/code&gt;&lt;br&gt;
The compiler will not be able to figure out which Date class do we want. This problem can be solved by using a specific import statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.Date;
import java.sql.*;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we need both Date classes then, we need to use a full package name every time we declare a new object of that class.&lt;br&gt;
For Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;java.util.Date deadLine = new java.util.Date();
java.sql.Date today = new java.sql.Date();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How to compile the Package (if not using IDE)
&lt;/h3&gt;

&lt;p&gt;If you are not using any IDE, you need to follow the syntax given below:&lt;br&gt;
&lt;code&gt;javac -d &amp;lt;directory or dot operator&amp;gt; &amp;lt;javafilename&amp;gt;&lt;/code&gt;&lt;br&gt;
For example&lt;br&gt;
&lt;code&gt;javac -d . Simple.java&lt;/code&gt;&lt;br&gt;
The -d switch specifies the destination where to put the generated class file. You can use any directory name like /home (in case of Linux), d:/abc (in case of windows) etc. If you want to keep the package within the same directory, you can use . (dot).&lt;br&gt;
For more visit &lt;a href="https://dev.to/killallnano/java-for-beginners-installation-of-java-nhc"&gt;Java Installation&lt;/a&gt;.&lt;br&gt;
&lt;strong&gt;How to run the Package (if not using IDE)&lt;/strong&gt;&lt;br&gt;
You need to use fully qualified name e.g. mypack.Simple etc to run the class.&lt;br&gt;
&lt;strong&gt;To Compile:&lt;/strong&gt; &lt;code&gt;javac - d . Simple.java&lt;/code&gt;&lt;br&gt;
The &lt;code&gt;-d&lt;/code&gt; is a switch that tells the compiler where to put the class file i.e. it represents destination. The &lt;code&gt;.&lt;/code&gt; represents the current folder.&lt;/p&gt;

&lt;p&gt;This marks the end of the Java for beginners.&lt;br&gt;
You can learn more about Java through the urls below:&lt;br&gt;
&lt;a href="https://beginnersbook.com/2013/03/packages-in-java/"&gt;https://beginnersbook.com/2013/03/packages-in-java/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/packages-in-java/"&gt;https://www.geeksforgeeks.org/packages-in-java/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.javatpoint.com/package"&gt;https://www.javatpoint.com/package&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Java for beginners: Polymorphism in Java</title>
      <dc:creator>Jeff Odhiambo</dc:creator>
      <pubDate>Mon, 07 Mar 2022 17:20:24 +0000</pubDate>
      <link>https://dev.to/smartjeff/java-for-beginners-polymorphism-in-java-1ng4</link>
      <guid>https://dev.to/smartjeff/java-for-beginners-polymorphism-in-java-1ng4</guid>
      <description>&lt;p&gt;&lt;strong&gt;Polymorphism&lt;/strong&gt; is the ability of an object to take on many forms. In OOP, polymorphism is the capability of an action or method to do different things based on the object that it is acting upon.&lt;br&gt;
This is the third basic principle of object oriented programming. Polymorphism in Java has two types: &lt;strong&gt;Compile time polymorphism&lt;/strong&gt; (static binding) and &lt;strong&gt;Runtime polymorphism&lt;/strong&gt; (dynamic binding).&lt;/p&gt;
&lt;h2&gt;
  
  
  Compile time (Static) polymorphism
&lt;/h2&gt;

&lt;p&gt;A static polymorphism is one which method binds at compile time, also known as Compile time or static polymorphism. Static polymorphism is achieved through method(function) overloading or operator overloading. But Java doesn’t support the Operator Overloading.&lt;/p&gt;
&lt;h2&gt;
  
  
  Overloaded methods
&lt;/h2&gt;

&lt;p&gt;When there are multiple functions (methods) with same name but different parameters (implementation) then these functions are said to be overloaded. Thus, functions can be overloaded by change in number of arguments or/and change in type of arguments.&lt;br&gt;
These overloaded methods have same name signature but either a different number of parameters or different types in the parameter list. Overloaded methods:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Appear in the same class or a subclass.&lt;/li&gt;
&lt;li&gt;Have the same name but.&lt;/li&gt;
&lt;li&gt;Have different parameter lists.&lt;/li&gt;
&lt;li&gt;Can have different return types.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;At compile time, Java knows which method to invoke by checking the method signatures. So, this is called compile time polymorphism or static binding. The concept will be clear from the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class DemoOverload{
    public int add(int x, int y){ //method 1
        return x+y;
    }
    public int add(int x, int y, int z){ //method 2
        return x+y+z;
    }
    public int add(double x, int y){ //method 3
        return (int)x+y;
    }
    public int add(int x, double y){ //method 4
        return x+(int)y;
    }
}
class Test{
    public static void main(String[] args){
        DemoOverload demo=new DemoOverload();
        System.out.println(demo.add(2,3));
        //method
        System.out.println(demo.add(2,3,4));
        //method
        System.out.println(demo.add(2,3.4));
        //method
        System.out.println(demo.add(2.5,3));
        //method
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Constructor Overloading:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Constructor overloading is a technique in Java in which a class can have any number of constructors that differ in parameter lists.&lt;/li&gt;
&lt;li&gt;The compiler differentiates these constructors by taking into account the number of parameters in the list and their type.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Room
{
    double length,breadth,height;
    Room(double l,double b,double h)
    {
        length=l;
        breadth=b;
        height=h;
    }
    Room()
    {
        length=-1;
        breadth=-1;
        height=-1;
    }
    Room(double len)
    {
        length=breadth=height=len;
    }
    double volume()
    {
        return length*breadth*height;
    }
}
class OverloadConstructors
{
    public static void main(String args[])
    {
        Room a=new Room(20,30,40);
        Room b=new Room();
        Room c=new Room(10);
        double vol;
        vol=a.volume();
        System.out.println("Volume of room a is " + vol);
        vol=b.volume();
        System.out.println("Volume of room b is " + vol);
        vol=c.volume();
        System.out.println("Volume of room c is " + vol);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Limitation:&lt;/strong&gt; Poor utilization of memory resource (main memory).&lt;/p&gt;

&lt;h2&gt;
  
  
  Dynamic (Run Time) Polymorphism:
&lt;/h2&gt;

&lt;p&gt;It is a process in which a function call to the overridden method is resolved at Runtime. This type of polymorphism is achieved by Method Overriding.&lt;br&gt;
Run time polymorphism occurs when a sub class overrides a particular method of the super class.&lt;/p&gt;
&lt;h3&gt;
  
  
  Dynamic Binding (Late Binding)
&lt;/h3&gt;

&lt;p&gt;When a method is invoked, the code to be executed is only determined at run-time. During the compilation, the compiler checks whether the method exists and performs type check on the arguments and return type, but does not know which piece of codes to execute at run-time. When a message is sent to an object to invoke a method, the object figures out which piece of codes to execute at run-time. This mechanism is called &lt;strong&gt;dynamic binding&lt;/strong&gt; (or &lt;strong&gt;late-binding&lt;/strong&gt; or &lt;strong&gt;run-time binding&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;In polymorphism, Dynamic (or late) method binding is the ability of a program to resolve references to subclass methods at runtime.&lt;/p&gt;
&lt;h2&gt;
  
  
  Overridden Methods
&lt;/h2&gt;

&lt;p&gt;Overridden methods are methods of a super class that are redefined(defined again) within a subclass.&lt;br&gt;
In Java, you can create a method in a superclass (or parent class), then in a subclass ALSO define that&lt;br&gt;
method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Vehicle{
    public void move(){
        System.out.println("Vehicles can move!!");
    }
}
class MotorBike extends Vehicle{
    public void move(){
        System.out.println("MotorBike can move and accelerate too!!");
    }
}
class Test{
    public static void main(String[] args){
        Vehicle vh=new MotorBike();
        vh.move(); // prints MotorBike can move and accelerate too!!
        vh=new Vehicle();
        vh.move(); // prints Vehicles can move!!
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It should be noted that in the first call to move(), the reference type is Vehicle and the object being referenced is MotorBike. So, when a call to move() is made, Java waits until runtime to determine&lt;br&gt;
which object is actually being pointed to by the reference. In this case, the object is of the class MotorBike. So, the move() method of MotorBike class will be called. In the second call to move(), the object is of the class Vehicle. So, the move() method of Vehicle will be called. As the method to call is determined at runtime, this is called &lt;strong&gt;dynamic binding&lt;/strong&gt; or &lt;strong&gt;late binding&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Overriding:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;applies ONLY to inherited methods is related to polymorphism&lt;/li&gt;
&lt;li&gt;object type (NOT reference variable type) determines which overridden method will be used at runtime&lt;/li&gt;
&lt;li&gt;overriding method MUST have the same argument list (if not, it might be a case of overloading)&lt;/li&gt;
&lt;li&gt;overriding method MUST have the same return type; the exception is covariant return (used as of Java 5) which returns a type that is a subclass of what is returned by the overridden method&lt;/li&gt;
&lt;li&gt;overriding method MUST NOT have more restrictive access modifier, but MAY have less restrictive one&lt;/li&gt;
&lt;li&gt;overriding method MUST NOT throw new or broader checked exceptions, but MAY throw fewer or narrower checked exceptions or any unchecked exceptions&lt;/li&gt;
&lt;li&gt;abstract methods MUST be overridden&lt;/li&gt;
&lt;li&gt;final methods CANNOT be overridden&lt;/li&gt;
&lt;li&gt;static methods CANNOT be overridden&lt;/li&gt;
&lt;li&gt;constructors CANNOT be overridden
##Upcasting &amp;amp; Downcasting
&lt;strong&gt;Upcasting a Subclass Instance to a Superclass Reference&lt;/strong&gt;
Substituting a subclass instance for its superclass is called "upcasting". This is because, in a UML class diagram, subclass is often drawn below its superclass. Upcasting is always safe because a subclass instance possesses all the properties of its superclass and can do whatever its superclass can do. The compiler checks for valid upcasting and issues error "incompatible types" otherwise.
For example,
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Circle c1 = new Cylinder(); // Compiler checks to ensure that R-value is a subclass of L-value
Circle c2 = new String(); // Compilation error: incompatible types
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Downcasting a Substituted Reference to Its Original Class&lt;/strong&gt;&lt;br&gt;
You can revert a substituted instance back to a subclass reference. This is called "downcasting". For&lt;br&gt;
example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Cycle c1 = new Cylinder(5.0); // upcast is safe
Cylinder aCylinder = (Cylinder) c1; // downcast needs the casting operator
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Downcasting requires explicit type casting operator in the form of prefix operator (new-type).&lt;br&gt;
Downcasting is not always safe, and throws a runtime &lt;code&gt;ClassCastException&lt;/code&gt; if the instance to be downcasted does not belong to the correct subclass. A subclass object can be substituted for its superclass, but the reverse is not true.&lt;br&gt;
Compiler may not be able to detect error in explicit cast, which will be detected only at runtime.&lt;br&gt;
For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Circle c1 = new Circle(5);
Point p1 = new Point();
c1 = p1; // compilation error: incompatible types (Point is not subclass of Circle)
c1 = (Circle)p1; // runtime error: java.lang.ClassCastException: Point cannot be casted to Circle
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The &lt;code&gt;instanceof&lt;/code&gt; Operator&lt;/strong&gt;&lt;br&gt;
Java provides a binary operator called &lt;code&gt;instanceof&lt;/code&gt; which returns true if an object is an instance of a particular class. The syntax is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//anObjectinstanceofaClass
Circle c1 = new Circle();
System.out.println(c1 instanceof Circle); // true
if (c1 instanceof Cirlce){
    //body
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An instance of subclass is also an instance of its superclass. For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Circle c1 = new Circle(5);
Cylinder cy1 = new Cylinder(5, 2);
System.out.println(c1 instanceof Circle); //true
System.out.println(c1 instanceof Cylinder); //false
System.out.println(cy1 instanceof Cylinder); //true
System.out.println(cy1 instanceof Circle);  //true

Circle c2 = new Cylinder(5, 2);
System.out.println(c2 instanceof Circle); //true
System.out.println(c2 instanceof Cylinder); //true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Summary:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The method binding happens at the compile time i.e which methods can be invoked on a given reference type is decided at the compile time.&lt;/li&gt;
&lt;li&gt;The selection of the method’s implementation to execute happens at the run time i.e which implementation of the method to be executed i.e the super class version or one of the subclass’s version is decided at the run time and this is what leads to the runtime polymorphism.&lt;/li&gt;
&lt;li&gt;An object in Java that passes more than one IS-A tests is polymorphic in nature&lt;/li&gt;
&lt;li&gt;Static polymorphism in Java is achieved by method overloading&lt;/li&gt;
&lt;li&gt;Dynamic polymorphism in Java is achieved by method overriding&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Our last article on Java for beginners will be on &lt;a href="https://dev.to/killallnano/java-for-beginners-java-packages-2j1i"&gt;Java Packages&lt;/a&gt;. If you missed the previous articles on Java for beginners check on them through the links below&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/killallnano/java-for-beginners-introduction-to-java-36kn"&gt;Java for Beginners: Introduction to Java&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/killallnano/java-for-beginners-installation-of-java-nhc"&gt;Java for beginners: Installation of Java&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.to/killallnano/java-for-beginners-fundamentals-of-java-3601"&gt;Java for beginners: Fundamentals of Java&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.to/killallnano/java-object-oriented-programming-6bm"&gt;Java Object Oriented Programming&lt;/a&gt; 
Thanks for taking your time to read this article. see you in the &lt;a href="https://dev.to/killallnano/java-for-beginners-java-packages-2j1i"&gt;next article&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>java</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Java Object Oriented Programming</title>
      <dc:creator>Jeff Odhiambo</dc:creator>
      <pubDate>Mon, 07 Mar 2022 10:43:46 +0000</pubDate>
      <link>https://dev.to/smartjeff/java-object-oriented-programming-6bm</link>
      <guid>https://dev.to/smartjeff/java-object-oriented-programming-6bm</guid>
      <description>&lt;p&gt;Object-oriented programming takes advantage of our perception of world. An &lt;strong&gt;object&lt;/strong&gt; is an encapsulated completely-specified data aggregate containing attributes and behavior.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data hiding&lt;/strong&gt; protects the implementation from interference by other objects and defines approved interface. An object-oriented program is a growing and shrinking collection of objects that interact via messages. &lt;/p&gt;

&lt;p&gt;You can send the same message to similar objects--the target decides how to implement or respond to a message at run-time. Objects with same characteristics are called &lt;strong&gt;instances&lt;/strong&gt; of a class.&lt;br&gt;
This article extends&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://dev.to/killallnano/java-for-beginners-introduction-to-java-36kn"&gt;Java for Beginners: Introduction to Java&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/killallnano/java-for-beginners-installation-of-java-nhc"&gt;Java for beginners: Installation of Java&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.to/killallnano/java-for-beginners-fundamentals-of-java-3601"&gt;Java for beginners: Fundamentals of Java&lt;/a&gt; 
Kindly check on them to have a better understanding on this article.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Benefits of object-oriented programming include:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Troubleshooting is easy in OOP through modularity&lt;/li&gt;
&lt;li&gt;Benefit of code re-usability through inheritance&lt;/li&gt;
&lt;li&gt;Data redundancy is reduced&lt;/li&gt;
&lt;li&gt;Code flexibility emphasis through polymorphism&lt;/li&gt;
&lt;li&gt;Effective problem solving.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Java Classes
&lt;/h2&gt;

&lt;p&gt;A class is essentially an abstract data type that provides a template from which objects are created. Class consists of a collection of data together with functions that operate on the data. &lt;br&gt;
&lt;code&gt;Data&lt;/code&gt; is referred to as data members and &lt;code&gt;functions&lt;/code&gt; are referred to as member functions of a class. By declaring a class we create a new data type that is as powerful as any of the basic types.&lt;/p&gt;
&lt;h3&gt;
  
  
  class syntax
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class &amp;lt;classname&amp;gt;{
    //body
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Student{
    //body
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Class data member
&lt;/h3&gt;

&lt;p&gt;In a class, the members are by default hidden within the class and cannot be accessed from outside. We say that the members of a class are declared private by default. However, if we want to, we can declare members of a class to be public.&lt;br&gt;
&lt;strong&gt;Syntax&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class &amp;lt;classname&amp;gt;{
    &amp;lt;data_type&amp;gt; &amp;lt;variable_name&amp;gt;;
    //body
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Student{
    String student_name;
    int marks;
    Character grade;
    //body
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Class member functions (methods)
&lt;/h3&gt;

&lt;p&gt;Member functions of a class are also referred to as methods. If we make the member data of our student class private, we should provide functions to access the data for setting, manipulating or printing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Encapsulation and data hiding
&lt;/h3&gt;

&lt;p&gt;Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods. If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class.&lt;br&gt;
Encapsulation can be described as a protective barrier that prevents the code and data being randomly accessed by other code defined outside the class. Access to the data and code is tightly controlled by an interface.&lt;br&gt;
Encapsulation gives maintainability, flexibility and extensibility to our code. Data encapsulation led to the important OOP concept of data hiding.&lt;/p&gt;
&lt;h3&gt;
  
  
  Java Variable Types
&lt;/h3&gt;

&lt;p&gt;In Java, all variables must be declared before they can be used. The basic form of a variable declaration is shown here:&lt;br&gt;
&lt;code&gt;&amp;lt;type&amp;gt; &amp;lt;identifier&amp;gt; = &amp;lt;value&amp;gt;;&lt;/code&gt; e.g&lt;br&gt;
&lt;code&gt;String name = "Jeff Odhiambo";&lt;/code&gt;&lt;br&gt;
The &lt;strong&gt;type&lt;/strong&gt; is one of Java's data types. The &lt;strong&gt;identifier&lt;/strong&gt; is the name of the variable. To declare more than one variable of the specified type, use a comma-separated list.&lt;br&gt;
Java supports the following types of variables:&lt;/p&gt;
&lt;h4&gt;
  
  
  1. Local variables
&lt;/h4&gt;

&lt;p&gt;Local variables are declared in methods, constructors, or blocks. Local variables are created when the method, constructor or block is entered and the variable will be destroyed once it exits the method, constructor or block. Access modifiers cannot be used for local variables. Local variables are visible only within the declared method, constructor or block. Local variables are implemented at stack level internally. There is no default value for local variables so local variables&lt;br&gt;
should be declared and an initial value should be assigned before the first use.&lt;/p&gt;
&lt;h4&gt;
  
  
  2. Class (static) Variables
&lt;/h4&gt;

&lt;p&gt;Class variables are shared by all the instances of the class. Class variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block. Class methods are not tied to a specific object.&lt;br&gt;
There would only be one copy of each class variable per class, regardless of how many objects are created from it. Static variables are created when the program starts and destroyed when the program stops. Static variables can be accessed by calling with the class name. Syntax &lt;code&gt;ClassName.VariableName&lt;/code&gt; e.g &lt;code&gt;Math.PI&lt;/code&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  3. Constants (Final Variables)
&lt;/h4&gt;

&lt;p&gt;Any variable either member variable or local variable (declared inside method or block) modified by final keyword is called &lt;strong&gt;final variable&lt;/strong&gt;. Final variables are often declare with static keyword in java and treated as constant. A final variable can only be initialized once, either via an initializer or an assignment statement.&lt;br&gt;
Class constants are final variables shared by all the instances of the class. Class variables, constants, and methods are used with class name, such as &lt;code&gt;Math.pow(2,3)&lt;/code&gt;, &lt;code&gt;Math.PI&lt;/code&gt;.&lt;br&gt;
To declare class variables, constants, and methods, use the static modifier.&lt;br&gt;
When declaring class variables as public static final, then variables names (constants) are all in upper case. If the static variables are not public and final&lt;br&gt;
the naming syntax is the same as instance and local variables.&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.io.*;
public class Employee{
    // salary variable is a private static variable
    private static double salary;
    // DEPARTMENT is a constant
    public static final String DEPARTMENT = "Development ";
    public static void main(String args[]){
        salary = 1000;
        System.out.println(DEPARTMENT+"average salary:"+salary);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Instance variables
&lt;/h4&gt;

&lt;p&gt;Instance variables are declared in a class, but outside a method, constructor or any block. When a space is allocated for an object in the heap a slot for each instance variable value is created. Instance variables are created when an object is created with the use of the key word 'new' and destroyed when the object is destroyed.&lt;br&gt;
Instance variables hold values that must be referenced by more than one method, constructor or block, or essential parts of an object’s state that must be present throughout the class. Instance variables can be declared in class level before or after use. Access modifiers can be given for instance variables.&lt;/p&gt;

&lt;p&gt;The instance variables are visible for all methods, constructors and block in the class. Normally it is recommended to make these variables private (access level). However visibility for sub classes can be given for these variables with the use of access modifiers.&lt;br&gt;
Instance variables have default values. For numbers the default value is 0, for Booleans it is false and for object references it is null. Values can be assigned during the declaration or within the constructor.&lt;br&gt;
Instance variables can be accessed directly by calling the variable name inside the class. However within static methods and different class ( when instance variables are given accessibility) the should be called using the fully qualified name . &lt;code&gt;ObjectReference.VariableName&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Scope of Variables
&lt;/h3&gt;

&lt;p&gt;The scope of instance and class variables is the entire class. They can be declared anywhere inside a class. They are global variables. The scope of a local variable starts from its declaration and continues to the end of the block that contains the variable. A local variable must be declared before it can be used.&lt;br&gt;
E.g.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YeTfaKwb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6pbgwqu5inaxp9ys52wn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YeTfaKwb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6pbgwqu5inaxp9ys52wn.png" alt="Scope of variable" width="880" height="504"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Visibility Modifiers and Accessor Methods
&lt;/h3&gt;

&lt;p&gt;By default, the class, variable, or data can be accessed by any function in the class in which they are declared. &lt;strong&gt;Visibility modifiers include:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Public&lt;/strong&gt; - The class, data, or method is visible to any class in any package.&lt;br&gt;
&lt;strong&gt;Private&lt;/strong&gt; - The data or methods can be accessed only by the declaring class.&lt;br&gt;
&lt;strong&gt;Protected&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Accessor methods(Setters and Getters Methods)
&lt;/h3&gt;

&lt;p&gt;The getter and setter accessor methods are used to read and modify private properties in a class. These methods are also called accessor methods. &lt;br&gt;
&lt;strong&gt;The syntax for accessor methods is:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class AccessorExample {
    private String attribute;
    public String getAttribute() {
        return attribute;
    }
    public void setAttribute(String attribute) {
        this.attribute = attribute;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Java this Keyword
&lt;/h3&gt;

&lt;p&gt;The keyword this in Java refers to the current class instance. Within an instance method or a constructor, this is a reference to the current object. Therefore, this can be used inside any method to refer to the current object. You can refer to any member of the current object from within an instance method or a constructor by using this . The keyword can also be used to call overloaded constructors.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using &lt;code&gt;this&lt;/code&gt; to access a shadowed field
&lt;/h3&gt;

&lt;p&gt;The most common reason for using the this keyword is because a field is shadowed by a method or constructor parameter.&lt;br&gt;
For example, the &lt;code&gt;Point class&lt;/code&gt; was written like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Point {
    public int x = 0;
    public int y = 0;
    //constructor
    public Point(int a, int b) {
        x = a;
        y = b;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but it could have been written like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Point {
    public int x = 0;
    public int y = 0;
    //constructor
    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each argument to the constructor shadows one of the object's fields — inside the constructor x is a local copy of the constructor's first argument. To refer to the Point field &lt;code&gt;x&lt;/code&gt; , the constructor must use &lt;code&gt;this.x&lt;/code&gt; .&lt;/p&gt;

&lt;h3&gt;
  
  
  Using this to call a Constructor from another constructor
&lt;/h3&gt;

&lt;p&gt;From within a constructor, you can also use the &lt;code&gt;this&lt;/code&gt; keyword to call another constructor in the same class. Doing so is called an &lt;code&gt;explicit constructor invocation&lt;/code&gt;. Here's another Rectangle class, with a different implementation from the one in the Objects section.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Rectangle {
    private int x, y;
    private int width, height;
    public Rectangle() {
        this(0, 0, 0, 0);
    }
    public Rectangle(int width, int height) {
        this(0, 0, width, height);
    }
    public Rectangle(int x, int y, int width, int height) {
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This class contains a set of constructors. Each constructor initializes some or all of the rectangle's member variables. The constructors provide a default value for any member variable whose initial value is not provided by an argument.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data encapsulation
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Data encapsulation&lt;/strong&gt; is a mechanism of bundling the data, and the functions that use them.&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Student {
    private String name;
    private String idNum;
    private int age;

    public int getAge() {
        return age;
    }
    public String getName() {
        return name;
    }
    public String getIdNum() {
        return idNum;
    }
    public void setAge(int newAge) {
        age = newAge;
    }
    public void setName(String newName) {
        name = newName;
    }
    public void setIdNum(String newId) {
        idNum = newId;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Encapsulation using “this” Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Student{
    private String name;
    private String idNum;
    private int age;
    public int getAge(){
        return age;
    }
    public String getName(){
        return name;
    }
    public String getIdNum(){
        return idNum;
    }
    public void setAge( int age){
        this.age = age;
    }
    public void setName(String name){
        this.name = name;
    }
    public void setIdNum( String idNum){
        this.idNum = idNum;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Advantage of Encapsulation in Java and OOPS
&lt;/h3&gt;

&lt;p&gt;Here are few advantages of using Encapsulation while writing code in Java or any Object oriented programming language:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Encapsulated Code is more flexible and easy to change with new requirements.&lt;/li&gt;
&lt;li&gt;Encapsulation in Java makes unit testing easy.&lt;/li&gt;
&lt;li&gt;Encapsulation in Java allows you to control who can access what.&lt;/li&gt;
&lt;li&gt;Encapsulation also helps to write immutable class in Java which are a good choice in multi-threading environment.&lt;/li&gt;
&lt;li&gt;Encapsulation reduce coupling of modules and increase cohesion inside a module because all piece of one thing are encapsulated in one place.&lt;/li&gt;
&lt;li&gt;Encapsulation allows you to change one part of code without affecting other part of code.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Relationships among Classes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Association
&lt;/h3&gt;

&lt;p&gt;Association is a relationship between two objects. Association represents a general binary relationship that describes an activity between two classes.&lt;br&gt;
The association relationship is a way of describing that a class knows about and holds a reference to another class.&lt;br&gt;
You may be aware of one-to-one, one-to-many, many-to-one, many-to-many all these words define an association between objects.&lt;/p&gt;
&lt;h3&gt;
  
  
  Aggregation
&lt;/h3&gt;

&lt;p&gt;Aggregation is a relationship between two classes that is best described as a "has-a" and "whole/part" relationship.&lt;br&gt;
Aggregation models the relationship like has-a, part-of, owns, and employed-by. When an object ‘has-a’ another object, then you have got an aggregation between them.&lt;br&gt;
Direction between them specifies which object contains the other object. Aggregation is also called a &lt;code&gt;“Has-a” relationship.&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
There is an aggregation relationship between Student class and the Subject class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Subject {
    private String name;

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }
}
public class Student {
    private Subject[] studyAreas = new Subject[10];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Find more examples &lt;a href="http://www.javatpoint.com/aggregation-in-java"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Composition
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Composition&lt;/strong&gt; is restricted aggregation. When an object contains the other object,i.e., if the contained object cannot exist without the existence of container object, then it is called composition.&lt;br&gt;
&lt;strong&gt;Example:&lt;/strong&gt; A class contains students. A student cannot exist without a class.&lt;br&gt;
There exists composition between class and students.&lt;/p&gt;
&lt;h3&gt;
  
  
  Abstraction
&lt;/h3&gt;

&lt;p&gt;Abstraction is specifying the framework and hiding the implementation level information. Concreteness will be built on top of the abstraction. It gives you a&lt;br&gt;
blueprint to follow to while implementing the details. Abstraction reduces the complexity by hiding low level details.&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt;: A wire frame model of a car.&lt;/p&gt;
&lt;h3&gt;
  
  
  Generalization
&lt;/h3&gt;

&lt;p&gt;Generalization uses a “is-a” relationship from a specialization to the generalization class. Common structure and behavior are used from the specialization to the generalized class. At a very broader level you can understand this as &lt;code&gt;inheritance&lt;/code&gt;. Why I take the term inheritance is, you can relate this term very well.&lt;br&gt;
&lt;strong&gt;Example:&lt;/strong&gt; Consider there exists a class named Person. A student is a person. A faculty is a person. Therefore here the relationship between student and person, similarly faculty and person is generalization.&lt;/p&gt;
&lt;h3&gt;
  
  
  Realization
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Realization&lt;/strong&gt; is a relationship between the blueprint class and the object containing its respective implementation level details. This object is said to&lt;br&gt;
realize the blueprint class. In other words, you can understand this as the relationship between the interface and the implementing class.&lt;br&gt;
&lt;strong&gt;Example:&lt;/strong&gt; A particular model of a car ‘GTB Fiorano’ that implements the blueprint of a car realizes the abstraction.&lt;/p&gt;
&lt;h3&gt;
  
  
  Dependency
&lt;/h3&gt;

&lt;p&gt;Change in structure or behavior of a class affects the other related class, then there is a dependency between those two classes. It need not be the same on the vice-&lt;br&gt;
versa. When one class contains the other class this happens.&lt;br&gt;
&lt;strong&gt;Example:&lt;/strong&gt; Relationship between shape and circle is dependency.&lt;/p&gt;
&lt;h3&gt;
  
  
  Inheritance (developed from)
&lt;/h3&gt;

&lt;p&gt;Inheritance models the “is-a” relationship between two classes. It is a mechanism where a new class is derived from an existing class.&lt;br&gt;
In Java, classes may inherit or acquire the non private properties and methods of other classes. A class derived from another class is called a &lt;code&gt;subclass&lt;/code&gt;, whereas&lt;br&gt;
the class from which a subclass is derived is called a &lt;code&gt;super class&lt;/code&gt;. A subclass can have only one super class, whereas a super class may have one or more sub classes.&lt;/p&gt;

&lt;p&gt;Any class in java that does not extend any other class implicitly extends Object class. Therefore, the &lt;strong&gt;java.lang.Object&lt;/strong&gt; class is always at the top of any Class inheritance hierarchy.&lt;br&gt;
In Java, inheritance is used for two purposes:&lt;br&gt;
&lt;strong&gt;1. Class inheritance&lt;/strong&gt; - create a new class as an extension of another class, primarily for the purpose of code reuse. That is, the derived class inherits the public methods and public data of the base class. Java only allows a class to have one immediate base class,&lt;br&gt;
i.e., single class inheritance. The keyword “extends” is used to derive a subclass from the superclass, as illustrated by the following syntax:&lt;br&gt;
&lt;strong&gt;syntax&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class derived-class-name extends base-class-name {
// derived class methods extend and possibly override those of the base class
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class A{
//properties and methods of A
}
class B extends A {
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Class inheritance defines a is-a relationship between a superclass and its subclasses. Therefore inheritance is achieved at class level. We can therefore define inheritance in java as mechanism is used to build new classes from existing classes.&lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Animal{
}
public class Mammal extends Animal{
}
public class Reptile extends Animal{
}
public class Dog extends Mammal{
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Object Oriented terms following are true:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Animal is the super class of Mammal class.&lt;/li&gt;
&lt;li&gt;Animal is the super class of Reptile class.&lt;/li&gt;
&lt;li&gt;Mammal and Reptile are sub classes of Animal class.&lt;/li&gt;
&lt;li&gt;Dog is the subclass of both Mammal and Animal classes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now if we consider the IS-A relationship we can say:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mammal IS-A Animal&lt;/li&gt;
&lt;li&gt;Reptile IS-A Animal&lt;/li&gt;
&lt;li&gt;Dog IS-A Mammal&lt;/li&gt;
&lt;li&gt;Hence : Dog IS-A Animal as well
With use of extends keyword the sub classes will be able to inherit all the properties of the super class except for the private properties of the super class.
Below is a sample implementation of the Dog class:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Dog extends Mammal{
    public static void main(String args[]){
        Animal a = new Animal();
        Mammal m = new Mammal();
        Dog d = new Dog();
        System.out.println(m instanceof Animal);//Outputs true
        System.out.println(d instanceof Mammal); //Outputs true
        System.out.println(d instanceof Animal); //Outputs true
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Boolean &lt;code&gt;instanceof&lt;/code&gt; operator is used to determine whether Mammal is actually an Animal, and dog is actually an Animal.&lt;/p&gt;

&lt;h3&gt;
  
  
  super keyword
&lt;/h3&gt;

&lt;p&gt;‘super’ is used for pointing the super class instance. That is, it is a reference variable that is used to refer immediate parent class object.&lt;br&gt;
The keyword super will therefore be used when referring to the super class of an object.&lt;/p&gt;
&lt;h3&gt;
  
  
  Uses of super Keyword
&lt;/h3&gt;

&lt;p&gt;super is used to refer immediate parent class instance variable.&lt;br&gt;
super() is used to invoke immediate parent class constructor.&lt;br&gt;
super is used to invoke immediate parent class method.&lt;br&gt;
&lt;strong&gt;Using the super keyword to call immediate parent class constructor&lt;/strong&gt;&lt;br&gt;
The syntax for calling a super class constructor is&lt;br&gt;
&lt;code&gt;super();&lt;/code&gt; or &lt;code&gt;super(parameter list);&lt;/code&gt;&lt;br&gt;
NB: In a constructor, super MUST always be the first statement to appear:&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Vehicle{
    Vehicle(){
        System.out.println("Vehicle is created");
    }
    Void start(){
        System.out.println("Vehicle is starting...");
    }
}
class Bike extends Vehicle{
    Bike(){
        super();//will invoke parent class constructor
        System.out.println("Bike is created");
    }
    public static void main(String args[]){
        Bike b=new Bike();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Vehicle is created
Bike is created
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With super(), the super class no-argument constructor is called. With super(parameter list), the super class constructor with a matching parameter list is called. If accessing a method in super class, we use the syntax:&lt;br&gt;
&lt;code&gt;super.methodName( argument(s))&lt;/code&gt;&lt;br&gt;
&lt;code&gt;super.start();&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Method Overriding
&lt;/h2&gt;

&lt;p&gt;When a sub class defines a method that has same name signature and return type (or compatible with return type of super class method) it is called method overriding. In object oriented terms, overriding means to override the functionality of any existing method.&lt;br&gt;
The benefit of overriding is: ability to define a behavior that's specific to the sub class type. Which means a subclass can implement a parent class method based on its requirement.&lt;br&gt;
Consider the following example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Animal{
    public void move(){
        System.out.println("Animals can move");
    }
}
class Dog extends Animal{
    public void move(){
        System.out.println("Dogs can walk and run");
    }
}
public class TestDog{
    public static void main(String args[]){
        Animal a = new Animal(); // Animal reference and object
        Animal b = new Dog(); // Animal reference but Dog object
        a.move();// runs the method in Animal class
        b.move();//Runs the method in Dog class
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would produce following result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Animals can move
Dogs can walk and run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example you can see that the even though b is a type of Animal it runs the move method in the Dog class. The reason for this is : In compile time the check is made on the reference type. However in the runtime JVM figures out the object type and would run the method that belongs to that particular object.&lt;br&gt;
Therefore in the above example, the program will compile properly since Animal class has the method move. Then at the runtime it runs the method specific for that object.&lt;br&gt;
Consider the following example :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Animal {
    public void move() {
        System.out.println("Animals can move");
    }
}
class Dog extends Animal {
    public void move() {
        System.out.println("Dogs can walk and run");
    }

    public void bark() {
        System.out.println("Dogs can bark");
    }
}
public class TestDog {
    public static void main(String args[]) {
        Animal a = new Animal(); // Animal reference and object
        Animal b = new Dog(); // Animal reference but Dog object

        a.move();// runs the method in Animal class
        b.move();//Runs the method in Dog class
        b.bark();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would produce following result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TestDog.java:30: cannot find symbol
symbol : method bark()
location: class Animal
b.bark();
  ^
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This program will throw a compile time error since b's reference type Animal doesn't have a method by the name of bark.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using the super keyword to call overridden method
&lt;/h3&gt;

&lt;p&gt;When invoking a super class version of an overridden method the super keyword is used.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Animal{
    public void move(){
        System.out.println("Animals can move");
    }
}
class Dog extends Animal{
    public void move(){
        super.move(); // invokes the super class method
        System.out.println("Dogs can walk and run");
    }
}
public class TestDog{
    public static void main(String args[]){
        Animal b = new Dog(); // Animal reference but Dog object
        b.move(); //Runs the method in Dog class
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would produce following result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Animals can move
Dogs can walk and run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Rules for method overriding:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The argument list should be exactly the same as that of the overridden method.&lt;/li&gt;
&lt;li&gt;The return type should be the same or a sub type of the return type declared in the original overridden method in the super class.&lt;/li&gt;
&lt;li&gt;The access level cannot be more restrictive than the overridden method's access level. For example: if the super class method is declared public then the overridding method in the sub class cannot be either private or protected.&lt;/li&gt;
&lt;li&gt;Instance methods can be overridden only if they are inherited by the subclass.&lt;/li&gt;
&lt;li&gt;A method declared final cannot be overridden.&lt;/li&gt;
&lt;li&gt;A method declared static cannot be overridden but can be re-declared.&lt;/li&gt;
&lt;li&gt;If a method cannot be inherited then it cannot be overridden.&lt;/li&gt;
&lt;li&gt;A subclass within the same package as the instance's superclass can override any superclass method that is not declared private or final.&lt;/li&gt;
&lt;li&gt;A subclass in a different package can only override the non-final methods declared public or protected.&lt;/li&gt;
&lt;li&gt;An overriding method can throw any uncheck exceptions, regardless of whether the overridden method throws exceptions or not. However the overriding method should not throw checked exceptions that are new or broader than the ones declared by the overridden method. The overriding method can throw narrower or fewer exceptions than the overridden method.&lt;/li&gt;
&lt;li&gt;Constructors cannot be overridden.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Data abstraction
&lt;/h2&gt;

&lt;p&gt;Abstraction is the concept of object-oriented programming that “shows” only essential attributes and “hides” unnecessary information. The main purpose of abstraction is hiding the unnecessary details from the users. The implementation details is hidded from the user. Abstraction is achieved using either abstract classes or interfaces.&lt;/p&gt;

&lt;h2&gt;
  
  
  Class Abstraction
&lt;/h2&gt;

&lt;p&gt;Class abstraction means to separate class implementation from the use of the class. The creator of the class provides a description of the class and let the user know how the class can be used. The user of the class does not need to know how the class is implemented. The detail of implementation is encapsulated and hidden from the user.&lt;/p&gt;

&lt;h2&gt;
  
  
  Abstract Classes and Abstract Methods
&lt;/h2&gt;

&lt;p&gt;An &lt;strong&gt;abstract class&lt;/strong&gt; is a restricted class that cannot be used to create objects (to access it, it must be inherited from another class). An abstract class leaves one or more method implementations unspecified by declaring one or more methods abstract. An abstract can only be used as a super class for other classes that&lt;br&gt;
extend the abstract class. Abstract classes are declared with the abstract keyword. Abstract classes are used to provide a template or design for concrete subclasses down the inheritance tree.&lt;br&gt;
&lt;strong&gt;Abstract methods&lt;/strong&gt; are methods with no body specification (implementation).&lt;br&gt;
Abstract methods can only be used in an abstract class, and it does not have a body. I.e Abstract method would have no definition, and its signature is followed by a semicolon, not curly braces. The body is provided by the subclass (inherited from).&lt;br&gt;
The &lt;strong&gt;abstract keyword&lt;/strong&gt; is a non-access modifier, used for classes and methods. The abstract keyword is used to declare a class or a method as abstract. An abstract method consists of a method signature, but no method body.&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract class Shape {
    public String color;

    public Shape() {
    }

    public void setColor(String c) {
        color = c;
    }

    public String getColor() {
        return color;
    }

    abstract public double area();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that If a class has at least one abstract method, the class must be declared as abstract.&lt;br&gt;
A subclass is therefore required to override the abstract method and provide an implementation. Subclasses must provide the method statements for their particular meaning. If the method was one provided by the superclass, it would require overriding in each subclass. Hence, an abstract class is incomplete and cannot be instantiated, but can be used as a base class.&lt;br&gt;
The abstract class guarantees that each shape will have the same set of basic properties. We declare this class abstract because there is no such thing as a generic shape. There can only be concrete shapes such as squares, circles, triangles etc.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Point extends Shape {
    static int x, y;

    public Point() {
        x = 0;
        y = 0;
    }

    public double area() {
        return 0;
    }

    public double perimeter() {
        return 0;
    }

    public static void print() {
        System.out.println("point: " + x + "," + y);
    }

    public static void main(String args[]) {
        Point p = new Point();
        p.print();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Points to Remember&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An abstract class must be declared with an abstract keyword.&lt;/li&gt;
&lt;li&gt;It can have abstract and non-abstract methods.&lt;/li&gt;
&lt;li&gt;It cannot be instantiated.&lt;/li&gt;
&lt;li&gt;It can have constructors and static methods also.&lt;/li&gt;
&lt;li&gt;It can have final methods which will force the subclass not to change the body of the method.
##Interfaces
An interface in Java is a blueprint of a class. It consists of static constants and abstract methods. In Java, an interface is a mechanism to achieve abstraction.
There can be only abstract methods in a Java interface. No need to include keyword abstract when declaring abstract methods in in interface.
Just like an abstract class, an interface cannot be instantiated.
You can declare an interface in its own file like a class. In such a case, File name must be the same as the class name. Java Interface also represents the IS-A relationship.
###Declaring Interfaces
The interface keyword is used to declare an interface.
Syntax:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface &amp;lt;interface_name&amp;gt;{
// declare constant fields
// declare abstract methods
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* File name : Animal.java */
interface Animal {
    public void eat();
    public void travel();}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Implementing an interface
&lt;/h3&gt;

&lt;p&gt;Class inheritance in java uses the keyword extends. To access the interface methods, the interface must be "implemented" (inherited) by another class using the implements keyword (instead of extends). During implementation the body of each interface method is provided by the "implementing" class:&lt;br&gt;
Syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class class-name implements interface-name {
// class provides an implementation for the methods
// as specified by the interface
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface Animal {
    public void makeSound(); // interface method (does not have a body)

    public void sleep(); // interface method (does not have a body)}

    //Donkey "implements" the Animal interface
    class Donkey implements Animal {
        public void makeSound() {
            // The body of animalSound() is provided here
            System.out.println("The donkey says: hee hoo");
        }

        public void sleep() {
            // The body of sleep() is provided here
            System.out.println("Zzz");
        }
    }

    public class DonkeyImpl {
        public static void main(String[] args) {
            Donkey dnk = new Donkey();
            // Create a Donkey object
            dnk.makeSound();
            dnk.sleep();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why use Java interface?
&lt;/h3&gt;

&lt;p&gt;There are mainly three reasons to use interface. They are given below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is used to achieve abstraction.&lt;/li&gt;
&lt;li&gt;By interface, we can support the functionality of multiple inheritance.&lt;/li&gt;
&lt;li&gt;It can be used to achieve loose coupling.
Interfaces are preferred to classes because they help us to to achieve abstraction as well
as multiple inheritance in Java.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Extending Interfaces
&lt;/h3&gt;

&lt;p&gt;An interface can extend another interface in the same way that a class can extend another class. The extends keyword is used to extend an interface, and the child&lt;br&gt;
interface inherits the methods of the parent interface.&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Filename: Sports.java
public interface Sports {
    public void setHomeTeam(String name);
    public void setVisitingTeam(String name);
}
// Filename: Football.java
public interface Football extends Sports {
    public void homeTeamScored(int points);
    public void visitingTeamScored(int points);
    public void endOfQuarter(int quarter);
}
// Filename: Hockey.java
public interface Hockey extends Sports {
    public void homeGoalScored();

    public void visitingGoalScored();

    public void endOfPeriod(int period);

    public void overtimePeriod(int ot);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Multiple Class Inheritance in Java
&lt;/h3&gt;

&lt;p&gt;A class can extends ONLY one parent class using the extends keyword. Multiple class inheritance is not allowed.&lt;br&gt;
Class inheritance inheritance in java has the following limitations.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A subclass cannot inherit private members of its super class.&lt;/li&gt;
&lt;li&gt;A subclass can have only one super class.&lt;/li&gt;
&lt;li&gt;Constructor and initializer blocks cannot be inherited by a subclass.
Interfaces are not classes, thus you are allowed to inherit one or more interfaces.
Multiple inheritance by interface occurs if a class implements multiple interfaces or also if an interface itself extends multiple interfaces.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Extending Multiple Interfaces
&lt;/h3&gt;

&lt;p&gt;To achieve multiple inheritance, java allows you to implement more than one parent interfaces by declaring them in a comma-separated list. E.g.&lt;br&gt;
&lt;code&gt;public interface Hockey extends Sports, Event&lt;/code&gt;&lt;br&gt;
&lt;em&gt;Note that an interface can extend more than one parent interface&lt;/em&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bpMFpspq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wgsxn94j8kauykr4pyk3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bpMFpspq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wgsxn94j8kauykr4pyk3.png" alt="interface" width="569" height="319"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Difference between Abstraction and Encapsulation
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2XNTX6so--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a5nodojkrwrcxsg4ybms.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2XNTX6so--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a5nodojkrwrcxsg4ybms.png" alt="abstraction" width="880" height="257"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Difference between Abstract Class and Interface
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Tg3p1uG2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7tl5pfodhqo21yvp56f7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Tg3p1uG2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7tl5pfodhqo21yvp56f7.png" alt="interfaces" width="880" height="313"&gt;&lt;/a&gt;&lt;br&gt;
In the next article we will discuss &lt;a href="https://dev.to/killallnano/java-for-beginners-polymorphism-in-java-1ng4"&gt;Polymorphism in java&lt;/a&gt; in depth.&lt;/p&gt;

&lt;p&gt;Thanks for taking your time to read this article.&lt;/p&gt;

</description>
      <category>java</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>Java for beginners: Fundamentals of Java</title>
      <dc:creator>Jeff Odhiambo</dc:creator>
      <pubDate>Sat, 05 Mar 2022 15:57:16 +0000</pubDate>
      <link>https://dev.to/smartjeff/java-for-beginners-fundamentals-of-java-3601</link>
      <guid>https://dev.to/smartjeff/java-for-beginners-fundamentals-of-java-3601</guid>
      <description>&lt;h2&gt;
  
  
  Java Input/Output
&lt;/h2&gt;

&lt;p&gt;Java uses streams to perform input and output. A &lt;strong&gt;stream&lt;/strong&gt; can be defined as a sequence of data. All streams represent an input source and an output destination.&lt;br&gt;
Java uses the &lt;strong&gt;InputStream&lt;/strong&gt; to read data from a source and the &lt;strong&gt;OutputStream&lt;/strong&gt; is used for writing data to a destination.&lt;br&gt;
The JDK has two sets of I/O packages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Standard I/O (in package java.io), introduced since JDK 1.0 for stream-based I/O.&lt;/li&gt;
&lt;li&gt;The New I/O (in packages java.nio), introduced in JDK 1.4, for more efficient buffer-based I/O.
###Console Output
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;System.out.print("Hello ");
System.out.println("world");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Console Input
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String text = in.readLine();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  GUI Input
&lt;/h3&gt;

&lt;p&gt;GUI input and output is performed using the JOptionPane class of package &lt;code&gt;javax.swing&lt;/code&gt;&lt;br&gt;
&lt;code&gt;String name = JOptionPane.showInputDialog(null, "What's your name?");&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OTjczNND--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4z76ne0zrgs5ci7cr90w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OTjczNND--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4z76ne0zrgs5ci7cr90w.png" alt="Output" width="304" height="132"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  GUI Output
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;JOptionPane.showMessageDialog(null,"Welcome to Java Programming");&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A99xTRQr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9nm804t4yrm49xb67los.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A99xTRQr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9nm804t4yrm49xb67los.png" alt="Output" width="293" height="127"&gt;&lt;/a&gt;&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import javax.swing.*;
public class JOptionPaneTest1 {
    public static void main(String[] args) {
        String ans;
        ans = JOptionPane.showInputDialog(null, "Speed in miles per hour?");
        double mph = Double.parseDouble(ans);
        double kph = 1.621 * mph;
        JOptionPane.showMessageDialog(null, "KPH = " + kph);
        System.exit(0);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2khAvstk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jtmu9kocrqz4eknjzgp5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2khAvstk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jtmu9kocrqz4eknjzgp5.png" alt="Question image" width="302" height="130"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GBdeSgCd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/seere7cf0fjfk8lr04wq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GBdeSgCd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/seere7cf0fjfk8lr04wq.png" alt="Answer image" width="272" height="125"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  File Output
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        PrintWriter out = new PrintWriter(new FileWriter("/home/jeff/Desktop/Notes-1.pdf\n"));
        out.print("Hello ");
        out.println("world");
        out.close();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  File Input
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; BufferedReader in = new BufferedReader(new FileReader("/home/jeff/Desktop/Notes-1.pdf"));
        String text = in.readLine();
        in.close();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Converting input data
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String text = in.readLine();
int x = Integer.parseInt(text);
double y = Double.parseDouble(text);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Reading until EOF&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while (in.ready()) {
    text = in.readLine();
    System.out.println(text);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Variables:
&lt;/h3&gt;

&lt;p&gt;Variables are named memory locations that store data to be used in a program.&lt;br&gt;
Variables maintain the state of your application, and enable the user to manage data. The values stored in variables may change during program execution.&lt;/p&gt;
&lt;h3&gt;
  
  
  Identifier:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;These are variable names.&lt;/strong&gt; Variable name is a name given to memory cells location of a computer where data is stored. You can use any combination of those&lt;br&gt;
characters as long as the name doesn’t begin with a number. Identifier is the name of a variable that is made up from combination of alphabets, digits and underscore.&lt;/p&gt;
&lt;h3&gt;
  
  
  Rules for naming varibales:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Variable names may contain only letters, numbers, underscores.&lt;/li&gt;
&lt;li&gt;Should not begin with a number. First character should be letter or alphabet.&lt;/li&gt;
&lt;li&gt;Keywords are not allowed to be used as a variable name.&lt;/li&gt;
&lt;li&gt;White space is not allowed.&lt;/li&gt;
&lt;li&gt;Java is case sensitive i.e. UPPER and lower case are significant.&lt;/li&gt;
&lt;li&gt;Special characters such as space etc not allowed.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Keywords
&lt;/h3&gt;

&lt;p&gt;Keywords are the system defined identifiers. All keywords have predefined meanings. White spaces are not allowed in keywords. Keyword should not be used as an identifier.&lt;/p&gt;
&lt;h3&gt;
  
  
  Common java keywords include:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;abstract&lt;/strong&gt; - Indicates that the details of a class, a method, or an interface are given elsewhere in&lt;/li&gt;
&lt;li&gt;the code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;assert&lt;/strong&gt; - Tests the truth of a condition that the programmer believes is true.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;boolean&lt;/strong&gt; - Indicates that a value is either true or false.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;break&lt;/strong&gt; - Jumps out of a loop or switch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;byte&lt;/strong&gt; - Indicates that a value is an 8-bit whole number.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;case&lt;/strong&gt; - Introduces one of several possible paths of execution in a switch statement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;catch&lt;/strong&gt; - Introduces statements that are executed when something interrupts the flow of execution in a try clause.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;char&lt;/strong&gt; - Indicates that a value is a character (a single letter, digit, punctuation symbol, and so on).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;class&lt;/strong&gt; - Introduces a class(a blueprint for an object).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;continue&lt;/strong&gt; - Forces the abrupt end of the current loop iteration and begins another iteration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;default&lt;/strong&gt; - Introduces a path of execution to take when no case is a match in a switch statement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;do&lt;/strong&gt; Causes the computer to repeat some statements over and over again (for example, as long as the computer keeps getting unacceptable results).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;double&lt;/strong&gt; - Indicates that a value is a 64-bit number with one or more digits after the decimal point.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;else&lt;/strong&gt; - Introduces statements that are executed when the condition in an if statement isn’t true.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;enum&lt;/strong&gt; - Creates a newly defined type(a group of values that a variable can have).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;extends&lt;/strong&gt; - Creates a subclass (a class that reuses functionality from a previously defined class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;final&lt;/strong&gt; - Indicates that a variable’s value cannot be changed, that a class’s functionality cannot be extended, or that a method cannot be overridden.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;finally&lt;/strong&gt; - Introduces the last will and testament of the statements in a try clause.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;float&lt;/strong&gt; - Indicates that a value is a 32-bit number with one or more digits after the decimal point.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;for&lt;/strong&gt; - Gets the computer to repeat some statements over and over again (for example, for a certain number of times).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;if&lt;/strong&gt; - Tests to see whether a condition is true. If it’s true, the computer executes certain statements; otherwise, the computer executes the remaining other statements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;implements&lt;/strong&gt; - Reuses the functionality from a previously defined interface.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;import&lt;/strong&gt; - Enables the programmer to abbreviate the names of classes defined in a package.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;instanceof&lt;/strong&gt; - Tests to see whether a certain object comes from a certain class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;int&lt;/strong&gt; - Indicates that a value is a 32-bit whole number.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;interface&lt;/strong&gt; - Introduces an interface, which is like a class, but less specific. (Interfaces are used where one is to inherit from one or more other instances.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;long&lt;/strong&gt; - Indicates that a value is a 64-bit whole number.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;native&lt;/strong&gt; - Enables the programmer to use code that was written in another language.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;new&lt;/strong&gt; - Creates an object from an existing class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;package&lt;/strong&gt; - Puts the code into a package — a collection of logically related definitions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;private&lt;/strong&gt; - Indicates that a variable or method can be used only within a certain class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;protected&lt;/strong&gt; - Indicates that a variable or method can be used in subclass from another package.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;public&lt;/strong&gt; - Indicates that a variable, class, or method can be used by any other Java code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;return&lt;/strong&gt; - Ends execution of a method and possibly returns a value to the calling code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;short&lt;/strong&gt; - Indicates that a value is a 16-bit whole number.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;static&lt;/strong&gt; - Indicates that a variable or method belongs to a class, rather than to any object created from the class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;strictfp&lt;/strong&gt; - Limits the computer’s ability to represent extra large or extra small numbers when the computer does intermediate calculations on float and double values.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;super&lt;/strong&gt; - Refers to the super class of the code in which the word super appears.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;switch&lt;/strong&gt; - Tells the computer to follow one of many possible paths of execution (one of many possible cases), depending on the value of an expression.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;synchronized&lt;/strong&gt; - Keeps two threads from interfering with one another.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;this&lt;/strong&gt; - A self-reference(refers to the object in which the word this appears).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;throw&lt;/strong&gt; - Creates a new exception object and indicates that an exceptional situation (usually something unwanted) has occurred.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;throws&lt;/strong&gt; - Indicates that a method or constructor may pass the buck when an exception is thrown.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;transient&lt;/strong&gt; - Indicates that, if and when an object is serialized, a variable’s value doesn’t need to be stored.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;try&lt;/strong&gt; - Introduces statements that are watched (during runtime) for things that can go wrong.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;void&lt;/strong&gt; - Indicates that a method doesn’t return a value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;volatile&lt;/strong&gt; - Imposes strict rules on the use of a variable by more than one thread at a time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;while&lt;/strong&gt; - Repeats some statements over and over again (as long as a condition is still true).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Data Types in Java
&lt;/h2&gt;

&lt;p&gt;Data types dictate the kind of data that a variable can store. Data type can be defined as the type of data for a variable or constant store. When we use a variable&lt;br&gt;
in a program then we have to mention the type of data.&lt;br&gt;
In java, there are two types of data types : &lt;strong&gt;primitive data types&lt;/strong&gt; and &lt;strong&gt;non-primitive data types&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Q_nzjbvo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/adhr8l2berx4cpvo1mdf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Q_nzjbvo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/adhr8l2berx4cpvo1mdf.png" alt="Data types in Java" width="880" height="571"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4xG5YoQy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/epudz11mcp4b8thw208a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4xG5YoQy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/epudz11mcp4b8thw208a.png" alt="Data size" width="764" height="560"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Variable Initialization
&lt;/h2&gt;

&lt;p&gt;In Java, variables aren’t necessarily assigned an initial value when they’re declared, but all variables must be assigned a value before the variable’s value is used in an assignment statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    int a;
    int b;
    // We're now initializing BOTH variables explicitly.
    a = 3;
    b = 7;
    a = a + b;
    System.out.println(a);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use of variables before they are initialized results in a compiler error.&lt;/p&gt;

&lt;h2&gt;
  
  
  The String Type
&lt;/h2&gt;

&lt;p&gt;A String represents a sequence of zero or more Unicode characters, in other words we can say, a String is array of characters. The symbol String starts with a capital “S,” whereas the names of &lt;strong&gt;primitive types&lt;/strong&gt; are expressed in all lowercase: int, float, boolean, etc.&lt;br&gt;
E.g. &lt;code&gt;String name = "Jeff";&lt;/code&gt;&lt;br&gt;
&lt;em&gt;This capitalization difference is deliberate and mandatory—string (lowercase) won’t&lt;br&gt;
work as a type.&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  String concatenation
&lt;/h3&gt;

&lt;p&gt;The plus sign (+) operator is normally used for arithmetic addition, but when used in conjunction with Strings. Any number of String values can be concatenated with the &lt;code&gt;+&lt;/code&gt; operator, as the following code snippet illustrates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class StringCont {
    public static void main(String[] args) {
        String f_name = "Jeff";
        String l_name = "Odhiambo";
        String name = "Mr. " + f_name + " " + l_name;
        System.out.println(name);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Mr. Jeff Odhiambo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Statements
&lt;/h2&gt;

&lt;p&gt;A statement is basically any declaration, function call, assignment, or condition. Statements are the building blocks of any program. Statements in Java must be&lt;br&gt;
terminated with a semi colon. E.g.&lt;br&gt;
&lt;code&gt;int a;&lt;/code&gt;&lt;br&gt;
&lt;code&gt;a=10;&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Comments
&lt;/h2&gt;

&lt;p&gt;Java supports three different comment styles: single line (end-of-line), Multi-line and Java documentation comments.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Single line (End-of-Line Comments)&lt;/strong&gt;
We use a double slash (//) to note the beginning of a comment that automatically ends when the end of the line is reached.
E.g. &lt;code&gt;x = y + z; // text of comment continues through to the end of the line&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-line Comments&lt;/strong&gt;
These comments begin with a forward slash followed by an asterisk (/&lt;em&gt;) and end with an asterisk followed by a forward slash (&lt;/em&gt;/).
Everything enclosed between these delimiters is treated as a comment and is therefore ignored by the Java
compiler, no matter how many lines the comment spans.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Java Documentation Comments&lt;/strong&gt;
The third and final type of Java comment, Java documentation comments (Javadoc comments), can be parsed from source code files by a special javadoc command-line utility program (which comes standard with the Java SDK)
and used to automatically generate HTML documentation for an application.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Operators and Expressions
&lt;/h2&gt;

&lt;p&gt;An expression is a statement that has a value. Expressions are basically any math or logical operation(s). They consist of a sequence of operators and operands that specifies a computation. E.g &lt;code&gt;x = 12 + 42;&lt;/code&gt; that assigns 54 i.e., 12+42 to variable x.&lt;br&gt;
A simple expression in Java is either&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A constant: &lt;code&gt;a=7;&lt;/code&gt;, &lt;code&gt;payment_status=false;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;A char(acter) literal enclosed in single quotes: &lt;code&gt;grade = 'A'&lt;/code&gt;, &lt;code&gt;mark = '3'&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;A String literal enclosed in double quotes: &lt;code&gt;f_name = "Jeff"&lt;/code&gt;, &lt;code&gt;"l_name = Odhiambo"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The name of any properly declared variables: &lt;code&gt;myString&lt;/code&gt;, &lt;code&gt;x&lt;/code&gt;, etc&lt;/li&gt;
&lt;li&gt;Any two of the preceding types of expression that are combined with one of the Java binary operators (discussed in detail later in this chapter). &lt;code&gt;y = 2x+3;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Any one of the preceding types of expression that is modified by one of the Java unary operators (discussed in detail later in this chapter): &lt;code&gt;i++&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Any of the preceding types of expression enclosed in parentheses: &lt;code&gt;(x + 2)&lt;/code&gt; etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Expressions of arbitrary complexity&lt;/strong&gt; can be assembled from the various different simple expression types by nesting parentheses, for example: &lt;code&gt;((((4/x) + y) * 7) +z)&lt;/code&gt;.
##Operators
Operators are symbols that specifies operations to be performed on operands. 
&lt;strong&gt;Common operators include:&lt;/strong&gt;
Assignment (=) The assignment operator assigns a value to a variable. &lt;code&gt;a = 5&lt;/code&gt;;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;*&lt;em&gt;Arithmetic operators ( +, -, *, /, *&lt;/em&gt;% )&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;-&amp;gt; addition&lt;/li&gt;
&lt;li&gt;-&amp;gt; subtraction&lt;/li&gt;
&lt;li&gt;-&amp;gt; multiplication
/ -&amp;gt; division
% -&amp;gt; modulo
&lt;strong&gt;Compound assignment (+=,-=,*=,/=, %=,&amp;gt;&amp;gt;=,&amp;lt;&amp;lt;=)&lt;/strong&gt;
When we want to modify the value of a variable by performing an operation on the value currently stored in that variable we can use compound assignment operators
which include:
&lt;code&gt;value += increase;&lt;/code&gt; -&amp;gt; &lt;code&gt;value = value + increase;&lt;/code&gt;
&lt;code&gt;a -= 5;&lt;/code&gt; -&amp;gt; &lt;code&gt;a = a - 5;&lt;/code&gt;
&lt;code&gt;a /= b;&lt;/code&gt; -&amp;gt; &lt;code&gt;a = a / b;&lt;/code&gt;
&lt;code&gt;price *= units + 1;&lt;/code&gt; -&amp;gt; price = &lt;code&gt;price * (units + 1);&lt;/code&gt;
&lt;strong&gt;Increment and Decrement operators&lt;/strong&gt;
The increment operator ( ++ ) and the decrement operator ( -- ) increase or reduce by one the value stored in a variable. They are equivalent to &lt;code&gt;+=1&lt;/code&gt; and to &lt;code&gt;-=1&lt;/code&gt; ,
respectively. Thus: &lt;code&gt;c++;c+=1;c=c+1;&lt;/code&gt; are all equivalent in its functionality.
&lt;strong&gt;Relational and equality operators (==,!=,&amp;gt;,&amp;lt;,&amp;gt;=,&amp;lt;= )&lt;/strong&gt;
These operators are used for comparison between two expressions. The result of a relational operation is a Boolean value that can only be true or false, according to its Boolean result. We may want to compare two expressions, for example, to know if they are equal or if one is greater than the other is. 
The relational and equality operators that can be used include:
&lt;code&gt;==&lt;/code&gt; -&amp;gt; &lt;code&gt;Equal to&lt;/code&gt;
&lt;code&gt;!=&lt;/code&gt; -&amp;gt; &lt;code&gt;Not equal to&lt;/code&gt;
&lt;code&gt;&amp;gt;&lt;/code&gt; -&amp;gt; &lt;code&gt;Greater than&lt;/code&gt;
&lt;code&gt;&amp;lt;&lt;/code&gt; -&amp;gt; &lt;code&gt;Less than&lt;/code&gt;
&lt;code&gt;&amp;gt;=&lt;/code&gt; -&amp;gt; &lt;code&gt;Greater than or equal to&lt;/code&gt;
&lt;code&gt;&amp;lt;=&lt;/code&gt; -&amp;gt; &lt;code&gt;Less than or equal to&lt;/code&gt;
&lt;strong&gt;Logical operators ( !, &amp;amp;&amp;amp;, || )&lt;/strong&gt;
The Operator &lt;code&gt;!&lt;/code&gt;, Is used to perform the Boolean operation &lt;code&gt;NOT&lt;/code&gt;, it has only one operand, located at its right, and the only thing that it does is to inverse the value of it, producing false if its operand is true and true if its operand is false.
The logical operators &amp;amp;&amp;amp; and || are used when evaluating two expressions to obtain a single relational result. The operator &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; corresponds with Boolean logical operation &lt;code&gt;AND&lt;/code&gt;. This operation results true if both its two operands are true, and false otherwise.
The operator &lt;code&gt;||&lt;/code&gt; corresponds with Boolean logical operation &lt;code&gt;OR&lt;/code&gt;. This operation results true if either one of its two operands is true, thus being false only when both operands are false themselves.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UvLqdW3F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nvg2e40i3fdq126ztws8.jpg" alt="Operators" width="880" height="762"&gt;
&lt;strong&gt;Conditional operator ( ? )&lt;/strong&gt;
The conditional operator evaluates an expression returning a value if that expression is true and a different one if the expression is evaluated as false. Its format is:
&lt;code&gt;condition ?result1 : result2&lt;/code&gt;
&lt;strong&gt;Precedence of operators&lt;/strong&gt;
Precedence of operators determines which operand is evaluated first and which one
is evaluated later. For example, in this expression: &lt;code&gt;a = 5 + 7 % 2&lt;/code&gt; we may doubt if it really means:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 5 + (7 % 2) // with a result of 6, or
a = (5 + 7) % 2 // with a result of 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Types of expressions in Java
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Arithmetic expressions
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;unary&lt;/strong&gt; expression consists of either a unary operator prepended to an operand, or the sizeof keyword followed by an expression. A &lt;strong&gt;binary&lt;/strong&gt; expression consists of two operands joined by a binary operator. A ternary expression consists of three operands joined by the conditional-expression operator.&lt;/p&gt;

&lt;p&gt;The easiest example of an expression is in the assignment statement. An expression is evaluated, and the result is saved in a variable. A simple example might look like &lt;code&gt;y = (m * x) + c&lt;/code&gt;&lt;br&gt;
This assignment will save the value of the expression in variable &lt;code&gt;y&lt;/code&gt;.&lt;br&gt;
Short hand assignments&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--alopJYaf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oibepqz5j7i1oukvzlvk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--alopJYaf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oibepqz5j7i1oukvzlvk.png" alt="Assignments" width="880" height="267"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Logical expressions
&lt;/h3&gt;

&lt;p&gt;Logical connectors allow several comparisons to be combined into a single test. They use And, Or and Not operators.&lt;br&gt;
They are frequently used to combine relational operators, for example &lt;code&gt;x&amp;lt; 20 &amp;amp;&amp;amp; x &amp;gt;= 10&lt;/code&gt;&lt;br&gt;
They evaluate their left hand operand, and then only evaluate the right hand one if this is required. Not operates on a single logical value, its effect is to reverse its state. Here is an example of its use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;boolean acceptable = false;
if(!acceptable){
    System.out.println("Not acceptable");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Comparison Expressions
&lt;/h3&gt;

&lt;p&gt;Comparison takes two numbers and produces a logical result. Comparisons are usually found controlling if statements or loops. Example&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WwQbxwJ---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5rg0yiz58mdhnks42bv9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WwQbxwJ---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5rg0yiz58mdhnks42bv9.png" alt="Coparison expression" width="583" height="247"&gt;&lt;/a&gt;&lt;br&gt;
Note that == is used in comparisons and = is used in assignments. Comparison operators are used when creating comparisons expressions. E.g.&lt;br&gt;
x == y&lt;br&gt;
i&amp;gt; 10&lt;br&gt;
a + b != c&lt;/p&gt;

&lt;p&gt;In our next article we will discuss &lt;a href="https://dev.to/killallnano/java-object-oriented-programming-6bm"&gt;Java Object Oriented Programming&lt;/a&gt; Where we will find how how Java is object oriented.&lt;/p&gt;

</description>
      <category>java</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Java for beginners: Installation of Java</title>
      <dc:creator>Jeff Odhiambo</dc:creator>
      <pubDate>Sat, 05 Mar 2022 12:44:03 +0000</pubDate>
      <link>https://dev.to/smartjeff/java-for-beginners-installation-of-java-nhc</link>
      <guid>https://dev.to/smartjeff/java-for-beginners-installation-of-java-nhc</guid>
      <description>&lt;p&gt;How do you know that you have java installed? How do you install Java? How do you write, compile and run a java code?&lt;br&gt;
We will perform all these in this article which will be a continuation of our previous article on Java, &lt;a href="https://dev.to/killallnano/java-for-beginners-introduction-to-java-36kn"&gt;Introduction to Java&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Check installation
&lt;/h2&gt;

&lt;p&gt;To run Java programs on your computer you must at least have the Java runtime environment (JRE) installed. This might already be the case on your machine. You can test if the JRE is installed and in your current path by opening a terminal or cmd in windows&lt;code&gt;(Win+R, enter cmd and press Enter)&lt;/code&gt; and by typing in the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;java -version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the JRE is installed and within your path, this command will print information about your Java installation as shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\prof&amp;gt;java -version
java version "17.0.2" 2022-01-18 LTS
Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the command line returns the information that the program could not be found, you have to install Java.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to install java on Ubuntu or any UNIX system
&lt;/h2&gt;

&lt;p&gt;On Ubuntu, you can install the latest Java through the terminal by writing the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install openjdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or you can specify the version, e.g for Java 7 we can use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install openjdk-7-jdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to install Java on Windows
&lt;/h2&gt;

&lt;p&gt;For Windows, Oracle provides a native installer which can be found on the Oracle website. The central website for installing Java is located under the following URL which also contains instructions on how to install&lt;br&gt;
Java for other platforms. &lt;a href="//java.com"&gt;java.com&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What to do if you come across an installation problem
&lt;/h2&gt;

&lt;p&gt;If you have problems installing Java on your system, search via Google for &lt;code&gt;How to install JDK on &amp;lt;YOUR_OS&amp;gt;&lt;/code&gt;. This should result in helpful links. Replace &lt;code&gt;&amp;lt;YOUR_OS&amp;gt;&lt;/code&gt; with your operating system, e.g., &lt;code&gt;Windows&lt;/code&gt;, &lt;code&gt;Ubuntu&lt;/code&gt;, &lt;code&gt;Mac OSX&lt;/code&gt;, etc.&lt;br&gt;
For instance, if having problem in installing Java on windows &lt;br&gt;
Search &lt;code&gt;How to install java on windows&lt;/code&gt; which will result to  &lt;a href="https://www.google.com/search?q=How+to+install+java+on+windows"&gt;results&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Validate installation
&lt;/h2&gt;

&lt;p&gt;After installation, you can confirm if Java is correctly installed by running &lt;code&gt;java -version&lt;/code&gt; on your terminal or cmd.&lt;br&gt;
If successful the output will be similar to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\prof&amp;gt;java -version
java version "17.0.2" 2022-01-18 LTS
Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How can you tell you are using a 32-bit or 64-bit version of Java?
&lt;/h2&gt;

&lt;p&gt;You can run a 32b-it or a 64-bit version of Java on a 64-bit system. If you use &lt;code&gt;java -version&lt;/code&gt; and the output contains the "64-Bit" string, then you are using the 64-bit version of Java otherwise you are using the 32-bit version. &lt;br&gt;
The following is the output of a 64-bit version.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\prof&amp;gt;java -version
java version "17.0.2" 2022-01-18 LTS
Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Writing, compiling, and running a Java program
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Write source code
&lt;/h3&gt;

&lt;p&gt;To create Java programs, use any text editor such as Notepad, WordPad, or gedit in ubux/Linux. After creation, save the file with &lt;code&gt;.Java&lt;/code&gt; file extension. Example: Create file &lt;code&gt;HelloWorld.java&lt;/code&gt; then write the following source code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Simplest Java program
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations, you just created your first java source file.&lt;br&gt;
The above Java program can be developed under Linux/Windows using a text editor and the command line. Select or create a new directory in Windows which will be used for your Java development. In this description, the path &lt;code&gt;C:\Users\prof\Desktop\javalessons&lt;/code&gt; is used.&lt;br&gt;
On Linux, you might see &lt;code&gt;\home\&amp;lt;name&amp;gt;\javalessons&lt;/code&gt; but this will depend on how you named your folder and the location of the folder.&lt;br&gt;
We will ignore the first file you created.&lt;br&gt;
Once done creating a directory, open a text editor which supports plain text, e.g., gedit in Linux or&lt;br&gt;
Notepad in Windows and write the following source code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Simplest Java program
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World, Thanks for reading this article. Did you find it useful");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the source code in your javadir directory(my case it's, &lt;em&gt;C:\Users\prof\Desktop\javalessons&lt;/em&gt;) with the &lt;code&gt;HelloWorld.java&lt;/code&gt; filename. The name of a Java source file must always be the same as the class name(within the source code) and end with the &lt;code&gt;.java&lt;/code&gt; extension. In this example, the filename must be &lt;code&gt;HelloWorld.java&lt;/code&gt;, because the class is called &lt;code&gt;HelloWorld&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Compiling and Running Java Programs
&lt;/h3&gt;

&lt;p&gt;Open a terminal or command line. Switch to the javadir directory using the command &lt;code&gt;cd javadir&lt;/code&gt;, e.g, in the above example  I'll use &lt;code&gt;cd C:\Users\prof\Desktop\javalessons&lt;/code&gt; command to change directory to where the file is located.&lt;br&gt;
Then use the &lt;code&gt;dir&lt;/code&gt; command (ls in Linux) to verify that the source file is in the directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\prof&amp;gt;cd C:\Users\prof\Desktop\javalessons

C:\Users\prof\Desktop\javalessons&amp;gt;dir

05/03/2022  14:54    &amp;lt;DIR&amp;gt;          .
05/03/2022  14:54    &amp;lt;DIR&amp;gt;          ..
05/03/2022  14:54               151 HelloWorld.java
               1 File(s)            151 bytes

C:\Users\prof\Desktop\javalessons&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To compile the source code file into a class file, use the &lt;code&gt;javac&lt;/code&gt; command. For example, the following command compiles &lt;code&gt;HelloWorld.java&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;javac HelloWorld.java
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Afterward, list again the content of the directory with the &lt;code&gt;ls&lt;/code&gt; or &lt;code&gt;dir&lt;/code&gt; command. The directory contains now a file &lt;code&gt;HelloWorld.class&lt;/code&gt;. If you see this file, you have successfully compiled your first Java source code into bytecode.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\prof\Desktop\javalessons&amp;gt;javac HelloWorld.java

C:\Users\prof\Desktop\javalessons&amp;gt;dir

05/03/2022  15:04    &amp;lt;DIR&amp;gt;          .
05/03/2022  15:04    &amp;lt;DIR&amp;gt;          ..
05/03/2022  15:04               425 HelloWorld.class
05/03/2022  14:54               151 HelloWorld.java
               2 File(s)            576 bytes

C:\Users\prof\Desktop\javalessons&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can now start to run your compiled Java program. Ensure that you are still in the &lt;code&gt;jardir&lt;/code&gt; directory.&lt;br&gt;
To run, use the java command. For example, the command &lt;code&gt;java HelloWorld&lt;/code&gt; will display &lt;code&gt;Hello World, Thanks for reading this article. Did you find it useful?&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\prof\Desktop\javalessons&amp;gt;java HelloWorld
Hello World, Thanks for reading this article. Did you find it useful?

C:\Users\prof\Desktop\javalessons&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using the classpath
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Common Error when compiling programs is:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jF63RYsK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u4lfren3hvb622hifqpt.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jF63RYsK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u4lfren3hvb622hifqpt.PNG" alt="Error" width="880" height="88"&gt;&lt;/a&gt;&lt;br&gt;
To solve the problem, set the classpath in the environmental variables as follows:&lt;/p&gt;

&lt;h3&gt;
  
  
  Classpath
&lt;/h3&gt;

&lt;p&gt;The classpath defines where the Java compiler and Java runtime look for &lt;code&gt;.class&lt;/code&gt; files to load. These instructions can be used in the Java program. You can use the classpath to run the program from another place in your directory.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configure classpath in Java environment on Windows (Windows10)
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Click on the Start menu&lt;/li&gt;
&lt;li&gt;Search Advanced System setting
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SnCGQgDT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uonl0pfclvxr4lps595h.png" alt="Advance system setting" width="880" height="665"&gt;
&lt;/li&gt;
&lt;li&gt;Click on Environment Variables, under System Variables, find path, and click on it.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XOJRV5oq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mzngy4gcyv936qiye86l.PNG" alt="system variables" width="407" height="464"&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--apNs117O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r80iinbyjsvvzjaths38.PNG" alt="Path" width="614" height="581"&gt;
&lt;/li&gt;
&lt;li&gt;In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value .e.g PATH= C:\ProgramFiles\Java\jdk1.7.0_45\bin.
In my case, it is already configured.&lt;/li&gt;
&lt;li&gt;Reopen Command prompt window, and run your java code using the &lt;code&gt;javac&lt;/code&gt; command.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Congratulations you completed the second article on Java. If you missed the first one, kindly visit &lt;a href="https://dev.to/killallnano/java-for-beginners-introduction-to-java-36kn"&gt;Introduction to Java.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next article is &lt;a href="https://dev.to/killallnano/java-for-beginners-fundamentals-of-java-3601"&gt;Java  Fundamentals&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Java for Beginners: Introduction to Java</title>
      <dc:creator>Jeff Odhiambo</dc:creator>
      <pubDate>Sat, 05 Mar 2022 11:02:44 +0000</pubDate>
      <link>https://dev.to/smartjeff/java-for-beginners-introduction-to-java-36kn</link>
      <guid>https://dev.to/smartjeff/java-for-beginners-introduction-to-java-36kn</guid>
      <description>&lt;h2&gt;
  
  
  What is JAVA?
&lt;/h2&gt;

&lt;p&gt;Java is a high-level, third generation programming language, like C,C++, Perl, and many others. You can use Java to write computer applications that play games, store data etc. Compared to other programming languages, Java is most similar to C++.&lt;br&gt;
What's special about Java in relation to other programming languages is that it lets you write special programs called &lt;strong&gt;applets&lt;/strong&gt; that can be downloaded from the Internet and played safely within a web browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  History
&lt;/h2&gt;

&lt;p&gt;Java is an object-oriented programming language created by &lt;strong&gt;James Gosling&lt;/strong&gt; from &lt;strong&gt;Sun Microsystems (Sun)&lt;/strong&gt; in &lt;strong&gt;1991&lt;/strong&gt;. The first publicly available version of Java (Java 1.0) was released in 1995.&lt;br&gt;
Sun Microsystems was acquired by the Oracle Corporation in 2010.&lt;br&gt;
Over time new enhanced versions of Java have been released. The current version of Java is Java 8.&lt;br&gt;
From the Java programming language, the Java platform evolved. The Java platform is usually associated with the Java virtual machine and the Java core libraries.&lt;br&gt;
In 2006, Sun started to make Java available under the GNU General Public License (GPL).&lt;/p&gt;

&lt;h2&gt;
  
  
  The Java compiler
&lt;/h2&gt;

&lt;p&gt;A compiler is a program that converts a high-level language to a machine language, i.e. from source code to binary code.&lt;br&gt;
When you program from the Java platform, you write source code with a &lt;code&gt;.java&lt;/code&gt; file extension and then compile them. The java compiler converts high-level java code into bytecode.&lt;br&gt;
The compiler checks your code against the language's syntax rules, then writes out bytecodes in a &lt;code&gt;.class&lt;/code&gt; files. Bytecodes are standard instructions targeted to run on a Java virtual machine (JVM).&lt;br&gt;
In adding this level of abstraction, the Java compiler differs from other language compilers, which write out instructions suitable for the CPU chipset the program will run on.&lt;br&gt;
An interpreter is a program that translates or converts a high-level language to a machine-language line by line. In Java, the Just In Time Code generator converts the bytecode into the native machine code which are at the same programming levels. Hence java is both compiled as well as an interpreted language.&lt;/p&gt;

&lt;h2&gt;
  
  
  Java virtual machine(JVM)
&lt;/h2&gt;

&lt;p&gt;Java programs are compiled by the Java compiler into bytecode. The JVM is a software implementation of a computer that executes programs like a real machine. At run time, the JVM reads and interprets a &lt;code&gt;.class&lt;/code&gt; files and executes the program's instructions on the native hardware platform for which the JVM was written. The Java virtual machine is written specifically for a specific operating system, e.g., for &lt;code&gt;Linux&lt;/code&gt; a special implementation is required as well as for &lt;code&gt;Windows&lt;/code&gt;.&lt;br&gt;
The JVM is the heart of the Java language's &lt;strong&gt;"write-once, run-anywhere"&lt;/strong&gt; principle. Your code can run on any chipset for which a suitable JVM implementation is available. JVMs are available for major platforms like Linux and Windows, and subsets of the Java language have been implemented in JVMs for mobile phones and hobbyist chips.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5vyla9th2neiz6hjf5pc.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5vyla9th2neiz6hjf5pc.PNG" alt="JVM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What are the tasks of JVM?
&lt;/h3&gt;

&lt;p&gt;JVM performs byte-code interpretation, garbage collection, exception handling, thread management, initialization of variables, and type definition.&lt;/p&gt;

&lt;h2&gt;
  
  
  Java platform
&lt;/h2&gt;

&lt;p&gt;The Java platform is the name given to the computing platform from Oracle that helps users to run and develop Java applications. The platform does not just enable a user to run and develop Java applications but also features a wide variety of tools that can help developers work efficiently with the Java programming language. The platform consists of two essential components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Java Runtime Environment (JRE)&lt;/strong&gt;, which is needed to run Java applications and applets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Java Development Kit (JDK)&lt;/strong&gt;, which is needed to develop those Java applications and applets. If you have installed the JDK, it comes equipped with a JRE as well.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When installed on a computer the &lt;strong&gt;JRE&lt;/strong&gt; provides the operating system with the means to run Java programs, whereas the &lt;strong&gt;JDK&lt;/strong&gt; is a collection of tools used by a programmer to create Java applications. &lt;br&gt;
The JDK has as its primary components a collection of programming tools, including:&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic Tools
&lt;/h3&gt;

&lt;p&gt;These tools are the foundation of the JDK. They are the tools you use to create and build applications.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;appletviewer&lt;/strong&gt; - Run and debug applets without a web browser.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;apt&lt;/strong&gt; - Annotation processing tool.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;extcheck&lt;/strong&gt; - Utility to detect Jar conflicts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;jar&lt;/strong&gt;   - Create and manage Java Archive (JAR) files.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;java&lt;/strong&gt; - The launcher for Java applications. The old deployment launcher, JRE, is no longer provided.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;javac&lt;/strong&gt; - The compiler for the Java programming language.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;javadoc&lt;/strong&gt; - API documentation generator.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;javah&lt;/strong&gt; - C header and stub generator. Used to write native methods.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;javap&lt;/strong&gt; - Class file disassembler&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;jdb&lt;/strong&gt;   - The Java Debugger. See &lt;a href="https://docs.oracle.com/javase/7/docs/technotes/guides/jpda/index.html" rel="noopener noreferrer"&gt;JPDA&lt;/a&gt; for the debugger architecture specifications.
###Security Tools
These security tools help you set security policies on your system and create applications that can work within the scope of security policies set at remote sites.
&lt;strong&gt;keytool&lt;/strong&gt; - Manage keystores and certificates.
&lt;strong&gt;jarsigner&lt;/strong&gt; - Generate and verify JAR signatures.
&lt;strong&gt;policytool&lt;/strong&gt; - GUI tool for managing policy files.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://docs.oracle.com/javase/7/docs/technotes/tools/" rel="noopener noreferrer"&gt;More&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Characteristics of Java
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Object Oriented&lt;/strong&gt;&lt;br&gt;
In Java, everything is an Object. Java can be easily extended since it is based on the Object model.&lt;br&gt;
&lt;strong&gt;Simple&lt;/strong&gt;&lt;br&gt;
Java is designed to be easy to learn. If you understand the basic concept of OOP Java, it would be easy to master.&lt;br&gt;
&lt;strong&gt;Platform Independent&lt;/strong&gt;&lt;br&gt;
When Java is compiled, it is not compiled into platform-specific machine, rather into platform-independent byte code. This byte code is distributed over the web and interpreted by the Virtual Machine (JVM) on whichever platform it is being run on.&lt;br&gt;
&lt;strong&gt;Secure&lt;/strong&gt;&lt;br&gt;
With Java's secure feature it enables to develop virus-free, tamper-free systems. Authentication techniques are based on public-key encryption.&lt;br&gt;
&lt;strong&gt;Portable&lt;/strong&gt;&lt;br&gt;
Being architecture-neutral and having no implementation-dependent aspects of the specification makes Java portable. &lt;br&gt;
&lt;strong&gt;Multithreaded&lt;/strong&gt;&lt;br&gt;
With Java's multithreaded feature it is possible to write programs that can perform many tasks simultaneously. This design feature allows the developers to construct interactive applications that can run smoothly.&lt;br&gt;
&lt;strong&gt;Architecture-neutral&lt;/strong&gt;&lt;br&gt;
Java compiler generates an architecture-neutral object file format, which makes the compiled code executable on many processors, with the presence of Java runtime system.&lt;br&gt;
&lt;strong&gt;Interpreted&lt;/strong&gt;&lt;br&gt;
Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development process is more rapid and analytical since the linking is an incremental and lightweight process.&lt;br&gt;
&lt;strong&gt;Dynamic&lt;/strong&gt;&lt;br&gt;
Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment. Java programs can carry an extensive amount of run-time information that can be used to verify and resolve accesses to objects at run-time.&lt;br&gt;
&lt;strong&gt;High Performance&lt;/strong&gt;&lt;br&gt;
With the use of Just-In-Time compilers, Java enables high performance.&lt;br&gt;
&lt;strong&gt;Distributed&lt;/strong&gt;&lt;br&gt;
Java is designed for the distributed environment of the internet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Development process with java
&lt;/h2&gt;

&lt;p&gt;Java source files are written as plain text documents. The programmer typically writes Java source code in an Integrated Development Environment (IDE) for programming. An IDE supports the programmer in the task of writing code, e.g., it &lt;code&gt;provides auto-formatting&lt;/code&gt; of the source code, &lt;code&gt;highlighting of the important keywords&lt;/code&gt;, etc. At some point, the programmer (or the IDE) calls the Java compiler (javac). The Java compiler creates the bytecode instructions. These instructions are stored in a &lt;code&gt;.class&lt;/code&gt; file and can be executed by the Java Virtual Machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Garbage collector
&lt;/h2&gt;

&lt;p&gt;The JVM automatically recollects or reclaims the memory which is not in use by the program. The Java garbage collector checks all object references and finds the objects which can be automatically released. While the garbage collector relieves the programmer from the need to explicitly manage memory, the programmer still needs to ensure that he does not keep unneeded object references, otherwise the garbage collector cannot release the associated memory.&lt;br&gt;
Keeping unneeded object references is typically called &lt;strong&gt;memory leaks&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Classpath
&lt;/h2&gt;

&lt;p&gt;The classpath defines where the Java compiler and Java runtime look for a &lt;code&gt;.class&lt;/code&gt; files to load. These instructions can be used in the Java program. For example, if you want to use an external Java library you have to add this library to your classpath to use it in your program. Java is case-sensitive, e.g., variables called jeff and Jeff are treated as different variables&lt;/p&gt;

&lt;h2&gt;
  
  
  Java Development Tools
&lt;/h2&gt;

&lt;p&gt;Java source files are written as plain text documents. The programmer writes Java source code in an Integrated Development Environment(IDE) for programming. An &lt;strong&gt;integrated development environment (IDE) or interactive development&lt;br&gt;
environment&lt;/strong&gt; is a software application that provides comprehensive facilities for programmers to use for software development. An &lt;strong&gt;IDE&lt;/strong&gt; normally consists of a &lt;code&gt;source code editor&lt;/code&gt;, &lt;code&gt;build automation tools&lt;/code&gt;, and &lt;code&gt;a debugger&lt;/code&gt;.&lt;br&gt;
Several modern IDEs integrate with Intelli-sense coding features. An IDE also supports the programmer in the task of writing code, e.g., it provides auto-formatting of the source code, highlighting of the important keywords, etc.&lt;br&gt;
Common Java IDE Tools include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IntelliJ IDEA &lt;/li&gt;
&lt;li&gt;Eclipse Java development tools (JDT)&lt;/li&gt;
&lt;li&gt;JCreator — Java IDE&lt;/li&gt;
&lt;li&gt;Java-Editor&lt;/li&gt;
&lt;li&gt;NetBeans IDE among others&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the next article, we will discuss the &lt;a href="https://dev.to/killallnano/java-for-beginners-installation-of-java-nhc"&gt;Installation of Java&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for taking your time to read this article&lt;/p&gt;

</description>
      <category>java</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>Python for Everyone: Mastering Python the right way</title>
      <dc:creator>Jeff Odhiambo</dc:creator>
      <pubDate>Mon, 28 Feb 2022 05:52:05 +0000</pubDate>
      <link>https://dev.to/smartjeff/python-for-everyone-mastering-python-the-right-way-183i</link>
      <guid>https://dev.to/smartjeff/python-for-everyone-mastering-python-the-right-way-183i</guid>
      <description>&lt;p&gt;what is the best way to learn python? There are various learning and teaching techniques used.Some of the techniques might include reading documentations and books related to the subject of study, watching tutorials, physical teaching by a teacher and by putting into practice all that you learn.&lt;br&gt;
A given technique might work well for person A as opposed to person B, therefore I would prefer usage of a technique that best suits you.&lt;br&gt;
In this article, I'll be discussing "Mastering python the best way" where ill highlight also methods/techniques that worked for most developers.&lt;/p&gt;

&lt;h2&gt;
  
  
  What should you learn?
&lt;/h2&gt;

&lt;p&gt;When getting started with python, one should;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have an overview of python or a little history of python.&lt;/li&gt;
&lt;li&gt;Learn on how to set up python environment.&lt;/li&gt;
&lt;li&gt;Learn basics of Python .i.e, Python fundamentals.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are captured in previous article &lt;a href="https://dev.to/killallnano/python-101-introduction-to-modern-python-196j"&gt;Python 101: Introduction to Modern Python &lt;/a&gt; where you'll learn how to install and set up your python as well as the fundamentals of python i.e you'll learn how to print to console,take input from the user, perform arithmetic operations among others. Find time to visit &lt;a href="https://dev.to/killallnano/python-101-introduction-to-modern-python-196j"&gt;Python 101: Introduction to Modern Python &lt;/a&gt; if you missed it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data structures and algorithm in Python&lt;/li&gt;
&lt;li&gt;Control flow and decision making in python(use of &lt;code&gt;if&lt;/code&gt; and &lt;code&gt;elif&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Functions in python&lt;/li&gt;
&lt;li&gt;Classes in python&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Again in the previous article &lt;a href="https://dev.to/killallnano/introduction-to-data-structures-and-algorithms-with-python-33c9"&gt;Introduction to Data Structures and Algorithms With Python &lt;/a&gt;,I discussed the various data structures and algorithm in Python, where we checked on some of the inbuilt data structures such as &lt;code&gt;list&lt;/code&gt;, &lt;code&gt;tuple&lt;/code&gt;, &lt;code&gt;dictionary&lt;/code&gt;, etc and some derived or user created data structure such as &lt;code&gt;trees&lt;/code&gt; etc and how they are implemented.&lt;br&gt;
We used various functions and illustrated how they are used as well as classes in python. If you haven't checked on them, you might consider visiting &lt;a href="https://dev.to/killallnano/introduction-to-data-structures-and-algorithms-with-python-33c9"&gt;Introduction to Data Structures and Algorithms With Python &lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;These are the basics that almost all the python developers should know and understand irrespective of your field.&lt;br&gt;
We also discussed on our &lt;a href="https://dev.to/killallnano/python-101-introduction-to-modern-python-196j"&gt;first article&lt;/a&gt; that python has various applications. Some of them being&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Artificial Intelligence(AI) &amp;amp; Machine Learning&lt;/li&gt;
&lt;li&gt;Data Science&lt;/li&gt;
&lt;li&gt;Web Development&lt;/li&gt;
&lt;li&gt;Game development&lt;/li&gt;
&lt;li&gt;Desktop GUI Development&lt;/li&gt;
&lt;li&gt;Automation&lt;/li&gt;
&lt;li&gt;Audio and Visual Applications&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These applications might be considered as a "course to learn" and each might have different learning paths, documents and sites that offers the courses. If you use &lt;a href="https://www.linkedin.com/learning/" rel="noopener noreferrer"&gt;linked&lt;/a&gt; in for learning you might consider the courses below and paths below. But you can also use various platform of your choice such as &lt;a href="https://www.udemy.com" rel="noopener noreferrer"&gt;Udemy&lt;/a&gt;, &lt;a href="https://www.coursera.org" rel="noopener noreferrer"&gt;Cousera&lt;/a&gt;, &lt;a href="https://www.ibm.com" rel="noopener noreferrer"&gt;IBM&lt;/a&gt;, &lt;a href="https://www.w3schools.com" rel="noopener noreferrer"&gt;W3Schools&lt;/a&gt;, &lt;a href="https://www.javatpoint.com" rel="noopener noreferrer"&gt;Javatpoint&lt;/a&gt; among others&lt;/p&gt;

&lt;h2&gt;
  
  
  AI and Machine Learning
&lt;/h2&gt;

&lt;p&gt;Artificial intelligence and machine learning are the part of computer science that are correlated with each other. These two technologies are the most trending technologies which are used for creating intelligent systems.&lt;br&gt;
Artificial intelligence is a field of computer science which makes a computer system that can mimic human intelligence. It is comprised of two words "Artificial" and "intelligence", which means "a human-made thinking power."&lt;br&gt;
Machine learning is about extracting knowledge from the data. It can be defined as,&lt;br&gt;
Machine learning is a subfield of artificial intelligence, which enables machines to learn from past data or experiences without being explicitly programmed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Courses for AI and Machine learning
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.linkedin.com/learning/machine-learning-with-python-foundations" rel="noopener noreferrer"&gt;Machine Learning&lt;/a&gt; By &lt;a href="https://www.linkedin.com/learning/instructors/frederick-nwanganga" rel="noopener noreferrer"&gt;Frederick Nwanganga&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.linkedin.com/learning/artificial-intelligence-foundations-machine-learning" rel="noopener noreferrer"&gt;Artificial Intelligence Foundations: Machine Learning&lt;/a&gt; By &lt;a href="https://www.linkedin.com/learning/instructors/doug-rose" rel="noopener noreferrer"&gt;Doug Rose&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Learning Paths for AI and Machine learning
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/learning/paths/master-the-fundamentals-of-ai-and-machine-learning" rel="noopener noreferrer"&gt;Master the Fundamentals of AI and Machine Learning&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/learning/paths/become-a-machine-learning-specialist" rel="noopener noreferrer"&gt;Become a Machine Learning Specialist&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also search for the books below and feel free to also learn through the &lt;a href="https://www.youtube.com/results?search_query=AI+and+Machine+learning+in+python" rel="noopener noreferrer"&gt;YouTube tutorials&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftwsg2g7vi4bqre6wjz31.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftwsg2g7vi4bqre6wjz31.jpg" alt="AI in python"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffkb60kgwziarm2qygae9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffkb60kgwziarm2qygae9.jpg" alt="Advanced guide for artificial intelligence"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa3n4j3crlal9w8d3z03b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa3n4j3crlal9w8d3z03b.png" alt="Machine learning using python"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F41qdhoxihjrs9ys68gcs.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F41qdhoxihjrs9ys68gcs.jpg" alt="introduction to machine learning in python"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Data Science
&lt;/h2&gt;

&lt;p&gt;Data science is a deep study of the massive amount of data, which involves extracting meaningful insights from raw, structured, and unstructured data that is processed using the scientific method, different technologies, and algorithms&lt;br&gt;
It is a multidisciplinary field that uses tools and techniques to manipulate the data so that you can find something new and meaningful.&lt;/p&gt;

&lt;h3&gt;
  
  
  Whats the difference between Data Science and Machine Learning
&lt;/h3&gt;

&lt;p&gt;Data Science is the study of data cleansing, preparation, and analysis, while machine learning is a branch of AI and subfield of data science.&lt;/p&gt;

&lt;h3&gt;
  
  
  Courses for Data Science
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.linkedin.com/learning/python-for-data-science-essential-training-part-1" rel="noopener noreferrer"&gt;Python for Data Science Essential Training Part 1&lt;/a&gt; By &lt;a href="https://www.linkedin.com/learning/instructors/lillian-pierson-p-e" rel="noopener noreferrer"&gt;Lillian Pierson,P.E.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.linkedin.com/learning/python-for-data-science-essential-training-part-2" rel="noopener noreferrer"&gt;Python for Data Science Essential Training Part 2&lt;/a&gt; By &lt;a href="https://www.linkedin.com/learning/instructors/lillian-pierson-p-e" rel="noopener noreferrer"&gt;Lillian Pierson,P.E.&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Learning Paths for Data Science
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/learning/paths/advance-your-python-skills-for-data-science" rel="noopener noreferrer"&gt;Advance Your Python Skills for Data Science&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/learning/paths/master-python-for-data-science-16361344" rel="noopener noreferrer"&gt;Master Python for Data Science&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also search for the books below and feel free to also learn through the &lt;a href="https://www.youtube.com/results?search_query=python+for+data+science" rel="noopener noreferrer"&gt;YouTube tutorials&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fghjkuhfjo7bl343v8bap.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fghjkuhfjo7bl343v8bap.png" alt="Python for data science"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdfi7hum2u3f1a2treq5l.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdfi7hum2u3f1a2treq5l.jpg" alt="Python for data science"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Web Development
&lt;/h2&gt;

&lt;p&gt;Python offers many frameworks from which to choose from including &lt;code&gt;Flask&lt;/code&gt;, &lt;code&gt;CherryPy&lt;/code&gt;, &lt;code&gt;Pyramid&lt;/code&gt;, &lt;code&gt;Django&lt;/code&gt; and &lt;code&gt;web2py&lt;/code&gt;. These frameworks have been used to power some of the world’s most popular sites such as Spotify, Mozilla, Reddit,etc. I had discussed &lt;strong&gt;django&lt;/strong&gt; in my previous article &lt;a href="https://dev.to/killallnano/getting-started-with-django-13ep"&gt;Getting Started with Django&lt;/a&gt; where I showed how to download, set up virtual environment, create a project, app among many more. You might consider checking on it to learn more.&lt;br&gt;
Web development can be learnt in many platform such as the ones listed at the beginning of the articles such as LinkedIn Learning, Udemy, Cousera etc.&lt;br&gt;
Learning through the documentation of the various frameworks is also a great one, in addition to that there are free tutorials on &lt;a href="https://www.youtube.com/results?search_query=Python+for+web" rel="noopener noreferrer"&gt;YouTube&lt;/a&gt;, and documents that can help a lot.&lt;br&gt;
Some of the books that I would recommend are:&lt;br&gt;
&lt;strong&gt;Django 3 by example&lt;/strong&gt; where you'll learn and build operational sites&lt;br&gt;
&lt;strong&gt;Django for beginners&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Django for Professionals&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Flask Framework&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8qzw79szbrupt5bkdu7w.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8qzw79szbrupt5bkdu7w.jpg" alt="Flask"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Building web applications with flask&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuk3t40gsamhh7adkw34r.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuk3t40gsamhh7adkw34r.jpg" alt="Build in Flask"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Flask by example&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs2zuyfkdlsge445ravqy.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs2zuyfkdlsge445ravqy.jpg" alt="Flask by examples"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Python is also used for Desktop GUI and Game development and more that will be discussed in the next article.&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>django</category>
    </item>
    <item>
      <title>What are the best programming languages to learn in 2022?</title>
      <dc:creator>Jeff Odhiambo</dc:creator>
      <pubDate>Mon, 21 Feb 2022 22:26:11 +0000</pubDate>
      <link>https://dev.to/smartjeff/what-are-the-best-programming-languages-to-learn-in-2022-1phb</link>
      <guid>https://dev.to/smartjeff/what-are-the-best-programming-languages-to-learn-in-2022-1phb</guid>
      <description>&lt;p&gt;I would like to specialize in software development. What languages would you recommend me to and some helpful resources that I can use to get started in those particular languages?&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Configure Static IP on Ubuntu</title>
      <dc:creator>Jeff Odhiambo</dc:creator>
      <pubDate>Mon, 21 Feb 2022 07:19:09 +0000</pubDate>
      <link>https://dev.to/smartjeff/how-to-configure-static-ip-on-ubuntu-1eic</link>
      <guid>https://dev.to/smartjeff/how-to-configure-static-ip-on-ubuntu-1eic</guid>
      <description>&lt;p&gt;Get the name of the network interface and the default gateway.&lt;br&gt;
We can use &lt;code&gt;ifconfig&lt;/code&gt; that will display the interfaces with their IP address, to be able to use ifconfig you’ll be required to install &lt;code&gt;net-tools&lt;/code&gt; in some OS.&lt;br&gt;
Run &lt;code&gt;sudo apt-get install -y net-tools&lt;/code&gt;. or run &lt;code&gt;ip link&lt;/code&gt;.&lt;br&gt;
&lt;code&gt;ifconfig&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl8txfhf9hj7i9ko8akzz.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl8txfhf9hj7i9ko8akzz.PNG" alt="First time"&gt;&lt;/a&gt;&lt;br&gt;
In my case the interphase where ill configure the static ip is &lt;code&gt;enp0s3&lt;/code&gt;.&lt;br&gt;
&lt;strong&gt;Note:&lt;/strong&gt; Your interphase might be different from mine.&lt;br&gt;
In order to assign a static IP address, we will modify a file in &lt;code&gt;/etc/netplan&lt;/code&gt;. We will &lt;code&gt;cd&lt;/code&gt; into /etc/netplan. Run the command below&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

cd /etc/netplan


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then &lt;code&gt;ls&lt;/code&gt; to list its content, the name of the file might be different depending on the system configuration. In my case, it is named &lt;code&gt;01-network-manager-all.yaml&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvzjsmf3vm7w7f2sq71ic.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvzjsmf3vm7w7f2sq71ic.PNG" alt="Second time"&gt;&lt;/a&gt;&lt;br&gt;
By default the file looks like the one below:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3mhqtrnqsmxmkc0nlrwf.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3mhqtrnqsmxmkc0nlrwf.PNG" alt="Step 3"&gt;&lt;/a&gt;&lt;br&gt;
Each Netplan Yaml file starts with the &lt;code&gt;network&lt;/code&gt; key that has at least two required elements. The first required element is the &lt;code&gt;version&lt;/code&gt; of the network configuration format, and the second one is the device type. The device type can be &lt;code&gt;ethernets&lt;/code&gt;, &lt;code&gt;bridges&lt;/code&gt;, &lt;code&gt;bonds&lt;/code&gt;, or &lt;code&gt;vlans&lt;/code&gt;. In this case we will be using the ethernet.&lt;br&gt;
Under the &lt;strong&gt;device type&lt;/strong&gt; in the case of &lt;code&gt;ethernets&lt;/code&gt; is where we can configure our interphases e.g the enp0s3 that can be configured to obtain IP addresses from DHCP server by setting &lt;code&gt;dhcp4&lt;/code&gt; to &lt;code&gt;yes&lt;/code&gt; or &lt;code&gt;true&lt;/code&gt; e.g &lt;code&gt;dhcp4: yes&lt;/code&gt; or &lt;code&gt;dhcp4: true&lt;/code&gt;.&lt;br&gt;
The configuration above also includes the &lt;strong&gt;renderer type&lt;/strong&gt;. If you installed Ubuntu in server mode, the renderer is configured to use &lt;code&gt;networkd&lt;/code&gt; as the back end, but in my case, it is set to &lt;code&gt;NetworkManager&lt;/code&gt; since am using ubuntu desktop in this illustration not ubuntu server.&lt;/p&gt;

&lt;p&gt;To assign a static IP address to enp0s3 interface, edit the file as follows:&lt;br&gt;
Set DHCP to &lt;code&gt;dhcp4: no&lt;/code&gt;. This is done so it doesn't take ip addresses from the DHCP.&lt;br&gt;
Specify the static IP address of your choice, in my case I'll use &lt;code&gt;192.168.10.10/24&lt;/code&gt;. Under addresses: you can add one or more IPv4 or IPv6 IP addresses that will be assigned to the network interface.&lt;br&gt;
Specify the gateway &lt;code&gt;gateway4: 192.168.10.1&lt;/code&gt;&lt;br&gt;
Under nameservers, set the IP addresses of the nameservers if any, &lt;code&gt;addresses: [8.8.8.8, 1.1.1.1]&lt;/code&gt;&lt;br&gt;
The final file should be similar to the one below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp0s3:
      dhcp4: no
      addresses:
        [192.168.10.10/24]
      gateway4: 192.168.10.1
      nameservers:
          addresses: [8.8.8.8, 1.1.1.1]


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Note&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Make sure to follow the YAML code indent standards when editing &lt;code&gt;.yaml file&lt;/code&gt;.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;If there are syntax errors in the configuration, the changes will not be applied.&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once done save and close the file.&lt;br&gt;
While using nano use&lt;code&gt;ctrl + X&lt;/code&gt; followed by &lt;code&gt;Y&lt;/code&gt; then enter to exit.&lt;br&gt;
Then apply the changes using:&lt;br&gt;
&lt;code&gt;sudo netplan apply&lt;/code&gt;&lt;br&gt;
Verify the changes by typing:&lt;br&gt;&lt;br&gt;
&lt;code&gt;ip addr show dev ens3&lt;/code&gt; or &lt;code&gt;ifconfig&lt;/code&gt; then you'll be able to see the changes&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpe1hf0q1fos8218gwq6a.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpe1hf0q1fos8218gwq6a.PNG" alt="Final"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next article, we will be able to configure DNS.&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>ubuntu</category>
    </item>
  </channel>
</rss>
