Java-Part 2

Java 2-Part 1   Index   Java 2-Part 3

* 2 Paradigms

  1. Process Oriented model => Code acting on data
  2. Object Oriented Programming => Data controlling access to code. In this we can achieve several organizational benefits.

*The 3 OOP Principals =>

  1. Encapsulation=> encapsulation is the mechanism that binds together code & the data, it manipulates & keeps both safe from outside interference and misuse. In java basis of encapsulation is a class. A class will define structure & behavior that will be shared by the objects. Objects also contains the same structure & behavior as that of class. For this reason, objects are sometimes referred as the instances of the classes. Thus class is logical construct & object has the physical entity. The data will be called as the member variable or instance variable. The code operate on that data is referred as the member methods or just methods. We have access specifiers like public, private, public methods & variables are accessed by any methods, but private will be accessed by only the native class methods.
  2. Inheritance => Inheritance is the process by which one object acquires the properties of another object. Inheritance interacts with encapsulation as well.
  3. Polymorphism =>Polymorphism is a feature that allows one interface to be used for general class of actions. The specific action is determined by the exact nature of the situation. Its a compiler job to select the specific action as it applies to each situation. You need only remember & utilize the general interface.

*Entering The Program =>The source file(.java) is officially called a compilation unit. The java compiler requires that a source file & it has .java file name extension.

*Compilation => To execute java compiler use use “javac” (ex: c:\javac Test.java).

*The java compiler will create the file called(Test.class) that contains the byte code version of the program. This byte code will be executed by the java interpreter.(ex:c:\Test). The java compiler searches for the “.class” file name & executes it.

*Java supports 3 types of comments.

=>1. //(single line comment)

=>2. /*

*/(multi line comment)

=>3. /**

*/(documentation comment, compiler will ignore the comments)

*class Example=> class  keyword is used to declare a new class & Example is the identifier of that class.

*public static void main(String args[])=>The main method is always public because it is accessed from the outside class. It is void because it returns nothing. Its static because it is instantiated before any object is initialized since it is called by the java interpreter before the objects are made.

*Compiler will compile the classes that don’t have the main method. But Interpreter has no way to run the java classes, so java interpreter should have to find main() method to execute. Compiler will compile the java program it its is main/Main.

*Strings args[] =>args will receive command line argument.

*Identifier =>It may be descriptive sequence of lowercase/uppercase letters/numbers/underscore(_) & $(symbol). It must not start with number.

JavaClassLoading
Java 2-Part 1   Index   Java 2-Part 3

2 thoughts on “Java-Part 2

Leave a comment