Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
Like Tree2Likes
  • 1 Post By tracknut
  • 1 Post By alykins

Thread: Programming Help - Question from coding from scratch

  1. #1
    New to the CF scene
    Join Date
    Jul 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Programming Help - Question from coding from scratch

    Hi,
    I'm a recent graduate from university and studied Computer Science but my skills in programming overall is abysmal, I didn't do much during my time in university
    (yes I've been pretty much partying all the time whilst in University :P) but after university and my final year I did come around.
    So well my question is regarding programming in general, I have read books such as Head First Java; practised programming whilst learning and then moved onto mid-tier books like the SCJP6 when my basic understanding was really good.

    I have learned most of the fundamentals regarding Java SE, such as Collections, Generics, Enums etc. I also know when to use some feature and the differences between some and when to use it, for example when to use StringBuilder opposed to StringBuffer or when to use HashMaps / LinkedHashMaps etc...

    So my question is this, I know the fundamentals but how is it that I can't code from scratch? Even when I was asked to do easy exercises for job applications i'm on a halt.
    These exercises consist of print hello world 100 with out the use of loops, (I know how to do it now) or have two int arrays and have them merged (not concatenate) but to store the two arrays in one for example. int[] a = {1,2,3,4,5}, int[] b = {6,7,8,9,10} and the final field has to look like this int[] c = {1,2,3,4,5,6,7,8,9,10}.

    So TL;DR version : I know all the fundamentals regarding Java programming, but I am stuck when asked to do simple tasks. Like a deer staring into the car headlights...

  • #2
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,296
    Thanks
    10
    Thanked 282 Times in 281 Posts
    Easy answer. You've spent time reading books about programming, but not enough time actually *doing* it.

    How many hours have you spent this week writing programs?
    hBGl likes this.

  • #3
    New Coder
    Join Date
    Aug 2013
    Posts
    36
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Do you not know the answers to those questions or are you too nervous because of the interview setting?

    By the way what code are you supposed to write for the array question?

  • #4
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,755
    Thanks
    41
    Thanked 191 Times in 190 Posts
    So does that mean you tanked the interview? I honestly don't know how I would respond to someone asking me to write hello world without using loops- aside from that's a really dumb task (off top of my head I'd do it recursively, but that's more work than needed- ie dumb question)-- please note don't tell an interviewer that-- but as tracknut hinted at, it's all about practice practice practice. As hBGI hinted at, if it's the setting, again practice practice practice- but this time practice interviews... get family friends etc to help (older friends who will give you real feedback, not you best bud who will be "awesome dude"). For example I tend to say "um" when I'm thinking on something- it took a few years before an actual friend called me on it- everyone else just kept saying "great!" and things of that nature.
    Dakuan likes this.

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #5
    New to the CF scene
    Join Date
    Jul 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by hBGl View Post
    Do you not know the answers to those questions or are you too nervous because of the interview setting?

    By the way what code are you supposed to write for the array question?
    I did it this way

    int[] a = { 2, 5, 7, 8, 10 };
    int[] b = { 2, 4, 6, 7, 20, 11 };
    int[] c = new int[a.length + b.length];
    int pos = 0;

    for (int i = 0; i < a.length; i++) {
    c[pos] = a[i];
    pos++;
    }

    for (int j = 0; j < b.length; j++) {
    c[pos] = b[j];
    pos++;
    }

    for (int d : c) {
    System.out.print(d);
    }

  • #6
    New to the CF scene
    Join Date
    Jul 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tracknut View Post
    Easy answer. You've spent time reading books about programming, but not enough time actually *doing* it.

    How many hours have you spent this week writing programs?

    Hi, actually I have spent more time coding than reading books :P I did a lot of experiments by reading of the API documentation then I came stumbling upon the chapters regarding it and I knew automatically what to do with it. It's just the fact that when I was given a simple task, I just froze as in all the knowledge I had went away. I have spent at least 3-5 hours every day coding, i've been doing stuff on Spring MVC and Hibernate at the moment.

  • #7
    New Coder
    Join Date
    Aug 2013
    Posts
    36
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by Dakuan View Post
    I did it this way

    int[] a = { 2, 5, 7, 8, 10 };
    int[] b = { 2, 4, 6, 7, 20, 11 };
    int[] c = new int[a.length + b.length];
    int pos = 0;

    for (int i = 0; i < a.length; i++) {
    c[pos] = a[i];
    pos++;
    }

    for (int j = 0; j < b.length; j++) {
    c[pos] = b[j];
    pos++;
    }

    for (int d : c) {
    System.out.print(d);
    }
    Isn't that what you would call concatenating?

  • #8
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,755
    Thanks
    41
    Thanked 191 Times in 190 Posts
    You want to look into Array.Copy(). IMO you've shown work- so here it is in C#- you will need to go the extra step to translate it to Java.
    Code:
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("start\n\n");
    
                int[] a = new int[] { 1, 2, 3 };
                int[] b = new int[] { 4, 5, 6 };
                int[] c = new int[a.Length + b.Length];
    
                a.CopyTo(c, 0);
                b.CopyTo(c, a.Length);
    
                foreach(int i in c)
                {
                    Console.WriteLine(i);
                }
    
                Console.WriteLine("\n");
    
                hello(10);
    
                Console.WriteLine("\n");
                Console.WriteLine("fin");
                Console.ReadLine();
            }
    
            static void hello(int i)
            {
                Console.WriteLine("hello");
                if (i > 0) hello(i-1);
            }
        }

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #9
    New to the CF scene
    Join Date
    Jul 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by hBGl View Post
    Isn't that what you would call concatenating?
    I know that's what I thought, but the task was not to "concatenate" but to "merge", I was scratching my head thinking aren't they the same?

  • #10
    New to the CF scene
    Join Date
    Jul 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I can't use any tools provided by the Arrays class or the System.arrayCopy or any collections. It was to test my experience and thought process to answer his quiz.

  • #11
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,755
    Thanks
    41
    Thanked 191 Times in 190 Posts
    Not all interviews suck like this- I would be annoyed with this interview.

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #12
    New to the CF scene
    Join Date
    Jul 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by alykins View Post
    Not all interviews suck like this- I would be annoyed with this interview.
    yeah I was frustrated too, I just didn't show it; hopefully my future interviews doesn't suck like that one :P

  • #13
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,755
    Thanks
    41
    Thanked 191 Times in 190 Posts
    Quote Originally Posted by Dakuan View Post
    just didn't show it
    Very wise decision xD

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •