Posts

Showing posts with the label java program

static method void return type primitive parameter

static method with void return type with primitive parameter: Lets describe what is the mean of static method whose return type is primitive and it has primitive parameter. void return type i.e. it does not returns any type of value and primitive parameter means it has a parameter like int, char, float etc.... static method means it can be called with class name i.e. there is no need to create the object of the class for calling this method . A program for this tutorial is given below- class Sm {  static void abc(int a,boolean b)   {     System.out.println("inside static method of abc of class Sm");   } public static void main(String args[])   {    int a=20;    boolean c=true;    Sm.abc(a,c);   } } Explanation: In this program we can also call abc() method directly without class name because within the same class we can call static method with or without class name. For Example: class Sm1 {  sta...

What is Object in java programming (object oriented programming)?

Image
Objects in Java :An object oriented programming language Definition of an Object: An object in java programming is an instance of a class. Object is the implementation of the concept given by the class. Whenever an object is created all the non static member of the class gets activated. Object in java programming is responsible for allocating memory to all non static member of the class. When object of the class is created , a context is created into heap memory area. In this heap memory all the non static member gets memory. The size of the context in heap is decided according to the members(if there are 2 integer variable in the class and 2 float variable then size of the context will be 16 bytes). Here is a demonstration of how a member gets memory in the heap memory area(HMA). Discussing back to the object, Basically object is used to access/call non static members of the class. Without creating object we are unable to use members of the class, but indirectly ...

Compilation of Java Program

Image
Compilation of Java Program Compilation of Java program is necessary before its execution. Javac is the compiler of java which compiles the source code of java program and JVM is the interpreter which generates machine code from the compiled source code. Compiling a java program we need a compiler known as JAVAC . See how to compile a java program in java programming. Compilation of a java program contains following steps- 1-Type your java program in a text editor. 2-Save it with the name of class with .java extension in your java program. 3-Now open command prompt and go to directory in which your java program has been saved. 4-Set the path of javac using set path=”path” 5-Type javac and enter file name with .java extension and press enter. 6-If your program is error free it will generate one or more .class file. 7-Type java and then file name without any extension and press enter. Now you will see output. For example if your java progr...