Wednesday, June 20, 2018

Basic, but very very useful information

## some common features in c and java ##

* nearly same data types

* same variable declaration style (plus, we can declare variables at any place, as per the need)

* nearly same style of loop, if, and switch statement

* same function declaration (but in java the functions are known as methods)

* nearly same style of array implementation (much simple approach)








## uncommon features in c and java ##

* no pointers

* no garbage values if variable is not initialized

* no header files

* no macros

* no struct and union

* no storage classes like auto/extern/register

* no screen clear function like clrscr()

* also no typedef and sizeof operator (sizeof was used to calcualte the size of any object (object: like data type/variable/value)










## history of java ##

* it is a fully object oriented programming language

* implemented by Mr. james gosling in the sun microsystem company (now overtaken by oracle)

* green was the name of project in which java was implemented

* java was implemented to provide an interface between the remote and a set-top-box

* first name of java was greentalk later on it was renamed to oak (tree outside office of Mr. james gosling), then renamed to java

* java is inspired by c (the GOD)

* logo is a cup of coffea








## versions ##

* first version came in june 1995

* latest is java 10 (came this year 2018)

* but here, i am using java 8 (it is a stable edition)

note: we can use any version which is greater than or equal to java 8








## applications those can be implemented using java ##

* desktop applications (for this we need to learn Java SE (Standard Edition))

note: Hamare watan me Java SE ko core java kaha jata hai

* web applications as well as for business/enterprise application (for this we need to learn Java EE (Enterprise Edition))

note: Hamare watan me Java EE ko advance java kaha jata hai

* mobile applications for symbian os/java based phones (for this we need to learn Java ME (Micro Edition))

* applications for smart cards (for this we need to learn Java Card)









## features of java programming language

1. easy to learn (so java is simple)

2. supports OOP (i mean, Object Oriented Programming guidelines)

3. platform independent, so a java application can be executed on any OS (OS is known as a platform), java do supports the WORA behaviour, means Write Once Run Anywhere

4. robust, immune to errors, if u do rong u r gone

5. free of cost --> bole toh open source

6. most secured programming language on this planet earth

7. is the first programming language that supports multithreading (bole to ek hi time  par bahut sari task/jobs can be done), bole toh multi-tasking

8. compiled as well as interpreted

bole toh -------------------->

write the code -> compile it -> run it









## hardware requirenments:

* no special hardware requirenments (like cpu/ram/hard-disk)






## software requirenments:

* any operating system [windwos or mac or unix/linux]

* JDK (Java Development Kid) and confiure the path variable

note: the JDK is OS dependent, so JDK is different for windwos a dn mac

* need an IDE (Integerated Development Enviornment) like Eclipse or NetBeans or Inteli-J-Idea

note: we will use Eclipse (reason it is open-source/fast/reliable/industry oriented)



## facts about a java application

* a java program must have a .java extension

* inside a java program we will define a class, a class is also known as
  a compilation unit

* class: is a like a structure

example:

class ClassName
{
}


life cycle of a java program ->

* write the code (to be done by us, bole to developers)

* compile (when we compile a java program, the compiler will generate an intermediate file from the class, this file is known as bytecode), the extension of bytecode will be classname.class

example: if program-name is zoo.java and class-name is lion then bytecode will be lion.class

* run the bytecode (in order to execute a bytecode we need a software known as JVM (bole toh Java Virtual Machine), the JVM executes the bytecode line by line, so technically JVM is an interpretor

note: JVM is written in C (maan gaye yaar, C is a real GOD)

note: in order to execute a bytecode using JVM it is mandatory to define a main method
inside the class, otherwise the bytecode will not run

note: compile and run process will be auto done by the Eclipse IDE (so no need to worry .....................................THANK GOD)












## lets show something on screen (screen bole toh console)

* print / println / printf (all are pre-defined methods)

* the print method just print the data on console, and keep the cursor on the same line

* the println method print the data on console then move the cursor to the next line

* the printf print the data in a format (format bole toh printing in alignment using some pre-defined format specifiers like %d or %f %s ............................................
jese hum C mai use karte thai)

* chalo syntax dekh lete hain..............

* print or println => System.out.print("any message" or value or variable-name or    expression);

* printf => System.out.printf("format-specifiers",variable-names);

* format-specifiers : Data-types
---------------------------------
%d :    int long
%o
%X

d means decimal, o means octal, X means hexa-decimal

%c %C :    char

%f %E float double

E means exponent

%s %S :    String

%b %B :    boolean








## some facts

1. In java any condition is denoted by boolean but in C or C++ the condition is int

   "yaad hoga ki C mai 1 means true and 0 means false hua karta thaa"

   example =>

if(true or false) <= in java
{
}

if(1 or 0) <= in C or C++, but error in java
{
}

2. In java we can declare a variable inside for-loop but that variable can't be used out the loop

example => 

for(int i = 1; i <= 10; i++)
{
}









## data types in java (lets do some fast brushup)

* primitives [types -> byte / short / int / long / char / float / double / boolean]

note: primitives are always pre-defined (bole toh they already exists in language)

* non-primitives [types -> class / array / interface]

note: class or interface may be [pre-defined / user-defined], but array always user-defined

## size for primitives

* byte 8 bits / short 16 / int 32 / long 64 / char 16 / float 32 / double 64 /
boolean size not specified

note: unlike C and C++, in Java, int / long are by default signed, never be unsigned
  but char is unsigned, never be signed, so cant store negative values
  float and double can store negative as well as positive values
 







## operators in java

* this is a priority table for operators

1. ++ -- [] . ()

2. ~ + - new (type)

3. * / %

4. + -

5. << >> >>>

6. < <= > >= instanceof

7. == !=

8. &

9. ^

10. |

11. &&

12. ||

13. ?:

14. = *= /= %= += -= <<= >>= >>>= &= ^= \=

note: the operators those comes first in the table has more priority/precedence than those comes later, but, in the same level the priority remain same











## OOPS (stands for Object Oriented Programming System/Structure)

* it is a guideline by which we can develop a software fast/easy/effectively.

* apart from that the benefites of oops are..............

1. re-usability of data and code
2. easy to modify the application as per the client needs
3. better security of data
4. modularization (application ko multiple modules mai divide karna)
5. scalability (under high user traffic the application should respond well)


* features of OOPS

COPIEAMM (guys, this word was invented by me 5 years back...........are bus yaad karne ke liye)

* the first object oriented programming language is Simula67

* types of programming languages in the context of OOPS

1. non-related-to-oops: like {C, pascal, fortarn, basic, lips, many more}
2. related-to-oops: like {Java, C++, C#, objective-c, smalltalk}

* fully OOPL: {means in these languages the class is a must, like -> Java, C# etc}

* pure OOOPL: {means, they does not have primitive-data-type, like -> smalltalk}










## class:

definition#1: class is a blueprint or a design by which a developer (means hum log) can create a collection of homogeneous (bole toh ek jaise) products, also known objects (bole toh real world entity)

definition#2: class is a non-primitive-data type also

types of classes:

1. pre-defined-classes: already built in java (they are inside library), like System or String, and many more

2. user-defined-classes: those are defined by me or you

syntax to define a class =>

class NameOfClass
{
}

* class is a keyword

* class-name may have [A to Z, 0 to 9, $, _], but must not start with number

* valid class-names => A1 A_ $ _ ___ $$$$
*invalid class-names => 1A A-B A B

* by convention the class-name should be [meaningful, and should follow the camel pattern, first letter of each word should be capital]

* example => W or Why or WhyThis or  WhyThisKolaveri or  WhyThisKolaveriDi








## content of a java class

* inside the class we may have

1. data members (bole toh variables): to hold data

2. methods (bole toh behavior): to store and fetch the data to/from the data members

3. constructor: to initialize data members at the time of object creation

4. block: will see later on

5. nested class: class inside a class, will see later on










## data members

1=> local variable

* declared inside method

* they must be initialized before use since they are blank (bole toh unko default values nahin miltin)

* they cant be accessed outside the method in which they are declared

2=> non-static-variable (also known as instance variable)

* declared inside class

* there is no need to initialize non-static-variable, since     they get default values

* they live inside object, and the JVM creates one copy of non-static-variable per object

3=> static variable

* declared inside class using static keyword

* there is no need to initialize non-static-variable, since     they get default values

* the JVM creates a single copy of static-variable when application starts, this copy can be shared by all the objects of this class (bole toh static-variable are shared variable)









## what is an object (object ko instance bhi kaha jata hai)

* object bole toh instance or vice versa

* object is a real world entity

* but technically ======> object is a memory allocated by JVM during runtime inside heap

* address of object is also known as reference-id or object-id





## syntax to create object

* class-name variable-name = new class-name();

example=>

lets assume that Person and Tiger are some classes

* Person p = new Person();

* Tiger t = new Tiger();

* here p and t are reference-variable or object-name

* reference-variable holds the address of object






## non-static-variable can be accessed using

* object-name.non-static-variable-name

# static-variable can be accessed using 3 ways

1. object-name.static-variable-name [this is a worst approach]

2. static-variable-name [this is good approach]

3. class-name.static-variable-name [this is best approach]





## interview question, when to use which data members.

1. local-variable (to store method related data, mainly used for intermediate values)

2. non-static-variable (to store object specific data)

3. static-variable (to store common data)


5 comments:

  1. Sir, ur punch lines are so good

    ReplyDelete
  2. Sir, ur punch lines r so good😊

    ReplyDelete
  3. Sir...it will help us to revise later...thank u sir

    ReplyDelete
  4. Itis a nice way of notes and revision sir

    ReplyDelete
  5. sir its like chotta packet bada dhamaka

    ReplyDelete