Skip to main content

Java Basics Overview


How Java is Different from others ??

Unlike other programming language java is compiled and interpreted language. Java IDE acts as a compiler and JVM java virtual machine behave like an interpreter. i.e. when any program let say Hello saved after compiling is in Hello.java extension and after compiling this file we get Hello.Class extension file is called as class-file, byte-code or intermediate code. Byte-code is not dependent for any specific machine so it is also called as intermediate code.
To convert this byte-code into machine code or machine understandable format JVM is used which is different for different operating system. JVM is actually a kind of software used for interpreting purpose hence it is called virtual machine.


In Java Programming language, why every program is written inside class?

          As we Know Java is an Object Oriented programming language so every type of the problem is solved with the representation of the object. And as we also know that class is the template for any object. Any functionality, attribute shown by an object is included in that particular type of class. So to implement the behavior of that kind of the object, the class relating that object first have to be determined and implemented. So it is necessary to use class in any program of the java.

           In Java programming even in a same class why it is necessary to create object to access the data and function of that particular class?

Ø     In Object Oriented Programming Language when we create a class it means that we are creating a template which contains certain attributes and functionality of a certain object. To implement that class template features object has to be defined. Memory location is not assigned until you have created the object. So when you create object of that class then only the memory is allocated. And then by accessing that class functionality via object is done.

Or
Ø  We can also understand as this: when Class is declared, only template is created which contain the attribute and functionality of its respective object and to implement that template, object is obviously required. 

       Why import statement are used in Java Programs?

      As we used to include different library files while writing programs in C/C++ by using structure like #include<stdio.h> to implement the function definition like printf, scanf etc.
But as we know java is purely Object Oriented Programming Language so the particular class is imported which contains function definitions and is already built in package using the keyword import.
If we have to use Scanner to give certain input to the program then Scanner class is imported which reside inside the package java.util.Scanner.

Why System.out.println() for printing ?

For taking input from keyboard input stream is used and output stream is used for output. likewise printStream is a class implementing outputStream. System is a built-in class inside java and inside Java. lang package, PrintSream is another class defined inside System class and PrintStream class contain method definition of println. Out is a static member acts as an object of PrintStream class defined as
                Public static final PrintStream out;

So the convention System.out.println(“Arguments”);  is written.

Why Public Static void main (String args []) { /*definition*/ } ?

Public is a kind of access specifier due to which we can access it from outside the class. Since main is the function that acts as an execution point. Main function is called by the JVM which is outside the class so it must be declared as public.

Static is a kind of keyword used in java to specify that there is no need to create any instance of it. As we know main method also reside inside a class and to access the particular function of a class from outside the class (In this case from JVM), an instance of that particular class is needed, so to avoid these we simply put static to make access main method outside of class. Mostly the method which are single for each class are declared as static. Static variables and method are compile time memory.

No any return type of main method since it is the execution point of program, there is no any point on returning other type than void from main method.


      String is a pre-defined class name in java. And args [] is a variable of array types. It’s a variable name of String type object. So we can also change the name of args []. String class and its object are passed here as an argument through command line to pass information to the main method. It is String because String can accept variety of data type like int, float, char, array etc. If int was present instead of String then the error will arise when user enters floating point as an command line arguments.




Comments

Popular posts from this blog

Angular JS Warm-Up

Angular JS is not just another javascript library but an client side javascript framework developed and maintained by Google. AngularJS brings in a revolution in the field of Single Page Application (SPAs) allowing to write a propered architectured, maintainable and testable client side code. It's ability to bring in the power of MVC framework in client side programning is one of the reason it's being popular these days. As we know good software design has High Cohesion (how well does that one thing stick to do just one thing) and  Loose Coupling (least possible dependency of one component on another component)Angular JS offers MVC/MVVM paradigm to create components more flexible and loosely coupled Being an client side framework, Angular JS comprised of HTML, CSS and JavaScript/TypeScript. Angular JS was written in TypeScript because: script with type is typescript and script without type is JavaScript 😂🤣 #devQuotes — ashwin (@AshwinJung) October 22, 201...

Shahrukh khan At a Glance

Unbeaten king since twenty-two years: Shah Rukh Khan (“Naam toh suna hi hoga”) Through this article i am not emphasizing over my favorite actor. He is the legend that every-one of you must know about him. Figuratively Shahrukh khan is an actor, film producer and TV personality while speaking literally these words aren’t enough that describes khan. After reading this article anyone can figure out why i am approaching him so deeply.                                                                                               ...