Posts

Java OOP

               OOP sands for Object-Oriented Programming    Procedural Programming -: Writing procedures or methods that performs operations on data. Object-Oriented Programming -: Creating objects that contains both data & methods Advantages of object-oriented programming over procedural programming -: faster & easier to execute provide the clear structure for the programs keep DRY "Don't repeat yourself" principle, and makes the code easier to maintain, modify & debug. possible to create less reusable application with less code & shorter development time   Classes & Objects  Classes and objects are the two main aspects of object-oriented programming.  Look following examples to get idea about classes & objects -: ex 1-: class - fruit objects -: Apple, Banana, Mango ex2-: class-: Animal objects -: Dog, Cat, Monkey class is a template for object. object is an instance of a class. When the indiv...

Java Variables

 Variables are containers for storing data values. In Java, there are different types of variable. String - stores text. String values are surrounded by double quotes int - stores integers (whole numbers), without decimals float - stores floating point numbers, with decimals, such as 9.99 or -1.99 char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes boolean - stores values with two states(true or false)   Variable Declaration  Syntax -: type  name_of_variable = value;      type -:  String/ int/ float/ char/ boolean      name_of_variable -: such as x,x1,y      equal sign used to assign values to the variable.            ex -: String name= "mala"                    int age=24;                    float decnum=5.99f; ...

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...