Introduction To JAVA
Java is Everywhere
Java Buzzwords
Java Buzzwords
• Simple:
Java language is a simple programming language because:
• Java syntax is based on C++ (so easier for programmers to learn it after C++).
• Java has removed many complicated and rarely-used features, for example,
explicit pointers, operator overloading, etc.
• There is no need to remove unreferenced objects because there is an
Automatic Garbage Collection in Java.
Java Buzzwords
• Object Oriented
Object-oriented programming (OOPs) is a methodology that simplifies software
development and maintenance by providing some rules.
• Basic concepts of OOPs are:
• Object
• Class
• Inheritance
• Polymorphism
• Abstraction
• Encapsulation
NOTE - OOP Features will be discussed in detail in next sprints.
Mrs. Soniya Sharma
[email protected] Java Buzzwords
• Platform Independent
Java code can be executed on multiple platforms, for
example, Windows, Linux, Sun Solaris, Mac/OS, etc. Java
code is compiled by the compiler and converted into
bytecode.
This bytecode is a platform-independent code because it can
be run on multiple platforms, i.e., Write Once and Run
Anywhere (WORA).
Java Buzzwords
• Secured
Java is best known for its security. With Java, we can develop virus-free systems.
Java is secured because:
• No explicit pointer
• Java Programs run inside a virtual machine sandbox
Java Buzzwords
• Robust
Java is robust because:
• It uses strong memory management.
• There is a lack of pointers that avoids security problems.
• Automatic garbage collection process by sporadically executing finalize().
• Exception handling and the type checking mechanism.
Java Buzzwords
• Architecture Neutral
There are no implementation dependent features.
• For example, the size of primitive types is fixed.
• In C programming, int data type occupies 2 bytes of memory for 32-bit architecture and
4 bytes of memory for 64-bit architecture. In java it occupies 4 bytes of memory for both
32 and 64-bit architectures in Java.
Java Buzzwords
• Portable
• Java is portable because it facilitates you to carry the Java bytecode to any platform. It
doesn't require any implementation.
• High-performance
• The Java bytecode was carefully designed so that it would be easy to translate directly
into native machine code for very high performance by using a just-in-time compiler.
Java Buzzwords
• Distributed
• Java is designed for the distributed environment of the Internet, because it handles
TCP/IP protocols. RMI and EJB are used for creating distributed applications. This
feature of Java makes us able to access files by calling the methods from any machine
on the internet.
Java Buzzwords
• Multi-threaded
• A thread is like a separate program, executing concurrently. We can write Java
programs that deal with many tasks at once by defining multiple threads. The main
advantage of multi-threading is that it doesn't occupy memory for each thread. It shares
a common memory area. Threads are important for multi-media, Web applications, etc.
• Dynamic
• Java programs carry with them substantial amounts of run-time type information that is
used to verify and resolve accesses to objects at run time. This makes it possible to
dynamically link code in a safeMrs.and
Soniyaexpedient manner.
Sharma [email protected]
Java’s Magic : Bytecode
• The output of Java compiler is not executable code rather, it is bytecode.
• Bytecode allows Java to solve both the security and the portability problems.
• Bytecode is executed by the Java run-time system, which is called as Java Virtual
Machine (JVM).
• The JVM is an interpreter for bytecode.
• Bytecode makes it possible to run a program in a wide variety of environments as only
the JVM needs to be implemented for each platform.
• The Just In Time compiler, compiles the code as needed, during execution, this gives
significant performance boost.
Mrs. Soniya Sharma [email protected]
Java’s Magic : Bytecode
Java Development Kit (JDK)
JDK helps the programmer in
development(compilation and execution)
of java programs. It's a software package
that contains tools and libraries needed for
compilation and execution of java
programs.
Java Runtime Environment (JRE)
• JRE provides a runtime environment to your program for it's execution. As soon as you
start running your program using java command, the job of JRE starts and it ends when
either the program ran successfully or any error is thrown.
• JRE is also a software package which contains JVM, runtime libraries and other
supporting files needed to run a program.
Java Virtual Machine (JVM)
• As soon as you run your program, a java virtual
machine is created which has some default size of
memory available for loading and executing classes,
objects, variables etc of a program.
• The machine loads not only your class(program) but
also other required classes and libraries which are
needed to execute the program.
• The execution of every Java program is under the
control of the JVM, it contains the program and prevent
it from generating side effects outside
Mrs. Soniya of the
Sharma system.
[email protected] Installing IntelliJ IDEA
• We will be using IntelliJ IDK
• For windows -https://www.jetbrains.com/idea/download/?section=windows
• For ubuntu - Download IntelliJ IDEA – The Leading Java and Kotlin IDE (jetbrains.com)
• For macOS - Download IntelliJ IDEA – The Leading Java and Kotlin IDE (jetbrains.com)
• However, following are few Java IDEs which can be used for writing java programs:
• IntelliJ IDEA
• Eclipse
• NetBeans
• BlueJ
• Jdeveloper
Mrs. Soniya Sharma
[email protected] Writing a simple java program
Program 1
class Simple{
public static void main(String args[]){
System.out.println(“Welcome To Lets Upgrade!!!");
}
}
Writing a simple java program
Program 2
Writing a simple java program
OUTPUT
Data Types, Variables & Operators
Think & Tell
Which type of data will be stored in this form?
Datatypes
• A data type in Java represents the size and different values that can be stored in a
variable.
Variable
• A variable is a container which holds the value while the Java program is executed. A
variable is assigned with a data type.
• Variable is a name of memory location. There are three types of variables in java: local,
instance and static.
Note: Instance &Mrs. Soniya Sharma [email protected]
Static variables will be discussed in future sprint.
Rules to Declare a Variable
• A variable name can consist of Capital letters A-Z, lowercase letters a-z digits 0-9, and two
special characters such as _ underscore and $ dollar sign.
• The first character must not be a digit.
• Blank spaces cannot be used in variable names.
• Java keywords cannot be used as variable names.
• Variable names are case-sensitive.
• There is no limit on the length of a variable name but by convention, it should be between 4
to 15 chars.
• Variable names always shouldMrs.
exist
Soniya on the
Sharma left-hand side of assignment operators.
[email protected]Rules to Declare a Variable
Initializing values to variables
Operators
Arithmetic Operators
Relational Operators
Unary Operators
Ternary/Conditional
Operator
Logical Operators
• And (&&)
• OR (||)
• Not(~)
Scanner Class
Control Flow Statements
if and if-else construct
• If Construct
Output
Predict the output
Output
If-else Construct
If-else-if Construct
Nested If-else Construct
Switch case
Loops
Types of Loops
Loops
Loops
Predict the Output
Loops
Loops
Predict the Output
Loops
Loops
Predict the Output
break and continue Statements
break and continue Statements
break and continue Statements
String
Declare and initialize a string
Immutability of Strings
String Pool
Immutability of Strings
Comparing String
Comparing String
Comparing String
Comparing String
Manipulate String
Manipulate String
Manipulate String
Manipulate String
Manipulate String
Manipulate String
String Methods
THANK YOU
➢ Ms. Soniya Sharma
[email protected] www.linkedin.com/in/soniya-p-sharma