Thursday, 8 January 2015

Checking Out Java Code for the First Time

The first time you look at somebody else’s Java program, you tend to feel a bit
queasy. The realization that you don’t understand something (or many things)
in the code can make you nervous. I’ve written hundreds (maybe thousands) of
Java programs, but I still feel insecure when I start reading someone else’s code.
The truth is that finding out about a Java program is a bootstrapping experience.
First, you gawk in awe of the program. 


Then you run the program to see
what it does. Then you stare at the program for a while or read someone’s
explanation of the program and its parts. Then you gawk a little more and run
the program again. Eventually, you come to terms with the program. (Don’t
believe the wise guys who say they never go through these steps. Even the
experienced programmers approach a new project slowly and carefully.)
In Listing 3-1, you get a blast of Java code. (Like all novice programmers,
you’re expected to gawk humbly at the code.) Hidden in the code, I’ve placed
some important ideas, which I explain in detail in the next section. These
ideas include the use of classes, methods, and Java statements.



The Simplest Java Program


class Displayer {

public static void main(String args[]) {

System.out.println(“You’ll love Java!”);

}


}


Tuesday, 6 January 2015

Not just English is One Language .. People found out even a Language to Communicate with Non Living things " Write Once, Run Anywhere "

Getting Perspective: Where Java Fits In


Here’s a brief history of modern computer programming:
✓ 1954–1957: FORTRAN is developed.
FORTRAN was the first modern computer programming language. For
scientific programming, FORTRAN is a real racehorse. Year after year,
FORTRAN is a leading language among computer programmers throughout
the world.

✓ 1959: COBOL is created.
The letter B in COBOL stands for Business, and business is just what
COBOL is all about. The language’s primary feature is the processing of
one record after another, one customer after another, or one employee
after another.

Within a few years after its initial development, COBOL became the most
widely used language for business data processing. Even today, COBOL
represents a large part of the computer programming industry.

✓ 1972: Dennis Ritchie at AT&T Bell Labs develops the C programming
language.
The “look and feel” that you see in this book’s examples comes from
the C programming language. Code written in C uses curly braces, if
statements, for statements, and so on.
In terms of power, you can use C to solve the same problems that you
can solve by using FORTRAN, Java, or any other modern programming
language. (You can write a scientific calculator program in COBOL,
but doing that sort of thing would feel really strange.) The difference
between one programming language and another isn’t power. The
difference is ease and appropriateness of use. That’s where the Java
language excels.

✓ 1986: Bjarne Stroustrup (again at AT&T Bell Labs) develops C++.
Unlike its C language ancestor, the language C++ supports object oriented
programming. 

✓ May 23, 1995: Sun Microsystems releases its first official version of the
Java programming language.
Java improves upon the concepts in C++. Java’s “Write Once, Run
Anywhere” philosophy


Part I Getting Started

                                                             All about Java



What You Can Do with Java

It would be so nice if all this complexity was free, but unfortunately, it isn't.

Someone has to think hard and decide exactly what to ask the computer to
do. After that thinking, someone has to write a set of instructions for the
computer to follow.

Given the current state of affairs, you can’t write these instructions in English
or any other language that people speak. Science fiction is filled with stories
about people who say simple things to robots and get back disastrous, unexpected
results. English and other such languages are unsuitable for communication
with computers for several reasons:
✓ An English sentence can be misinterpreted. “Chew one tablet three
times a day until finished.”
✓ It’s difficult to weave a very complicated command in English. “Join
flange A to protuberance B, making sure to connect only the outermost
lip of flange A to the larger end of the protuberance B, while joining the
middle and inner lips of flange A to grommet C.”
✓ An English sentence has lots of extra baggage. “Sentence has
unneeded words.”

Tuesday, 19 November 2013

why string is immutable in java



This is one of the most popular String Interview questions in Java, which starts with discussion of,  What is String, How String in Java is different than String in C and C++, and then shifted towards what is immutable object in Java , what are the benefits of immutable object , why do you use it and which scenarios do you use it. This is some time also asked as "Why String is final in Java" . Though there could be many possible answer for this question, and only designer of String class can answer this , I think below two does make sense

1) Imagine StringPool facility without making string immutable , its not possible at all because in case of string pool one string object/literal e.g. "Test" has referenced by many reference variables , so if any one of them change the value others will be automatically gets affected i.e. lets say

String A = "Test"
String B = "Test" 

Now String B called "Test".toUpperCase() which change the same object into "TEST" , so A will also be "TEST" which is not desirable.