Lesson 1 Introduction To Java
Lesson 1 Introduction To Java
Procedural Programming can be defined as a programming model which is derived from structured programming,
based upon the concept of calling procedure. Procedures, also known as routines, subroutines or functions, simply consist of a
series of computational steps to be carried out. During a program’s execution, any given procedure might be called at any point,
including by other procedures or itself.
Object oriented programming can be defined as a programming model which is based upon the concept of objects.
Objects contain data in the form of attributes and code in the form of methods. In object oriented programming, computer
programs are designed using the concept of objects that interact with real world. Object oriented programming languages are
various but the most popular ones are class-based, meaning that objects are instances of classes, which also determine their
types.
• Portable
Being architecture-neutral and having no implementation dependent aspects of the
specification makes Java portable. The compiler in Java is written in ANSI C with a clean
portability boundary, which is a POSIX subset.
• Robust
Java makes an effort to eliminate error-prone situations by emphasizing mainly on compile
time error checking and runtime checking.
• Multithreaded
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.
• Interpreted
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 light-weight process.
• High Performance
With the use of Just-In-Time compilers, Java enables high performance.
• Distributed
Java is designed for the distributed environment of the internet.
• Dynamic
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.
Java IDEs
Top 10 Java IDEs
• Eclipse
• IntelliJ
• NetBeans
• JDeveloper
• MyEclipse
• BlueJ
• JCreator
• DrJava
• jGRASP
• JSource
Understanding the First Class
Understanding the main() Method
Compiling a Java Class and Correcting Syntax Errors
• Compiling a Java class
– Compile the source code into bytecode
– Translate the bytecode into executable statements
• Using a Java interpreter
– Type javac First.java
• Compilation outcomes
– javac is an unrecognized command
– Program language error messages
– No messages indicating successful completion
• Reasons for error messages
– Misspelled the command javac
– A misspelled filename
– Not within the correct subfolder or subdirectory on the
command line
– Improper installation of Java
Correcting Syntax Errors
• Logic error
– The syntax is correct but incorrect results were
produced when executed
• Run-time error
– Not detected until execution
– Often difficult to find and resolve
Adding Comments to a Java Class
• Program comments
Types of Java comments
– Nonexecuting statements added to a
program for documentation Line comments
– Use to leave notes for yourself or Start with two forward slashes (//)
others Continue to the end of the current line
Do not require an ending symbol
– Include the author, date, and class’s Block comments
name or function Start with a forward slash and an
• Comment out a statement asterisk (/*)
End with an asterisk and a forward
– Turn it into a comment slash (*/)
– The compiler does not translate, and
the JVM does not execute its command
• Types of Java comments (cont’d.)
– Javadoc comments
• A special case of block
comments
• Begin with a slash and two
asterisks (/**)
• End with an asterisk and a
forward slash (*/)
• Use to generate
documentation