M1L1 Lyst5044
M1L1 Lyst5044
to
INTERNSHIP STUDIO
Module 01 | Lesson 01
Overview of JAVA
W W W. I N T E R N S H I P S T U D I O. C O M
Java’s History
James Gosling and Sun Microsystems (Green Team)
Firstly, it was called "Greentalk" by James Gosling, and the file extension
was .gt.
After that, it was called Oak
Java, May 20, 1995, Sun World
HotJava
– The first Java-enabled Web browser
JDK (Java Development Kit) 1.0 released in January 23,1996.
W W W. I N T E R N S H I P S T U D I O. C O M
JAVA
• Java is a high-level, general-purpose programming
language developed by a small team, headed by James
Gosling and Patrick Naughton at Sun Microsystems in
1991. It is currently owned by Oracle Corporation.
• It was designed to be small, simple, and portable across
platforms and operating systems.
• It was initially developed for consumer devices. Later it has
become a popular platform to develop enterprise
applications.
W W W. I N T E R N S H I P S T U D I O. C O M
Why JAVA
• It’s the current “hot” language
W W W. I N T E R N S H I P S T U D I O. C O M
What Is Java Used For?
• Server-Side or Backend Application Development
W W W. I N T E R N S H I P S T U D I O. C O M
Real world Applications Of Java
W W W. I N T E R N S H I P S T U D I O. C O M
JAVA Features
W W W. I N T E R N S H I P S T U D I O. C O M
Object Oriented Programming
W W W. I N T E R N S H I P S T U D I O. C O M
Object Oriented Paradigms
• Object
• Class
• Inheritance
• Polymorphism
• Abstraction
• Encapsulation
W W W. I N T E R N S H I P S T U D I O. C O M
Encapsulation
• Encapsulation in Java is a
mechanism of wrapping the data
(variables) and code acting on the
data (methods) together as a single
unit.
• In encapsulation, the variables of a
class will be hidden from other
classes, and can be accessed only
through the methods of their
current class
W W W. I N T E R N S H I P S T U D I O. C O M
Inheritance
• Inheritance in Java is
a mechanism in which
one object acquires all
the properties and
behaviors of a parent
object.
• Inheritance represents
the IS-A
relationship which is
also known as
a parent-
child relationship.
W W W. I N T E R N S H I P S T U D I O. C O M
Data Hiding
• Data hiding is a technique
of hiding internal object
details, i.e., data
members. It is an object-
oriented programming
technique.
• Access Specifiers:
1.Private
2.Public
3. Protected
W W W. I N T E R N S H I P S T U D I O. C O M
Polymorphism
• Polymorphism means
"many forms“.
• In Java, polymorphism
refers to the ability of a
class to provide
different
implementations of a
method, depending on
the type of object that
is passed to the
method.
W W W. I N T E R N S H I P S T U D I O. C O M
FOP versus OOP
W W W. I N T E R N S H I P S T U D I O. C O M
Java Editions
1. Java SE (Standard Edition)
• This edition consists of libraries for building core Java applications.
• It includes core topics like OOPs, String, Exception, Inner classes, Multithreading, I/O
Stream, Networking, AWT, Swing, Reflection, Collection, etc
2. Java EE (Enterprise Edition)
• This edition consists of libraries for building distributed Java applications.
• It includes topics like Servlet, JSP, Web Services, EJB, JPA, etc
3. Java ME (Micro Edition)
It is a micro platform that is dedicated to mobile applications.
4. JavaFX
It is used to develop rich internet applications. It uses a lightweight user interface API.
W W W. I N T E R N S H I P S T U D I O. C O M
The Initial Java Setup
• Go to the website http://java.com by typing this in the address bar of your web
browser. It will take you to the screen below:
W W W. I N T E R N S H I P S T U D I O. C O M
How to set path in Java
1) How to set the Temporary Path of JDK in Windows
To set the temporary path of JDK, you need to follow the following steps:
• Open the command prompt
• Copy the path of the JDK/bin directory
• Write in command prompt: set path=copied_path
For Example:
set path=C:\Program Files\Java\jdk1.8.0_51\bin
W W W. I N T E R N S H I P S T U D I O. C O M
How to set Permanent Path of JDK
in Windows
• For setting the permanent path of JDK, you need to follow these steps:
• Go to MyComputer properties -> advanced tab -> environment variables ->
new tab of user variable -> write path in variable name -> write path of bin
folder in variable value -> ok -> ok -> ok
W W W. I N T E R N S H I P S T U D I O. C O M
1) Go to MyComputer properties
W W W. I N T E R N S H I P S T U D I O. C O M
2) Click on the advanced tab
Type advanced system settings in the search box (beside the Windows start button),
clicks View advanced system settings.
W W W. I N T E R N S H I P S T U D I O. C O M
3. Environment Variables
Select Advance tab, clicks Environment Variables
W W W. I N T E R N S H I P S T U D I O. C O M
4. Add JAVA_HOME
• In System variables, clicks New... button to add a new JAVA_HOME variable and point
it to the JDK installed folder.
W W W. I N T E R N S H I P S T U D I O. C O M
5. Update PATH
• In System variables, find PATH, clicks edit... button :
In old version of Windows, it will prompt you below dialog box to edit the values
directly, append this %JAVA_HOME%\bin; to the end of the line.
W W W. I N T E R N S H I P S T U D I O. C O M
• In latest Windows 10, it will prompt you below dialog box, clicks on New button, and
add this %JAVA_HOME%\bin
W W W. I N T E R N S H I P S T U D I O. C O M
Structure of Java programs
public class <name> {
public static void main(String[] args) {
<statement(s)>;
}
}
W W W. I N T E R N S H I P S T U D I O. C O M
Java program layout
• A typical Java file looks like:
import java.util.*;
public class HelloWorld {
// object definitions go here
. .
System.out.println ("Welcome to Java!");
}
W W W. I N T E R N S H I P S T U D I O. C O M
The Block
• The Block
– 0, 1, or more statements
– Begins and ends with curly braces { }
– Can be used anywhere a statement is allowed.
W W W. I N T E R N S H I P S T U D I O. C O M
Class
Class :
The class is the fundamental concept in JAVA
A description of a type of objects
Classes have data (fields) and code (methods) and classes (member classes
or inner classes)
Every Java program must have at least one class. Each class has a name. By
convention, class names start with an uppercase letter. In this example, the
class name is Welcome.
W W W. I N T E R N S H I P S T U D I O. C O M
Main Method
In order to run a class, the class must contain a method named main.
The program is executed from the main method.
W W W. I N T E R N S H I P S T U D I O. C O M
Statement
• A statement represents an action or a sequence of actions.
– Performs some action
– Terminates with a semicolon (;)
– Can span multiple lines
W W W. I N T E R N S H I P S T U D I O. C O M
System.out.println
• Java programs use a statement called System.out.println to instruct the computer
to print a line of output on the console
– pronounced "print-linn"; sometimes called a println statement for short
– 2. System.out.println();
• Prints a blank line on the console.
W W W. I N T E R N S H I P S T U D I O. C O M
Statement Terminator
• Every statement in Java ends with a semicolon (;)
W W W. I N T E R N S H I P S T U D I O. C O M
Special Symbols
Character Name Description
" " Opening and closing Enclosing a string (i.e., sequence of characters).
quotation marks
; Semicolon Marks the end of a statement.
W W W. I N T E R N S H I P S T U D I O. C O M
Java static keyword
• The static keyword in Java is used for memory management mainly. We
can apply static keyword with variables, methods, blocks and nested classes
. The static keyword belongs to the class than an instance of the class.
W W W. I N T E R N S H I P S T U D I O. C O M
Keywords
W W W. I N T E R N S H I P S T U D I O. C O M
Identifiers
• identifier: A name that we give to a piece of data or part of a program.
Identifiers are useful because they allow us to refer to that data or code later in the program.
Identifiers give names to:
» classes
» methods
» variables (named pieces of data; seen later)
• Identifier Rules:
– Must start with a "Java letter"
• A - Z, a - z, _, $,
• Can contain essentially any number of Java letters and digits, but no spaces
– Case sensitive!!
• Number1 and number1 are different!
– Cannot be keywords or reserved words
W W W. I N T E R N S H I P S T U D I O. C O M
White Space
• Space, tab, newline are white space characters
• At least one white space character is required between a keyword and
identifier
• Any amount of white space characters are permitted between identifiers,
keywords, operators, and literals
W W W. I N T E R N S H I P S T U D I O. C O M
Comments
• comment: A note written in the source code by the programmer to make the code easier
to understand.
– Comments are not executed when your program runs.
– Most Java editors turn your comments a special colour to make it easier to identify them.
• Block comments
– Can span several lines
– Begin with /*
– End with */
• Line comments
– Start with //
• Examples:
/* It can even span
multiple lines. */
// This is a one-line comment.
W W W. I N T E R N S H I P S T U D I O. C O M
Escape Sequences
• An escape sequence is a sequence of two characters beginning with the character \
• A way to represents special characters/symbols
Character Escape Sequence
Newline \n
Tab \t
Double quotes \"
Single quote \'
Backslash \\
Backspace \b
Carriage return \r
Form feed \f
W W W. I N T E R N S H I P S T U D I O. C O M
Java Program Compilation
• The Java compiler (javac) converts a Java Program into Jata byte code
– Open DOS shell (in Windows) or Terminal (in Unix)
– Move to the directory where your Java program has been saved
– Enter the following command to compile:
javac HelloWorld.java
W W W. I N T E R N S H I P S T U D I O. C O M
Java Program Execution
• To execute the Java program, type the command java (from the command
prompt)
– For example, the current program HelloWorld.class can be executed as
Java HelloWorld
W W W. I N T E R N S H I P S T U D I O. C O M
Processing and Running HelloWorld
• javac HelloWorld.java
– Produces HelloWorld.class (byte code)
W W W. I N T E R N S H I P S T U D I O. C O M
Compiling and Executing a Program
W W W. I N T E R N S H I P S T U D I O. C O M
Compiling and Executing a Program
W W W. I N T E R N S H I P S T U D I O. C O M
C / C++ versus Java Execution
W W W. I N T E R N S H I P S T U D I O. C O M
Java IDE (Compiler / Editor)
• Eclipse
• IntelliJ IDEA
• BlueJ
• Notepad++
• Visual Studio Code
• NetBeans
W W W. I N T E R N S H I P S T U D I O. C O M
Eclipse
• http://eclipse.org/downloads - Download and install the Eclipse program you need
W W W. I N T E R N S H I P S T U D I O. C O M
• Create a new Java project by going to the menu on top: FILE > NEW > JAVA PROJECT
W W W. I N T E R N S H I P S T U D I O. C O M
Create a new class
W W W. I N T E R N S H I P S T U D I O. C O M
Execute FirstJavaPogram.java by clicking on this button located at the top and
check to make sure that the output produced
W W W. I N T E R N S H I P S T U D I O. C O M
S U M M A RY
You got this Next session
• J AVA Fe a t u re s
• OOP Concepts • D a t a Ty p e s
• J AVA Pro g r a m S t r u c t u re • Va r i a b l e s
• C o m p i l e & E xe c u t e J AVA
Pro g r a m
W W W. I N T E R N S H I P S T U D I O. C O M