Thursday, November 5, 2015

Getting Ready for Technical Interviews - 1

After long time I get chance to continue writing my blog. I thought include some basic java concepts and more technical concepts with this post. There is no any order of concepts. I just put things that I have focused when I was getting ready for interviews.

Ok lets start. 

JDK - Java Development Kit

A bundle of software with tools needed to develop java program such as compiler (javac.exe), java app launcher (java.exe) etc. This is mainly targeted for java development, compile a java file and run a java file. So it is clear even it providing facilities for development purpose, it includes execution environment also. 

JRE - Java Runtime Environment

This can be known as the implementation of java virtual machine which actually executes java programs. Therefore it is mainly targeted for execution of java files. 

JRE = JVM + Java Packages (util,lang etc) + Run time Libraries 

JVM - Java Virtual Machine


An implementation of the Java Virtual Machine Specification, interprets compiled Java binary code (called bytecode) for a computer's processor ( or "hardware platform") so that it perform a Java program's intructions. Java was designed to allow application programs to be built that could be run on any platform without having to be rewritten or recompiled by the programmer for each separate platform. A JVM makes this possible because it is aware of specific instruction lengths and other particularities of the platform.


Execution of a java program. Java is a both compiled and interpreted language.


Next


OOP With Java-Part 2

                                                    Access Modifiers
      There are three main access modifiers available in java.

  1. Private
  2. Protected
  3. Public                
    Other than these three access modifiers there is one more access level called default access level, which does not include any access modifier. Class can be modified only with public modifier or use default access level. (Private and protected not allowed) .If class A need to access members(variables or methods) in class B, class B must be accessible from class A.

                                          Private Access Modifier
  • Private access modifier restricts the accessibility to the class level.
  • It can be applied to member variables and methods.(both static and instance)
  • Constructors can be modified with private.
  • Classes can NOT be applied with private.
  • Method local variables can NOT be modified with private.
                void m(private int x){} //CE
  • Private variables and methods do NOT inherit to sub classes.
                                     Protected Access Modifier
  • Protected modifier is visible to all the class in the same package and to the sub classes outside the package.(Package+Kids)
  • Can be applied to variables(static/instance) and methods (static/instance)
  • Constructors can be modified with protected.
  • Can NOT be applied to top level classes.
  • Can NOT be applied to method local variables.
  • Accessing a protected member in a different package can be done only through inheritance.

     Other modifier applicable for class other than access modifier.
  1. abstract
  2. final
  3. strictfp
                                  Abstract classes and methods
  • "abstract" class can NOT instantiate (can not create objects out of abstract classes)
  • Only classes and methods can be marked as abstract.
  • "abstract" methods do not have a body.
                   public abstract void m(int x);
  • If a class has one or more abstract methods that class MUST be abstract.
  • "abstract" class can have both abstract and non abstract methods.
  • Even without a single abstract method, class can be marked as abstract.
                               abstract class A
                                {
                                          void m(){}
                                }
  • When an abstract method inherited down we must OVERRIDE  the abstract method in the first concrete (non abstract) subclass. If not CE(Compile Error).

Show Part 1



Thursday, September 26, 2013

OOP with Java - Part 1


         Welcome to Object Oriented                                               Programming

                          JDK(Java Development Kid)

      The "JDK" is the Java Development Kit. I.e., the JDK is bundle of software that you can use to develop Java based software. The "JRE" is the Java Runtime Environment. I.e., the JRE is an 
implementation of the Java Virtual Machine which actually executes Java programs.Java Development Kit contains tools needed to develop the Java programs, and JRE to run the programs. The tools include compiler (javac.exe), Java application launcher (java.exe), Appletviewer, etc...

    JRE = JVM + Java Packages Classes(like util, math, lang,                                                         awt,swing etc)+runtime libraries.

                             JRE (Java Runtime Environment)

            Java Runtime Environment contains JVM, class libraries, and other supporting files. It does not contain any development tools such as compiler, debugger, etc. Actually JVM runs the program, and it uses the class libraries, and other supporting files provided in JRE. If you want to run any java program, you need to have JRE installed in the system.  
         The Java Virtual Machine provides a platform-independent way of executing code; programmers can concentrate on writing software, without having to be concerned with how or where it will run. 

                         JVM(Java Virtual Machine)

          The JVM is called "virtual" because it provides a machine interface that does not depend on the underlying operating system and machine hardware architecture. This independence from 
hardware and operating system is a cornerstone of the write-once run-anywhere value of Java programs. JVM is platform dependent.

            Java compiler generates Java byte code. Byte code is easy (and fast) to interpret, like machine language, but it is also portable, like a high-level language. Thus, it is possible to compile a Java 
program on one machine, transfer the byte code to another machine over a network, and then interpret the byte code on the other machine. This ability is one of the advantages of Java over many other high-level languages.

          java is a high level programming language. Computer doesn't understand our languages. It can understand only 0 and 1.There are three steps to create a java program.

  1. Writing the code
  2. Compiling the code 
  3. Running the code

  • How to run a "Hello World" program.....?
      1. Writing the code  
          
        Usually,we use notepad for this task.

                                         class Test{
                                                public static void main(String arg[]){
                                                    System.out.println("Hello World");
                                               }
                                          }


        First we have to type above code in notepad and save it
     C:\java -----> Test.java

      2. Compiling the code

         Then type we have to give compile and run command in command prompt. So to before give command we have to navigate the place we saved the text file(source file).
        To compile ----->  javac Test.java  (then press Enter) 
After compile source file, we can call it as "Class file".

       3. Running the code

          We run the byte code -------> java Test (then press Enter)

           
                      Declarations & Access Control
       
   An identifier can only be started with a letter, _(underscore) or $(dollar sign).Classes,interfaces,variables and method names should be "camelCase". classes and  interfaces usually start with a capital letter.





Next Post