tag:blogger.com,1999:blog-834289431694678932024-03-13T13:26:47.223-07:00Java - Free Learning TutorialsLearn Java basics in a simple wayVidhyadhar Birnalehttp://www.blogger.com/profile/12646601670900095814noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-83428943169467893.post-88673813085932257512010-10-27T02:21:00.001-07:002010-10-27T02:21:46.981-07:00Introduction Java is related to C++, which is a direct descendent of C. From C, java derives its syntax.<br />
Many of java’s object oriented features were influenced by C++.<br />
Java was conceived by James Gosling, Patrick Naughton, Ed Frank, and Mike Sheridan at<br />
Sun Microsystems, Inc. in 1991. This language was initially called “Oak”, but was renamed<br />
to “Java” in 1995.<br />
The primary motivation behind development of Java was the need for a platformindependent<br />
language that could be used to create software to be embedded in various<br />
consumer electronic devices, such as microwave ovens and remote controls.<br />
The output of Java compiler is not executable code. Rather, it is bytecode. Bytecode is a<br />
highly optimized set of instructions designed to be executed by the Java run-time system,<br />
which is called Java Virtual Machine (JVM). The JVM is an interpreter for bytecode.<br />
HotSpot technology of Sun provides a Just-In-Time (JIT) compiler for bytecode. When a JIT<br />
compiler is part of JVM, selected portions of bytecode are compiled into executable code in<br />
real time.<br />
Java features : i) Simple ii) Secure iii) Portable iv) Object-oriented v) Robust<br />
vi) Multithreaded vii) Architectura-neutral viii) Interpreted<br />
ix) High performance x) Distributed xi) Dynamic<br />
Object Oriented Programming organizes a program around its data (i.e., objects). An object<br />
oriented program can be characterized as data controlling access to code.<br />
Object - An object is a real world entity or real world thing, which one knows how to use it<br />
but unaware of its internal structure or the way it works.<br />
Abstraction – An abstraction is a lack of knowledge. An Object Oriented Programming<br />
language advises the programmer to maintain an abstraction between user & application to<br />
keep away the complexity of an application from user. A powerful way to manage the<br />
abstraction is through the use of hierarchical classifications.<br />
Three Object Oriented Programming Principles<br />
Encapsulation – Encapsulation is the mechanism that binds together code and data it<br />
manipulates, and keeps both safe from outside interference and misuse. In java, the basis<br />
of encapsulation is the class. Each method or variable in a class may be marked private<br />
or public. The public interface of a class represents everything that external users of the<br />
class need to know, or may know. The private methods and data can only be accessed<br />
by code that is a member of a class.<br />
Interference – Interference is the process by which object acquires the properties of<br />
another object. A new subclass inherits all of the attributes of all of its ancestors.<br />
Polymorphism – Polymorphism is a feature that allows one interface to be used for a<br />
general class of actions. The concept of polymorphism is often expressed by the phrase<br />
“one interface, multiple methods.”<br />
As compared to VB, which is object based language, Java is class based language with more<br />
than 15 thousand classes & above 2 lack methods.<br />
Java uses both compiler & interpreter to execute a program.<br />
In case of a program, containing multiple classes, one can assign any name to a program,<br />
but can execute the program using the class name which has ‘main’ method. A ‘.class’ file is<br />
created for each class in a program.<br />
Java doesn’t recognize ‘boolean’ data type as ‘int’. It stores ‘true’ & ‘false’ literals.<br />
A first simple program : Displaying messages on console.<br />
1. class Example {<br />
2. public static void main(String args[]) {<br />
3. System.out.println(“Hello! Vishal Birnale”);<br />
4. }<br />
5. }<br />
The 1 s t line uses the keyword class to declare that a new class is being defined.<br />
The 2 nd line of code uses:<br />
‘ public’ keyword – it is an access specifier, which allows the programmer to control the<br />
visibility of class members. public member may be accessed by code outside the class in<br />
which it is declared.<br />
‘ static’ keyword – it allows main() to be called without having to instantiate particular<br />
instance of the class.<br />
‘ void’ keyword – it simply tells the compiler that the main() doesn’t return a value.<br />
The 3 rd line contains System class, which is a predefined class that provides access to system,<br />
and out is the output stream that is connected to the console.<br />
println() displays the string which is passed to it.<br />
Block of code ({ . . . })<br />
Coding is done in blocks. A variable declared in a block is local to that block & is<br />
accessible anywhere within the same block; it can’t be accessed in any other block.<br />
In case of nesting of blocks, the variable of outer block can be accessed in inner block but<br />
not vice versa.Vidhyadhar Birnalehttp://www.blogger.com/profile/12646601670900095814noreply@blogger.com0tag:blogger.com,1999:blog-83428943169467893.post-56557264787517315392010-10-26T22:38:00.001-07:002010-10-26T22:40:44.765-07:00<a href="http://java.com/inc/BrowserRedirect1.jsp?locale=en&host=java.com">download</a>Vidhyadhar Birnalehttp://www.blogger.com/profile/12646601670900095814noreply@blogger.com0