Java Programming Language
Java is a class based, object oriented programming langue.
Java can be use for: software development, web application development , big data , Android apps.
Java code was designed to run on all plat forms. It was developed with the purpose to give programmers the ability to write once, run anywhere (WORA).
Java environment is made up of three components: JDK, JRE, JVM
JDK
java development kit (jdk) used for software development. Includes the tools Java compiler, Javadoc, Jar, and debugger.
A Java Debugger (jdb) is a software used by programmers to find errors within programs. When a program crashes, the jdb finds the specific line of code that caused the crash.
JRE
Java Run-time Environment (jre) is required to run Java programs. Contains Java libraries.
JVM
Java virtual machine (jvm) allows the computer to run but Java programs. Jvm follow an instruction set called byecode.
Basic Syntax
- Java is Case Sensitive. java and Java are two separate identifiers.
- Method names must start with Lowercase letter.
- Class names should start with Capital letter.
- File names must match the class name
- All Java programs start from main() method. public static void main(String[] args)
Objects
entities ; have state, behaviors and identities
state – descries the object
behaviors – how an object acts, interacts with other objects
identity – unique name given to object
Java Class
blueprint of user created objects. Describes the behaviors of the objects with in it.
Method
statements that execute specific tasks. Methods only run when they are called.
Instant Variables
objects contain a unique set of instant variables. Object’s state is composed of instant variables.
Java Variables
Java Variables are user created containers that hold a value.
Three types of variables:
- local variables
- instance variables
- static variables
Local Variables
are variables that are with in the body of a method (block of code).
public class exLocalVar
{
public static void main(String[] args)
{
String exString; // Creating String
exString = "www.codeit.blog";
System.out.println(exString); //Print Out String
}
}
Instance Variables
are declared outside of the method but are still with in the class. Instance variables can be used by all methods and constructors but they have to be within the same java class. Instance variables are created by using the keyword new when creating and object.
public class Purchase{
public void TotalExpenses()
{
int amount= 25;
String item= "Gas";
System.out.println("Purchase Amount: " + amount);
System.out.println("Item Name: " + item);
}
public static void main(String args[])
{
Purchase receipt = new Purchase();
receipt.TotalExpenses();
}
}
Static Variables
is a class level variable.It is a common property within all the objects in a class. Using static variables are good for memory management because these variables are only stored once. Static variables help save memory because they are loaded once, with the class.
class Example{
static String mString;
static{
mString= "www.codeit.blog";
}
public static void main(String args[])
{
System.out.println("More tutorials @ "+mString);
}
}