Introduction to java | History of java Introduction | Features of java | Fundamentals of java | Data types | Operators in java | Conditional statements | Access modifiers

CONTENTS

 

List of topics that we cover in the article:

  • History of java
  • Introduction
  • Features of java
  • Fundamentals of java
  • Data types
  • Operators in java
  • Conditional statements
  • Access modifiers          
  • INTRODUCTION TO JAVA
  • History of java:
    • Java was developed at SUN MICROSYSTEMS by JAMES GOSLINGS & his team.
    • The trail version was developed and released in the year 1990 was named as “OAK” which was later named as java and it took 18 months.
    • The software OAK initially solved some of the problems of the industry and yet there were problems not solved. In other words OAK software did not completely solve the problems in the industry. Hence the software OAK was revised sunMicroSystems and in the year 1995 it was released to the industry with the name “JAVA”.
  • Introduction:
    • There are three categories of java namely:
      • J2SE
      • J2EE
      • J2ME
  • J2SE: It is used by the industry for the development of standalone applications.
  • J2EE: It is used for developing the server-side application to exchange the data between J2SE and J2EE applications. Here we use a protocol called HTTP.
  • J2ME: It is used for developing mobile/wireless application, by using a protocol called WAP (wireless access protocol).
  • Features of java:
  • Features of any programming language is nothing but the services or basic facilities provided by the language to the programmers. The java language provides the following features.

  • Simple
  • Distributed
  • Portable
  • secured
  • High performance
  • Object Oriented
  •  

  • Simple:
  • Java is a simple programming language. Because all the difficult concepts of C and C++ have been omitted in java. For example, the concept of pointers- which is vey difficult for both learners and programmers has been completely eliminated in java.further, java

    soft people maintained the same syntax of C and C++ in java, so that a programmer who knows C or C++will find java familiar.

  • Distributed:
  • Information is distributed on various computers in a network. Using java, we can write programs, which capture information and distribute it to the client. This is possible with java because, java can handle the protocols like TCP/IP and UDP.

  • Portability:
  • if a program yields the same result on every machine, then that program is called portable.java programs are portable. This is result of the java’s system independence nature.

  • Secured:
  • Security problems like eaves dropping, tampering, impersonation, and virus threats can be eliminated or minimized by using java on internet.

  • High performance:
  • The problems with the interpreter inside the JVM is that it is slow. Because of this, java programs run slow. To overcome this problem, along with the interpreter, javasoft people has introduced JIT compiler, which enhances the speed of execution. So, now in JVM, both interpreter and JIT compiler works together to run the program.

  • Object Oriented:
  • if any programming language is called object-oriented then it must represent the data in the form of objects. Java is called as a object oriented programming because java represents data in the form of objects (inside the class only).

    The main advantage of object-oriented programming language is to provide reusability, flexibility, and security.

  • The object-oriented programming language must satisfy the object-oriented principles such as:

  • Class
  • Object
  • Inheritance
  • Polymorphism
  • Encapsulation
  • Abstraction
  • Class:
  • Simply, Class contains variables, methods and class name should be “noun”, because it represents things.
  • Class name should be in tittle case which means every word first letter should be capital letter.
  • Example: Bank, PrintStream.
  • Syntax:
  •            public class A{

  •                    Public static void main (string args[]){

  •                       // statements;

  •                     }
  •           }
  •  

  • Object:
  • Object is an instance of a class.
  • The memory space which is allocated for the members of a class, dynamically at the run time, can be called as object.
  • Objects are created for only classes, thus objects can’t be created without a class.
  • Syntax:

    Public class Hello

  • {
  • Public cat ()

  • {
  • }
  • Public static void main ()

  • {
  • Hello ob = new Hello();

  • }
  • }
  • Ob: here ob is object.

    New is a keyword will allocate a memory to the object.

  • Inheritance:
  • Inheritance is the process of acquiring properties from the super class.
  • Inheriting class is also known as subclass.
  • extends is a keyword used to inherit the properties of a class.
  • Example:
  • Class super ()

    {  

  • }
  • class derived extends super
  •        {
  •        }
  • Polymorphism:
  • We can say simply that single work can be done in different ways.
  • Poly means many.
  • Possible way to access to object is through reference variable.
  • Encapsulation:

The process of creating a class by hiding internal data from outside world and accessing it only through public exposed method is known as data encapsulation.

How can we develop encapsulation in java?

1)By declaring variables as private, to restrict it from direct access.

 

Example:

Package p2;

Public class Account

{

Private double balance;

Public double getbalance()

{

return balance;

}

Public void setBalance(double balance){

this.balance=balance;

class BankUser

{

public static void main(string args[])

{

Account a=new Account();

a.setbalance(5000000);

system.out.println(a.getbalance());

​}

}

  • Abstraction:

java also supports Abstraction, it is a supporting principle of OOPS that ensures all three principles are working together to give final shape of the project.

  • Hiding internal implementation and just to hide the setup services what we are offering is call abstraction.
  • By using interface, we can implement abstraction.
  • Example: By using BankAtm GUI screen bank people will hide the setup services what they offer without highlighting internal implementation.
  • It provides security.
  • Data types:

Data types are used to store data temporarily in computer through a program. In real world, we have different types of data like integer,floating-point,character,Boolean and string etc. To store all these types of data in a program to perform business required calculation and validations we must use data types concept.

  • Definition of data type:

Data type is something which gives information about

  • Size of the memory location and range of data that can be accommodated inside that location.
  • Possible legal operations that can be performed on that location. For example: on Boolean data we cannot perform addition operation.
  • What type of result comes out from an expression when these types are used in that expression.
  • Keywords which gives these semantics is treated as “datatype”. There are two types of data types available in java:
    • Primitive Datatypes used to store single value at a time.
    • Reference/object Data types (4) used to collect multiple values.

  • Operators in java:

An operator is a symbol or a special character that tells the computer to perform certain mathematical or logical manipulations which is applied to operands to get a result.

  •  

Operators are used in programs to manipulate data and variables. They usually form a part of mathematical or logical expressions.

  •  
  • The data items that operators act upon to evaluate expressions are called operands.
  • Most operators require two or more operands while others act upon a single operand.
  • Most operators allow the individual operands to be expressions.
  • A few operators permit only single variable as operands.
  • The operands can be integer quantities,floating-point quantities or characters

  Various types of operators:

  • Relational operators
  • Bitwise operators
  • Assignment operators
  • Arithmetic operators

Relational operators:

In C programming, we can compare the values stored between two variables and depending on the result we can follow different blocks using relational operator.

Bitwise operators:

&-And => if both arguments are true then the result is true.

| - or=> At least one argument is true then the result is true.

  • if both arguments are different then result is true.
  •  

Public class operatorsdemo{

Public static void main(string[]args){

System.out.println(4 & 5);

System.out.println(4 | 5);

System.out.println(4 ^ 5);

  •  
  •  

Assignment operators:

There are three types of assignment operators

1)simple assignment

int X=10

2)chained assignment

int a,b,c,d;

  1.  

we cant perform chained assignment at the time of declaration as it gives CE: find the symbol.

3) compound assignment: Sometimes we can mix assignment operator with some other operator to form compound assignment operator.

 

+=, -= *=,/=,%=,&=,|=,^=,>>=,>>>=,<<=

Text Box: +=, -= *=,/=,%=,&=,|=,^=,>>=,>>>=,<<=  

 

 

 

 

The main advantage of compound assignment operator is, internal typecasting is performed automatically.

  • Compound{

Public static void main(string[]args){

byte b=12;​​

b=b+4;

system.out.println(b);

}

}

Arithmetic operators:

Arithmetic operators used in mathematical expressions are in the same way as they used in algebra. C provides all the basic arithmetic operators they can be used on char types, since the char type is, essentially, a subset of int.

All the above operators are called Binary operators as they act upon two operands at a time. The operands acted upon by arithmetic operators must represent numeric values.

  • Conditional statements:

Programming language possesses decision making capabilities and supports the following statements known as control or decision making statements. So depending on the particular condition we need to perform some set of instructions. Flow control describes the order in which the statements will be executed at run time.

Selection statements:                Itereative statements:      Transfer statements:

If                                             while                              break

If- else                                   d0-while                       continue

Switch                                   for loop                         return, try-catch-                                                                                                                             final

Decision making with if statement:

The if statement is a powerful decision making statement and is used to control the flow of execution of statements.it is basically a two-way decision statement and is used I conjunction with an expression. It take the following form.

Example:   public class IfStatement{

                   Public static void main(string[]args)

                   {

                   int a,b;

                   b=5;

                   if(a>b)

                   {

                   System.out.prinln(“a is greater”);

                   }

                   }

                   }

          The if else statement is an extension of the simple if statement. The general form is :

                             If(test expression)

                             true-block statement(s)

                             else

                             false-block statement(s) 

switch statement: 

if several options are available then it isn’t recommended to take nested if-else we should go for switch statement so that readability of the code will be improved.Multiple choices can be constructed by using ‘case’ keyword.

Syntax:

Switch(expression){

Case expr1:

Statements;

break;

case expr2:

statements;

break;

default:

statements;

}

Access modifiers:

  • Private access modifier-private
  • Protected Access Modifier-Protected
  • Public access modifier-public 
  • Default Access Modifier
  • Private access modifier:

Variables, methods and constructors that are declared private can only be accessed within the declared class itself. private access modifier is the most restrictive access level modifier. Class and interfaces cannot be private. Variables that are declared private can ba accessed outside the class, if public getter methods are present in the class.

 

 

 

  • Protected Access Modifier:
  • variables, methods and constructors which are declared protected in a super class can be accessed only by the subclasses in other package or any class within the package of the protected members class.
  • The protected access modifier cannot be applied to class and interfaces. Methods, fields can be declared protected, however methods and fields in an interface cannot be declared protected.
  • Public access modifier:
  • A class, method, constructor, an interface etc declared public can be accessed from any other class. Therefore fields, methods, blocks declared inside a public class can be accessed from any class belonging to the java universe
  • However if the public class we are trying to access is in a different package, then the public class still needs to be imported.
  • Default Access Modifier:
  • Default access modifier means that explicitly an access modifier for a class, field, method, etc is not declared.
  • A variable or method declared without any access control modifier is available to any other class in the same package. The fields in an interface are implicitly public static final and the methods in an interface are by default public.
  • Conclusion:

In this article we have covered wide variety of object oriented programming topics including features and fundamentals of java, data types, operators and access modifiers.

 

Contributor's Info

Created: Edited:
0Comment
Basics: Definitions & Terms | Program | Programming | High Level Language | Assembly Level Language | Machine Language / Low Level Language | Compiler | Interpreter

Program: It is a sequence of instructions, written to perform a specific task with a computer.

Programming: It is a process that leads from an original formulation of a computing problem to executable program.

High Level Language -> (Compiler/Interpreter) -> Assembly Language -> (Assembler) -> Machine Language

High Level Language:

  • Easier to learn
  • English like statements

Assembly Level Language:

  • Symbolic operation code to represent the machine operation code

Machine Language / Low Level Language:

  • Fundamental language of computer's processor
  • Combination of 0's and 1's which representing high and low electrical voltages

Compiler: Programs that translate source code from a high-level programming language to a lower level language.

  • Example: C, C++, COBOL, Fortran etc. uses compiler.

Interpreter: Programs that directly execute instructions written in a programming language, without previously batch-compiling them into machine language.

  • Example: BASIC, Perl, Python etc. uses interpreter.

Contributor's Info

Created:
0Comment