Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Data Types and variables in Java

datatypes

Data Types

  • The term data type refers to the type of data that can be stored in a variable.
  • Sometimes,java is called a "strongly typed language"because when you declare a variable,you must specify the variable's type.
  • Then the compiler  ensures that you don't try to assign data of the wrong type to the variable. 

Variables

Variable is name of reserved area allocated in memory
There are 3 types of  variables in Java
  1. Local variable
  2. Static variable
  3. Instance Variable.
Local Variable
A variable that is declared inside the method is called local variable.

Static Variable
A variable that is declared as static is called static variable. It cannot be local.


Instance Variable
A variable that is declared inside the class but outside the method is called instance variable.
It is not declared as Static.

Basics of Java


Syntax of Java

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 java.

Class Name

For all class names the first letter should be in Upper Case.
I. If several words are used to form a name of the class ,each inner word's first letter should be in Upper case.
II. Example class MyFirstJavaClass

Method Name

All method names should start with a Lower case letter.
I. If several words are used to form the name of the method,then each inner word's first letter should in Upper case.
II.Example public void myMethodName()

Program File Name

Name of the program file should exatly match the class nae.
I. When saving the file,youshould save it using the class name and append'.Java'to the end of the name.
II. Example : Assume 'MyFirstJavaProgram'is the class name. Then the file should be saved as "MyFirstJavaProgram.java"

public static void main(String args[])

Java program processing starts from the main() method which is a mandatory part of every Java program.

Comments in Java

The java language supports three types of comments
/*text*/ the compiler ignores everything from?8 to */ /**documentation**/ This indicates a documentation comment.comment. The compiler ignores this kind of comment, just like it ignores comments that use /*and*/.The JDK java doc tool uses doc comments when preparing automatically generated documentation. //text The compiler ignores everything from // to the end of the line.

Reserved keywords in Java

Keywords are special tokens in the language which have reserved use in the language. Keywords may not be used as identifier in Java. You cannot declare a field whose name is a keyword ,for instance

Explain about JDK , JVM in Java

  jdk in java ,JRE and JVM

JRE:  Java Run time Environment ,It is used to provide run time environment. It is the implementation of JVM. It physically exists. It contains of set of libraries + other files.
JDK:  Java Development Kit it physically exists. It contains JRE+ development tools.

JVM :  Java virtual Machine it is a specification that provides run time environment.

JVM Performs the Loads code,Verifies Code,Executes Code.

Internal Architecutre of JVM
  1. Class Loader: class loader loads the class files.
  2. Class(Method) Area: This stores per class structures such as the run time constant pool field and method data the code for methods.
  3. Heap:It is the run time data area in which objects are allocated.
  4. Stack: Java Stack stores frames.It holds local variables and partial results.
  5. Program Counter Register(PC):It contains the address of the Java Virtual Machine instruction currently being executed.
  6. Native Method Stack:It contains the all the native methods.
  7. Execution Engine:  It contains  Virtual Processor, Interpreter,Just In Time Compiler(JIT)



Java Introduction

What is a Java
learn java


Java is a programming language. Java is a High level, robust secured and Object-Oriented Language

Platform: Any hardware or software environment which a program runs is known as platform.

Java has a programming language

  • The java programming language is a high-level,object-oriented and general purpose computer programming language.
  • You can use java to write computer applications that play games,store data or do any of the thousands of other things computer software can do.

Where is java used
There are many devices where java is currently used. some of them are as follows.

  1. Desktop applications such as acrobat reader,media player,antivirus etc.
  2. Mobile.
  3. Embedded System.
  4. Enterprise Applications such as banking Applications.
  5. Web Applications such as irctc.co.in.
  6. Smart Card.
  7. Robotics.
  8. Games etc.
Types of Java Applications
By using java mainly we create 4 types of applications.
  1. Standalone Application : It is also know as window based or Desktop Applications .An application that we need to install on every machine such as media player,antivirus,etc.
  2. Web Application:An Application that runs on server side and creates a dynamic page that is Web Applications.
  3. Enterprise Application:An Application that is distributed in nature is know as Enterprise Applications such as Banking.
  4. Mobile Application:An application that is created for mobile devices.
History Of Java

Java was developed by Sun Micro systems in theearly to mid 1990 and development continues to this day.

1990: A team headed by James Gosling i set up to work on a programming language for consumer electronic devices.
1992: The team creates a project called star7(*7) and personal, hand-held remote control. The development team s incorporated as a First person,inc.
1994:the team notices the popularity of the web which came along in 1993 and builds first web-enabled browser.
1995: May 23 At sun world in san Francisco Sun Micro Systems,inc. formally announces Java 1.0 and Netscape also announces   it will license Java for its browser. 

Java Version History

  1. JDK Alpha and Beta(1995)
  2. JDK 1.0(23 rd Jan 1996)
  3. JDK1.1(19 th Feb 1997)
  4. J2SE1.2(8 th Dec 1998)
  5. J2SE 1.3 (8th May 2000)
  6. J2SE1.4 (6 th Feb 2002)
  7. J2SE 5.0(30 th sep 2004)
  8. JAVA SE6(11 th Dec 2006)
  9. JAVA SE7(28 th July 2011)
  10. JAVA SE8(18 th March 2014)

Features of Java Programming Language


Simple
  • Java is Easy to write and more readable and eye catching.
  • Java has a concise,cohesive set of features that makes it easy to learn and use.
  • Most of the concepts are drew from c++ thus making java learning simpler.
Secure:
  • Java provides secure way to access the web applications.
  • java provides a secure means of creating internet applications.
Portable:
  • Java program can execute in any environment for which there is a java run time system(JVM)
  • Java program runs any platform
  • Java programs can be transferred  over world wide web(e.g. applet).
Object-Oriented:
  • Java program is Object-oriented programming language.
  • Java is pure OOP. Language.
Robust:
  • Java encourages error-free programming by being strictly typed and performing run-time checks.
Multi threaded:
  • Java provides integrated support for multi thread programming.
High Performance:
  • Byte codes are highly optimized. JVM can executed them much faster.
Dynamic:
  • Java programs carry with them substantial amounts of run time information that is used to verify and resolve access to objects at run time.