Java (1) Lectures
Java (1) Lectures
Introduction to java
What is Java?
Java is popular high-level, class-based object
oriented programming language originally
developed by Sun Microsystems and released
in 1995.
Currently Java is owned by Oracle and more
than 3 billion devices run Java.
Java runs on a variety of platforms, such as
Windows, Mac OS, and the various versions
of UNIX.
Java is used to develop Mobile apps, Web
apps, Desktop apps, Games and much more.
Why to Learn Java?
Java is a MUST for students and working
professionals to become a great Software
Engineer specially when they are working
in Software Development Domain.
Java is fairly easy to learn, so if you are
starting to learn any programming
language then Java could be your great
choice.
Why to Learn Java?
There are many other good reasons which
makes Java as the first choice of any
programmer:
◦ Java is Open Source which means its available
free of cost.
◦ Java is simple and so easy to learn
◦ Java is much in demand and ensures high salary
◦ Java has a large vibrant community
◦ Java has powerful development tools
◦ Java is platform independent
JAVA Features
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 extensive amount of run-time information that
can be used to verify and resolve accesses to objects on run-time.
Java - Environment
Java - Environment
JDK(Java Development Kit): JDK is intended for
software developers and includes development
tools such as the Java compiler, Javadoc, Jar, and a
debugger.
JRE(Java Runtime Environment): JRE contains the
parts of the Java libraries required to run Java
programs and is intended for end-users. JRE can
be viewed as a subset of JDK.
JVM: JVM (Java Virtual Machine) is an abstract
machine. It is a specification that provides a
runtime environment in which java bytecode can
be executed. JVMs are available for many
hardware and software platforms.
Popular Java Editors
To write your Java programs, you will need a
text editor,you can consider one of the
following :
Notepad − On Windows machine, you can
use any simple text editor like Notepad
(Recommended for this tutorial), TextPad.
Netbeans − A Java IDE that is open-source
and free which can be downloaded
from https://www.netbeans.org/index.html.
Eclipse − A Java IDE developed by the
eclipse open-source community and can be
downloaded from https://www.eclipse.org/
Java - Basic Syntax
When we consider a Java program, it can be defined as a collection
of objects that communicate via invoking each other's methods. Let
us now briefly look into what do class, object, methods, and
instance variables mean.
Object − Objects have states and behaviors. Example: A dog has
states - color, name, breed as well as behavior such as wagging their
tail, barking, eating. An object is an instance of a class.
Class − A class can be defined as a template/blueprint that
describes the behavior/state that the object of its type supports.
Methods − A method is basically a behavior. A class can contain
many methods. It is in methods where the logics are written, data is
manipulated and all the actions are executed.
Instance Variables − Each object has its unique set of instance
variables. An object's state is created by the values assigned to
these instance variables.
Basic Syntax
About Java programs, it is very important to keep in mind
the following points.
◦ Case Sensitivity − Java is case sensitive, which means
identifier Hello and hello would have different meaning in Java.
◦ Class Names − For all class names the first letter should be in
Upper Case. If several words are used to form a name of the
class, each inner word's first letter should be in Upper Case.
Example: class MyFirstJavaClass
◦ Method Names − All method names should start with a
Lower Case letter. If several words are used to form the name of
the method, then each inner word's first letter should be in
Upper Case.
Example: public void myMethodName()
◦ Program File Name − Name of the program file should
exactly match the class name.
Java Variables
Here data type is one of Java's data types and variable is the
name of the variable. To declare more than one variable of
the specified type, you can use a comma-separated list.
Following are valid examples of variable declaration and
initialization in Java .
◦ int a, b, c; // Declares three ints, a, b, and c.
◦ int a = 10, b = 10; //Example of initialization
◦ byte B = 22; // initializes a byte type variable B.
◦ double pi = 3.14159; // declares and assigns a value of PI.
◦ char a = 'a'; // the char variable and it is initialized with value 'a'