Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Java Basic Concept
Where it is used?
1. Desktop Applications such as acrobat reader, media player, antivirus etc.
2. Web Applications such as irctc.co.in, javatpoint.com etc.
3. Enterprise Applications such as banking applications.
4. Mobile
5. Embedded System
6. Smart Card
7. Robotics
8. Games etc.
Features of Java
1. Simple
2. Object-Oriented
3. Platform independent
4. Secured
5. Robust
6. Architecture neutral
7. Portable
8. Dynamic
9. Interpreted
10. High Performance
11. Multithreaded
12. Distributed
Object-oriented
Object-oriented programming(OOPs) is a methodology that simplify software development and
maintenance by providing some rules.
Basic concepts of OOPs are:
1. Object
2. Class
3. Inheritance
4. Polymorphism
5. Abstraction
6. Encapsulation
Platform Independent
Java code can be run on multiple platforms e.g.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).
Understanding first java program
Let's see what is the meaning of class, public, static, void, main, String[], System.out.println().
 class keyword is used to declare a class in java.
 public keyword is an access modifier which represents visibility, it means it is visible to
all.
 static is a keyword, if we declare any method as static, it is known as static method. The
core advantage of static method is that there is no need to create object to invoke the
static method. The main method is executed by the JVM, so it doesn't require to create
object to invoke the main method. So it saves memory.
 void is the return type of the method, it means it doesn't return any value.
 main represents startup of the program.
 String[] args is used for command line argument. We will learn it later.
 System.out.println() is used print statement. We will learn about the internal working of
System.out.println statement later.
Valid java main method signature:
1. public static void main(String[] args)
2. public static void main(String []args)
3. public static void main(String args[])
4. public static void main(String... args)
5. static public void main(String[] args)
6. public static final void main(String[] args)
7. final public static void main(String[] args)
8. final strictfp public static void main(String[] args)
Types of Variable
There are three types of variables in java
 local variable
 instance variable
 static variable
Local Variable
A variable that is declared inside the method is called local variable.
Instance Variable
A variable that is declared inside the class but outside the method is called instance variable . It is not
declared as static.
Static variable
A variable that is declared as static is called static variable. It cannot be local.
We will have detailed learning of these variables in next chapters.
In java, there are two types of data types
 primitive data types
 non-primitive data types
Data Types in Java
Data Type Default Value Default size
boolean false 1 bit
char 'u0000' 2 byte
byte 0 1 byte
short 0 2 byte
int 0 4 byte
long 0L 8 byte
float 0.0f 4 byte
double 0.0d 8 byte
Java basic concept
Operators in java
Operator in java is a symbol that is used to perform operations. There are many types of
operators in java such as unary operator, arithmetic operator, relational operator, shift operator,
bitwise operator, ternary operator and assignment operator.
Operators Precedence
Postfix expr++ expr--
unary
++expr --expr +expr -
expr ~ !
multiplicative * / %
additive + -
shift << >> >>>
relational < > <= >= instanceof
equality == !=
bitwise AND &
bitwise exclusive OR ^
bitwise inclusive OR |
logical AND &&
logical OR ||
ternary ? :
assignment
= += -= *= /= %= &= ^=
|= <<= >>= >>>=
Advantage of naming conventions in java
By using standard Java naming conventions, you make your code easier to read for yourself and
for other programmers. Readability of Java program is very important. It indicates that less time
is spent to figure out what the code does.
Name Convention
class name
should start with uppercase letter and be a noun e.g. String, Color, Button,
System, Thread etc.
interface
name
should start with uppercase letter and be an adjective e.g. Runnable, Remote,
ActionListener etc.
method name
should start with lowercase letter and be a verb e.g. actionPerformed(), main(),
print(), println() etc.
variable name should start with lowercase letter e.g. firstName, orderNumber etc.
package
name
should be in lowercase letter e.g. java, lang, sql, util etc.
constants should be in uppercase letter. e.g. RED, YELLOW, MAX_PRIORITY etc.
name
CamelCase in java naming conventions
Java follows camelcase syntax for naming the class, interface, method and variable.
If name is combined with two words, second word will start with uppercase letter always e.g.
actionPerformed(), firstName, ActionEvent, ActionListener etc.
Class in Java
A class is a group of objects that has common properties. It is a template or blueprint from which objects
are created.
A class in java can contain:
 data member
 method
 constructor
 block
 class and interface
Constructor in Java
1. Types of constructors
1. Default Constructor
2. Parameterized Constructor
2. Constructor Overloading
3. Does constructor return any value
4. Copying the values of one object into another
5. Does constructor perform other task instead initialization
Constructor in java is a special type of method that is used to initialize the object.
Java constructor is invoked at the time of object creation. It constructs the values i.e. provides
data for the object that is why it is known as constructor.
Rules for creating java constructor
There are basically two rules defined for the constructor.
1. Constructor name must be same as its class name
2. Constructor must have no explicit return type
Types of java constructors
There are two types of constructors:
1. Default constructor (no-arg constructor)
2. Parameterized constructor
Java Keyword:
Md.Delwar Hossain
Android Apps Developer
Trainer & Lecturer at Open IT,Dhaka
1283, Begum Rokeya Sarani, Mirpur-10
(Opposite of Al-Helal Hospital)

More Related Content

Java basic concept

  • 1. Java Basic Concept Where it is used? 1. Desktop Applications such as acrobat reader, media player, antivirus etc. 2. Web Applications such as irctc.co.in, javatpoint.com etc. 3. Enterprise Applications such as banking applications. 4. Mobile 5. Embedded System 6. Smart Card 7. Robotics 8. Games etc. Features of Java 1. Simple 2. Object-Oriented 3. Platform independent 4. Secured 5. Robust 6. Architecture neutral 7. Portable 8. Dynamic 9. Interpreted 10. High Performance 11. Multithreaded 12. Distributed Object-oriented Object-oriented programming(OOPs) is a methodology that simplify software development and maintenance by providing some rules. Basic concepts of OOPs are: 1. Object 2. Class 3. Inheritance 4. Polymorphism 5. Abstraction 6. Encapsulation
  • 2. Platform Independent Java code can be run on multiple platforms e.g.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). Understanding first java program Let's see what is the meaning of class, public, static, void, main, String[], System.out.println().  class keyword is used to declare a class in java.  public keyword is an access modifier which represents visibility, it means it is visible to all.  static is a keyword, if we declare any method as static, it is known as static method. The core advantage of static method is that there is no need to create object to invoke the static method. The main method is executed by the JVM, so it doesn't require to create object to invoke the main method. So it saves memory.  void is the return type of the method, it means it doesn't return any value.  main represents startup of the program.  String[] args is used for command line argument. We will learn it later.  System.out.println() is used print statement. We will learn about the internal working of System.out.println statement later. Valid java main method signature: 1. public static void main(String[] args) 2. public static void main(String []args) 3. public static void main(String args[]) 4. public static void main(String... args) 5. static public void main(String[] args) 6. public static final void main(String[] args)
  • 3. 7. final public static void main(String[] args) 8. final strictfp public static void main(String[] args) Types of Variable There are three types of variables in java  local variable  instance variable  static variable Local Variable A variable that is declared inside the method is called local variable. Instance Variable A variable that is declared inside the class but outside the method is called instance variable . It is not declared as static. Static variable A variable that is declared as static is called static variable. It cannot be local. We will have detailed learning of these variables in next chapters. In java, there are two types of data types  primitive data types  non-primitive data types Data Types in Java Data Type Default Value Default size boolean false 1 bit char 'u0000' 2 byte byte 0 1 byte short 0 2 byte int 0 4 byte long 0L 8 byte float 0.0f 4 byte double 0.0d 8 byte
  • 5. Operators in java Operator in java is a symbol that is used to perform operations. There are many types of operators in java such as unary operator, arithmetic operator, relational operator, shift operator, bitwise operator, ternary operator and assignment operator. Operators Precedence Postfix expr++ expr-- unary ++expr --expr +expr - expr ~ ! multiplicative * / % additive + - shift << >> >>> relational < > <= >= instanceof equality == != bitwise AND & bitwise exclusive OR ^ bitwise inclusive OR | logical AND && logical OR || ternary ? : assignment = += -= *= /= %= &= ^= |= <<= >>= >>>= Advantage of naming conventions in java By using standard Java naming conventions, you make your code easier to read for yourself and for other programmers. Readability of Java program is very important. It indicates that less time is spent to figure out what the code does. Name Convention class name should start with uppercase letter and be a noun e.g. String, Color, Button, System, Thread etc. interface name should start with uppercase letter and be an adjective e.g. Runnable, Remote, ActionListener etc. method name should start with lowercase letter and be a verb e.g. actionPerformed(), main(), print(), println() etc. variable name should start with lowercase letter e.g. firstName, orderNumber etc. package name should be in lowercase letter e.g. java, lang, sql, util etc. constants should be in uppercase letter. e.g. RED, YELLOW, MAX_PRIORITY etc.
  • 6. name CamelCase in java naming conventions Java follows camelcase syntax for naming the class, interface, method and variable. If name is combined with two words, second word will start with uppercase letter always e.g. actionPerformed(), firstName, ActionEvent, ActionListener etc. Class in Java A class is a group of objects that has common properties. It is a template or blueprint from which objects are created. A class in java can contain:  data member  method  constructor  block  class and interface Constructor in Java 1. Types of constructors 1. Default Constructor 2. Parameterized Constructor 2. Constructor Overloading 3. Does constructor return any value 4. Copying the values of one object into another 5. Does constructor perform other task instead initialization Constructor in java is a special type of method that is used to initialize the object. Java constructor is invoked at the time of object creation. It constructs the values i.e. provides data for the object that is why it is known as constructor. Rules for creating java constructor There are basically two rules defined for the constructor. 1. Constructor name must be same as its class name 2. Constructor must have no explicit return type
  • 7. Types of java constructors There are two types of constructors: 1. Default constructor (no-arg constructor) 2. Parameterized constructor Java Keyword: Md.Delwar Hossain Android Apps Developer Trainer & Lecturer at Open IT,Dhaka 1283, Begum Rokeya Sarani, Mirpur-10 (Opposite of Al-Helal Hospital)