Wednesday, March 6, 2013

Java Basic

Java Basics 



Before we begin our discussion about basic stuff of  "Java", Let us start from the scratch, which we all know but never give so much concern.

FAQ:1 Why just 0s and 1s?

Computers use 0s and 1s because it is easy to make an electrical device that has only two stable states. However, when you are programming, you normally need not be concerned about the encoding of data as 0s
and 1s. You can program as if the computer directly stored numbers,letters, or strings of characters in memory.
There is nothing special about calling the states zero and one. We could just as well use any two names, such as A and B or true and false.

The important thing is that the underlying physical device has two stable states, such as on and off or high voltage and low voltage. Calling these two states zero and one is simply a convention, but it’s one that is almost
universally followed.

FAQ:2 A SIP OF JAVA !~!


Java n. An island of Indonesia, 48,842 square miles in area, lying between
the Indian Ocean and the Java Sea.

Java n. Informal. Brewed coffee.


Now Comes the Topic of Discussion :-

Bytecode

Before we explain Bytecode, let us take an example form Real World !~!

Stenography : The process of writing in Shorthand.

Bytecode - is a Shorthand, which converts Source code into specific Bytes of Code, which can be understand by Sun MicroSystems, now known by Oracle.















How it is Inter-operable with Different Operating System ?

It require a virtual environment which will be compatible with that ByteCode, i.e. JVM


JVM 

JVM (Java Virtual Machine) is a software which creates its own environment, that will provide a virtual environment to the Bytecode, which takes Bytecode into Memory & along with Operating System, it convert in machine code.It will also call O.S function calls.

OS vendor, just download JVM API, and it will integrate its own 20% file & make its own JVM compatible to different O.S.It makes JRE for each Operating System


The Java Virtual Machine (JVM) gives Java its platform independence. One of the primary design goals of the Java language is to enable the same code to run on any platform. The JVM is a software program that behaves like an entire computer. By using this artificial computer on different computer platforms (UNIX, Win32, Macintosh, and so forth),

You can reuse programs without creating a version for each platform. Your Java programs will always run on a JVM. A Java program can be run on any platform for which a JVM is available.



Class
class -A type of container into which all Java code must be placed. Also, the template or blueprint for an object.

class HelloWorld
{ -------- Statement  -------------}


When you write a stand-alone application, the Java Virtual Machine must know where to begin executing the code. To begin executing code, the JVM looks for and calls a special method by the name of,
public static void main(String[] args). 

The JVM uses this method to begin executing your program. 
Study the following code example:

class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello Code-Crazy Guys !~!~! ");
}
}



JRE

The Java Runtime Environment (JRE), which provides the JVM. The development tools and compilation libraries necessary to create Java applications, servlets and applets. This grouping includes the Java compiler, debugging programs, and tools to run applets without a browser.



Lab 1-1: Compiling and running your first Java program

A Java application always starts with the public static void main(String[] args) method.
1. Editor: Create a new text file and enter the following Java code:

class HelloCodeCrazy
{
public static void main(String[] args)
{
System.out.println("Hello Code Crazy Guys !~!~! ");
}
}

2. Editor: Save the file as HelloCodeCrazy.java.

Note:- you can observe one thing here, that i have written first name, as capital.
So it is a Convention, one should follow to begin there class name from capital letters.

3. Prompt: Compile HelloCodeCazy.java to generate a *.class file. From the
command line, enter the following:

javac HelloCodeCrazy.java

4. Prompt: Execute HelloCodeCazy. From the command line, enter the following:

java HelloCodeCrazy



No comments:

Post a Comment