Posts

Showing posts from July, 2020

Java Constructors

Image
           Constructor is a block of codes similar to the method. It is called when an instance of the class is created.  constructor must  declare name same as class name , constructor hasn't return type ex -: when you creating object from java class, the constructor in that class runs automatically. ex-: -------------------------------------Box.java------------------------------------------------------------- -------------------------------Demo.java------------------------------------------------------------------------- Output -: Case 1-: Constructor can't run as another methods. it automatically runs when creating an object ex -: //gives compile error Case 2-:     we can create a method its name same as class name & has return type.  It is not a constructor. its run same as another method. ex-: -----------------------------------------Box.java--------------------------------------------------------------- -------------------...

Basics of Java variables, methods , class & object

  Variable -:  A piece of memory that can contain a data value. Variable Types -: Local Variable -: variable that define & initialized inside a method (variable will be destroyed when the method has completed) Instance Variable (Global Variable) -: variable within a class but outside any method.                         (Initialized when the class is instantiated, can be accessed from inside any method, constructor or block of that particular class)  Class Variable -: Variable declared within a class, outside any method with the static key word. Attribute = Property =Global Variable "Global variable can define with access modifier. But local variable not allow to define with access modifier" Object -: A unit that store variables & methods (to create a software) Object have states & behaviors ex-: Dog has, state -: color, name behavior -: barking, eating Class -: Class can be define as a template/b...

Step 2 -: Java Comments

Image
 The purpose of including comments in your code is to explain what the code is doing. Type of Java Comments -: Line Comment Block Comment Document Comment Line Comment        A single-line comment starts with two forward slashes and continues until it reaches the end of the line. ex -: output -: Block Comment   (Multi-Line Comment) Java also supports comments that span multiple lines. You start this type of comment with a forward slash followed by an asterisk, and end it with an asterisk followed by a forward slash. ex-: output -: Java does not support nested multi-line comments. However, you can nest single-line comments within multi-line comments. ex-: /* This is a single-line comment:     // a single-line comment  */ Document Comment Documentation comments are special comments that have the appearance of multi-line comments, with the difference being that they generate external documentation of your source code. These begin with a for...

Create your first Java program

Image
 INTRODUCTION  More than 3 billion devices run Java. Java is used to develop apps for Google's Android OS, various Desktop Applications, such as media players, antivirus programs, Web Applications, Enterprise Applications (i.e. banking), and many more! "Java Programs are platform independent. Because when the Java program runs in a particular machine it is sent to java compiler, which converts this code into intermediate code called bytecode. This bytecode is sent to Java virtual machine (JVM) which resides in the RAM of any operating system. JVM recognizes the platform it is on and converts the bytecodes into native machine code. Hence java is called platform independent language." WRITE YOUR FIRST JAVA PROGRAM     you can use any Java development kit to run your java program (ex-: Geany, eclipse or any other) In Java, each application has an entry point, or a starting point, which is a method called main. Along with main, the keywords public and static will also be...